Merge branch 'random-from-set' into 'master'

add !random command to dice module

See merge request !11
This commit is contained in:
Brian S. Stephan 2017-02-04 10:43:49 -06:00
commit 38d14bb0d2
1 changed files with 15 additions and 0 deletions

View File

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