#!/usr/bin/env python3 """ Pick some random numbers. """ import sys import random import string from module import commands, example @commands("rand") @example(".rand 2", "random(0, 2) = 1") @example(".rand -1 -1", "random(-1, -1) = -1") @example(".rand", "random(0, 56) = 13") @example(".rand 99 10", "random(10, 99) = 53") @example(".rand 10 99", "random(10, 99) = 29") def rand(bot, trigger): """Replies with a random number between first and second argument.""" arg1 = trigger.group(3) arg2 = trigger.group(4) try: if arg2 is not None: low = int(arg1) high = int(arg2) elif arg1 is not None: low = 0 high = int(arg1) else: low = 0 high = sys.maxsize except (ValueError, TypeError): return bot.reply("Arguments must be of integer type") if low > high: low, high = high, low number = random.randint(low, high) bot.reply(f"random({low}, {high}) = {number}") @commands('letters') @example('.letters', 'iloynlle') @example('.letters 16', 'oaotordbwaauouxk') def rand_letters(bot, trigger): """ usage: .letters [num_letters] [num_vowels] Generates a series of string of random letters. """ num_letters = int(trigger.group(3)) if trigger.group(3) else 8 num_vowels = int(trigger.group(4)) if trigger.group(4) else 2 msg = [] for _ in range(num_letters): c = random.choice(string.ascii_lowercase + "aioue" * num_vowels) msg.append(c) bot.msg(''.join(msg))