def run_dice_format(self, num_dice, num_sides): """Rolls numDice number of dice, each with numSides number of sides""" if num_dice == 0 or num_dice > 100: return "Invalid number of dice." if num_sides == 0 or num_sides > 1000000: return "Invalid number of sides." if num_dice == 1: rand = Commons.get_random_int(1, num_sides)[0] return "I roll {}!!!".format(rand) else: dice_rolls = Commons.get_random_int(1, num_sides, num_dice) output_string = "I roll {}. The total is {}.".format(", ".join([str(x) for x in dice_rolls]), sum(dice_rolls)) return output_string
def run(self, line, user_obj, destination_obj=None): """WH40K Thought for the day. Format: thought_for_the_day""" thought_list = Commons.read_file_to_list('store/WH40K_ToTD2.txt') rand = Commons.get_random_int(0, len(thought_list) - 1)[0] if thought_list[rand][-1] not in ['.', '!', '?']: thought_list[rand] += "." return '"' + thought_list[rand] + '"'
def run(self, line, user_obj, destination_obj=None): word_list = Commons.read_file_to_list('store/ouija_wordlist.txt') rand_list = Commons.get_random_int(0, len(word_list) - 1, 4) num_words = (rand_list[0] % 3) + 1 output_string = "I'm getting a message from the other side..." output_string += " ".join([word_list[rand_list[x + 2]] for x in range(num_words)]) output_string += "." return output_string
def run(self, line, user_obj, channel_obj=None): choices = re.compile(', | or ', re.IGNORECASE).split(line) numchoices = len(choices) if numchoices == 1: return 'Please present me with more than 1 thing to choose from!' else: rand = Commons.get_random_int(0, numchoices - 1)[0] choice = choices[rand] return 'I choose "' + choice + '".'
def run(self, line, user_obj, channel_obj=None): responses = ['It is certain', 'It is decidedly so', 'Without a doubt', 'Yes definitely', 'You may rely on it'] responses += ['As I see it yes', 'Most likely', 'Outlook good', 'Yes', 'Signs point to yes'] responses += ['Reply hazy try again', 'Ask again later', 'Better not tell you now', 'Cannot predict now', 'Concentrate and ask again'] responses += ["Don't count on it", 'My reply is no', 'My sources say no', 'Outlook not so good', 'Very doubtful'] rand = Commons.get_random_int(0, len(responses) - 1)[0] return responses[rand] + "."
def run(self, line, user_obj, channel_obj=None): # If this command is run in privmsg, it won't work if channel_obj is None or channel_obj.is_user(): return "This function can only be used in a channel" # Get the user list user_set = channel_obj.get_user_list() # Get list of users' names names_list = [user_obj.get_name() for user_obj in user_set] rand = Commons.get_random_int(0, len(names_list) - 1)[0] return 'It should be obvious by now that ' + names_list[rand] + ' is the chosen one.'
def test_get_random_int(self): for count in range(1, 3): for max_int in range(2, 10): for min_int in range(1, 5): if min_int > max_int: continue rand_list = Commons.get_random_int(min_int, max_int, count) assert len(rand_list) == count, "Random integer list is the wrong length. " + str(rand_list) + \ " not " + str(count) + " elements" for rand in rand_list: assert rand >= min_int, "Random integer was too small. " + str(rand) + " < " + str(min_int) assert rand <= max_int, "Random integer was too big. " + str(rand) + " > " + str(max_int)
def run(self, event): rgb_list = Commons.get_random_int(0, 255, 3) hex_code = "{}{}{}".format(hex(rgb_list[0])[2:].zfill(2), hex(rgb_list[1])[2:].zfill(2), hex(rgb_list[2])[2:].zfill(2)).upper() url = "https://www.thecolorapi.com/id?hex={}".format(hex_code) human_url = "{}&format=html".format(url) colour_data = Commons.load_url_json(url) colour_name = colour_data["name"]["value"] output = "Randomly chosen colour is: {} #{} or rgb({},{},{}) {}".format(colour_name, hex_code, rgb_list[0], rgb_list[1], rgb_list[2], human_url) return event.create_response(output)
def run(self, line, user_obj, destination_obj=None): rgb_list = Commons.get_random_int(0, 256, 3) hex_code = (hex(rgb_list[0])[2:] + hex(rgb_list[1])[2:] + hex(rgb_list[2])[2:]).upper() url = "http://www.perbang.dk/rgb/" + hex_code + "/" url_data = Commons.load_url_string(url) colour_match = re.search('<meta name="Description" content="([A-Za-z ]+)#', url_data, re.M) if colour_match is None or colour_match.group(1) is None: output = "Randomly chosen colour is: #" + hex_code + " or rgb(" + str(rgb_list[0]) + "," + str( rgb_list[1]) + "," + str(rgb_list[2]) + ") " + url else: colour_name = colour_match.group(1) output = "Randomly chosen colour is: " + colour_name + " #" + hex_code + " or rgb(" + str( rgb_list[0]) + "," + str(rgb_list[1]) + "," + str(rgb_list[2]) + ") " + url return output
def run(self, event): """FOOOOOOOOOF. Format: foof""" rand = Commons.get_random_int(0, 60)[0] if rand <= 20: return event.create_response('doof') elif rand <= 40: return event.create_response('doooooof') else: if rand == 40 + 15: server_obj = event.server server_obj.send(event.create_response("Powering up...")) time.sleep(5) return event.create_response('d' * 100 + 'o' * 1000 + 'f' * 200 + '!' * 50) else: return event.create_response('ddddoooooooooooooooooooooffffffffff.')
def run(self, line, user_obj, destination_obj=None): """FOOOOOOOOOF. Format: foof""" rand = Commons.get_random_int(0, 60) if rand <= 20: return 'doof' elif rand <= 40: return 'doooooof' else: if rand == 40 + 15: server_obj = user_obj.get_server() server_obj.send('powering up...', destination_obj) time.sleep(5) return 'd' * 100 + 'o' * 1000 + 'f' * 200 + '!' * 50 else: return 'ddddoooooooooooooooooooooffffffffff.'
def run(self, line, user_obj, destination_obj=None): """Prints ascii dragon. Format: dragon""" dragon_deer = r'''hmm.. nah. have another deer. ""\/ \/"" "\__/" (oo) -. ______-LJ ,' | |.____.. / \\ /A\ |A |//''' dragon_one = r''' _ _ _ //` `\ _,-"\% // /``\`\ ~^~ >__^ |% // / } `\`\ ) )%// / } } }`\`\ / (%/'/.\_/\_/\_/\`/ ( ' `-._` \ , ( \ _`-.__.-;%> /_`\ \ `\ \." `-..-'` ``` /_/`"-=-'`/_/ jgs ``` ```''' dragon_two = r''' ____ __ { --.\ | .)%%%)%% '-._\\ | (\___ %)%%(%%(%%% `\\|{/ ^ _)-%(%%%%)%%;%%% .'^^^^^^^ /` %%)%%%%)%%%' jgs //\ ) , / '%%%%(%%' , _.'/ `\<-- \< `^^^` ^^ ^^''' rand = Commons.get_random_int(0, 100)[0] if rand == 15: dragon = dragon_deer elif rand % 2 == 0: dragon = dragon_one else: dragon = dragon_two return dragon
def run_range_format(self, range_min, range_max): """Generates a random number between rangeMin and rangeMax""" rand = Commons.get_random_int(range_min, range_max)[0] return "I roll {}!!!".format(rand)
def run(self, event): word_list = Commons.read_file_to_list('store/ouija_wordlist.txt') num_words = Commons.get_random_int(1, 3)[0] rand_words = Commons.get_random_choice(word_list, num_words) output_string = "I'm getting a message from the other side... {}.".format(" ".join(rand_words)) return event.create_response(output_string)
def run(self, line, user_obj, destination_obj=None): rand = Commons.get_random_int(0, len(self.proverb_list) - 1)[0] return self.proverb_list[rand]