diff --git a/botcmd.py b/botcmd.py index 00949bc..0675fab 100644 --- a/botcmd.py +++ b/botcmd.py @@ -176,16 +176,23 @@ def parse_command(message, nick, irc): global irc_chan irc.bot_response(irc_chan, m) - def arg(num, index = 1): + def arg(num, index = 1, at_least = False): nonlocal message - if type(num) == int: - num = [num] + if not at_least: + if type(num) == int: + num = [num] - if len(message) - index not in num: - send(usage(message[:index])) - return None + if len(message) - index not in num: + send(usage(message[:index])) + return None - return message[index:] + return message[index:] + else: + if len(message) - index < num: + send(usage(message[:index])) + return None + + return message[index:] def valid_choice(c): return re.fullmatch(r'\d+(,\d+)*', c) @@ -275,10 +282,11 @@ def parse_command(message, nick, irc): subc = message[1] if subc == 'add': - args = arg([1, 2], 2) + args = arg(1, 2, at_least = True) if args is not None: - if len(args) == 2: - bot_type, name = args + if len(args) > 1: + bot_type, *name = args + name = ' '.join(name) else: bot_type, = args name = bot_type @@ -288,9 +296,9 @@ def parse_command(message, nick, irc): send('Allowed bot types: rando') elif subc == 'remove': - args = arg(1, 2) + args = arg(1, 2, at_least = True) if args is not None: - name, = args + name = ' '.join(args) send_event((events.bot_remove, name)) else: