Allow multi-word names for bots
This commit is contained in:
parent
451bf710f1
commit
fc19e7c442
32
botcmd.py
32
botcmd.py
|
@ -176,16 +176,23 @@ def parse_command(message, nick, irc):
|
||||||
global irc_chan
|
global irc_chan
|
||||||
irc.bot_response(irc_chan, m)
|
irc.bot_response(irc_chan, m)
|
||||||
|
|
||||||
def arg(num, index = 1):
|
def arg(num, index = 1, at_least = False):
|
||||||
nonlocal message
|
nonlocal message
|
||||||
if type(num) == int:
|
if not at_least:
|
||||||
num = [num]
|
if type(num) == int:
|
||||||
|
num = [num]
|
||||||
|
|
||||||
if len(message) - index not in num:
|
if len(message) - index not in num:
|
||||||
send(usage(message[:index]))
|
send(usage(message[:index]))
|
||||||
return None
|
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):
|
def valid_choice(c):
|
||||||
return re.fullmatch(r'\d+(,\d+)*', c)
|
return re.fullmatch(r'\d+(,\d+)*', c)
|
||||||
|
@ -275,10 +282,11 @@ def parse_command(message, nick, irc):
|
||||||
|
|
||||||
subc = message[1]
|
subc = message[1]
|
||||||
if subc == 'add':
|
if subc == 'add':
|
||||||
args = arg([1, 2], 2)
|
args = arg(1, 2, at_least = True)
|
||||||
if args is not None:
|
if args is not None:
|
||||||
if len(args) == 2:
|
if len(args) > 1:
|
||||||
bot_type, name = args
|
bot_type, *name = args
|
||||||
|
name = ' '.join(name)
|
||||||
else:
|
else:
|
||||||
bot_type, = args
|
bot_type, = args
|
||||||
name = bot_type
|
name = bot_type
|
||||||
|
@ -288,9 +296,9 @@ def parse_command(message, nick, irc):
|
||||||
send('Allowed bot types: rando')
|
send('Allowed bot types: rando')
|
||||||
|
|
||||||
elif subc == 'remove':
|
elif subc == 'remove':
|
||||||
args = arg(1, 2)
|
args = arg(1, 2, at_least = True)
|
||||||
if args is not None:
|
if args is not None:
|
||||||
name, = args
|
name = ' '.join(args)
|
||||||
send_event((events.bot_remove, name))
|
send_event((events.bot_remove, name))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue