From be0fafc897531f770a6b18db0d77ee68a37152d2 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 4 Feb 2017 10:03:47 -0600 Subject: [PATCH] add !random command to dice module chooses one random element from the provided list of choices. pretty basic right now --- dr_botzo/dice/ircplugin.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dr_botzo/dice/ircplugin.py b/dr_botzo/dice/ircplugin.py index f9d2a73..5ccf96a 100644 --- a/dr_botzo/dice/ircplugin.py +++ b/dr_botzo/dice/ircplugin.py @@ -27,6 +27,8 @@ class Dice(Plugin): self.handle_roll, -20) self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!ctech\s+(.*)$', self.handle_ctech, -20) + self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!random\s+(.*)$', + self.handle_random, -20) super(Dice, self).start() @@ -35,9 +37,22 @@ class Dice(Plugin): self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_roll) self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_ctech) + self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_random) super(Dice, self).stop() + def handle_random(self, connection, event, match): + """Handle the !random command which picks an item from a list.""" + + nick = NickMask(event.source).nick + choices = match.group(1) + + choices_list = choices.split(' ') + choice = random.choice(choices_list) + + reply = "{0:s}: {1:s}".format(nick, choice) + return self.bot.reply(event, reply) + def handle_roll(self, connection, event, match): """Handle the !roll command which covers most common dice stuff."""