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."""