diff --git a/botcmd.py b/botcmd.py index 7073518..c3e1832 100644 --- a/botcmd.py +++ b/botcmd.py @@ -5,6 +5,9 @@ import channel import gameloop +import random +import re + nickserv_pass = None irc_chan = None @@ -139,7 +142,7 @@ def usage(command): elif command[0] == 'kick': return 'Usage: !kick ' elif command[0] == 'card': - return 'Usage: [!card] ...' + return 'Usage: [!card] ...' elif command[0] == 'deck': return 'Subcommands: !deck add | remove | list' elif command[0] == 'bot': @@ -190,6 +193,9 @@ def parse_command(message, nick, irc): return message[index:] + def valid_choice(c): + return re.fullmatch(r'\d+(,\d+)*', c) + events = gameloop.events message = message.split() @@ -323,17 +329,23 @@ def parse_command(message, nick, irc): else: send_event((events.limit, gameloop.limit_types.points, num)) - elif c == '!card' or all(i.isdecimal() for i in message): + elif c == '!card' or all(valid_choice(i) for i in message): if c == '!card': args = message[1:] else: args = message - if not all(i.isdecimal() for i in args): + if not all(valid_choice(i) for i in args): send(usage('!card')) return - choices = [int(i) for i in args] + def pick(c): + if c.isdecimal(): + return c + else: + return random.choice(c.split(',')) + + choices = [int(pick(i)) for i in args] send_event((events.card, nick, choices)) elif c == '!cards':