Split usage info into its own function and use that to display usage if !command is misused
This commit is contained in:
parent
1ffb82ebc1
commit
c688acf55e
127
botcmd.py
127
botcmd.py
|
@ -118,6 +118,62 @@ def send_event(event):
|
|||
|
||||
game_channel.send(event)
|
||||
|
||||
def usage(command):
|
||||
if type(command) == str:
|
||||
command = [command]
|
||||
|
||||
if len(command) > 0:
|
||||
if command[0][0] == '!':
|
||||
command[0] = command[0][1:]
|
||||
|
||||
if len(command) == 0:
|
||||
return '!status !start !ready !unready !kill !join !leave !players !kick !deck !limit !card !cards !origins !redeal !help'
|
||||
|
||||
elif len(command) == 1:
|
||||
if command[0] in ('status', 'ready', 'unready', 'kill', 'join', 'leave', 'players', 'cards', 'origins', 'redeal'):
|
||||
return 'Usage: !%s' % (command[0])
|
||||
elif command[0] == 'start':
|
||||
return 'Usage: !start [<preset>]'
|
||||
elif command[0] == 'join':
|
||||
return 'Usage: !join [<message>]'
|
||||
elif command[0] == 'kick':
|
||||
return 'Usage: !kick <nick>'
|
||||
elif command[0] == 'card':
|
||||
return 'Usage: [!card] <number> ...'
|
||||
elif command[0] == 'deck':
|
||||
return 'Subcommands: !deck add | remove | list'
|
||||
elif command[0] == 'bot':
|
||||
return 'Subcommands: !bot add | remove'
|
||||
elif command[0] == 'limit':
|
||||
return 'Usage: !limit [<number> [<type>]]'
|
||||
elif command[0] == 'help':
|
||||
return 'Usage: !help [command [subcommmand]]'
|
||||
else:
|
||||
return 'No such command !%s' % (command[0])
|
||||
|
||||
elif len(command) == 2:
|
||||
if command[0] == 'deck':
|
||||
if command[1] == 'add':
|
||||
return 'Usage: !deck add <code> | random'
|
||||
elif command[1] == 'remove':
|
||||
return 'Usage: !deck remove <code>'
|
||||
elif command[1] == 'list':
|
||||
return 'Usage: !deck list'
|
||||
else:
|
||||
return 'No such subcommand !%s %s' % (command[0], command[1])
|
||||
elif command[0] == 'bot':
|
||||
if command[1] == 'add':
|
||||
return 'Usage: !bot add <type> [<name>]'
|
||||
elif command[1] == 'remove':
|
||||
return 'Usage: !bot remove <name>'
|
||||
else:
|
||||
return 'No such subcommand !%s %s' % (command[0], command[1])
|
||||
else:
|
||||
return 'No such subcommand !%s %s' % (command[0], command[1])
|
||||
|
||||
else:
|
||||
return 'Uh, how did we get %i args?' % len(command)
|
||||
|
||||
def parse_command(message, nick, irc):
|
||||
def send(m):
|
||||
global irc_chan
|
||||
|
@ -129,15 +185,7 @@ def parse_command(message, nick, irc):
|
|||
num = [num]
|
||||
|
||||
if len(message) - index not in num:
|
||||
command = ' '.join(message[:index])
|
||||
|
||||
if len(num) == 1:
|
||||
if num[0] == 1:
|
||||
send('%s needs 1 argument' % command)
|
||||
else:
|
||||
send('%s needs %i arguments' % (command, num[0]))
|
||||
else:
|
||||
send('%s needs either %s arguments' % (command, ' or '.join(num)))
|
||||
send(usage(message[:index]))
|
||||
return None
|
||||
|
||||
return message[index:]
|
||||
|
@ -194,7 +242,7 @@ def parse_command(message, nick, irc):
|
|||
|
||||
elif c == '!deck':
|
||||
if len(message) < 2:
|
||||
send('Subcommands: !deck add | remove | list')
|
||||
send(usage('!deck'))
|
||||
return
|
||||
|
||||
subc = message[1]
|
||||
|
@ -218,11 +266,11 @@ def parse_command(message, nick, irc):
|
|||
send_event((events.deck_list,))
|
||||
|
||||
else:
|
||||
send('Subcommands: !deck add | remove | list')
|
||||
send(usage('!deck'))
|
||||
|
||||
elif c == '!bot':
|
||||
if len(message) < 2:
|
||||
send('Subcommands: !bot add | remove')
|
||||
send(usage('!bot'))
|
||||
return
|
||||
|
||||
subc = message[1]
|
||||
|
@ -246,7 +294,7 @@ def parse_command(message, nick, irc):
|
|||
send_event((events.bot_remove, name))
|
||||
|
||||
else:
|
||||
send('Subcommands: !bot add | remove')
|
||||
send(usage('!bot'))
|
||||
|
||||
elif c == '!limit':
|
||||
arg = args([0, 1, 2])
|
||||
|
@ -258,7 +306,7 @@ def parse_command(message, nick, irc):
|
|||
else:
|
||||
num = arg[0]
|
||||
if not num.isdecimal():
|
||||
send('Usage: !limit [<number> [<type>]]')
|
||||
send(usage('!limit'))
|
||||
return
|
||||
num = int(num)
|
||||
|
||||
|
@ -282,7 +330,7 @@ def parse_command(message, nick, irc):
|
|||
arg = message
|
||||
|
||||
if not all(i.isdecimal() for i in arg):
|
||||
send('Usage: [!card] <number> ...')
|
||||
send(usage('!card'))
|
||||
return
|
||||
|
||||
choices = [int(i) for i in arg]
|
||||
|
@ -303,54 +351,7 @@ def parse_command(message, nick, irc):
|
|||
elif c == '!help':
|
||||
arg = args([0, 1, 2])
|
||||
if arg is not None:
|
||||
if len(arg) > 0:
|
||||
if arg[0][0] == '!':
|
||||
arg[0] = arg[0][1:]
|
||||
|
||||
if len(arg) == 0:
|
||||
send('!status !start !ready !unready !kill !join !leave !players !kick !deck !limit !card !cards !origins !redeal')
|
||||
|
||||
elif len(arg) == 1:
|
||||
if arg[0] in ('status', 'ready', 'unready', 'kill', 'join', 'leave', 'players', 'cards', 'origins', 'redeal'):
|
||||
send('Usage: !%s' % (arg[0]))
|
||||
elif arg[0] == 'start':
|
||||
send('Usage: !start [<preset>]')
|
||||
elif arg[0] == 'join':
|
||||
send('Usage: !join [<message>]')
|
||||
elif arg[0] == 'kick':
|
||||
send('Usage: !kick <nick>')
|
||||
elif arg[0] == 'card':
|
||||
send('Usage: [!card] <number> ...')
|
||||
elif arg[0] == 'deck':
|
||||
send('Subcommands: !deck add | remove | list')
|
||||
elif arg[0] == 'bot':
|
||||
send('Subcommands: !bot add | remove')
|
||||
elif arg[0] == 'limit':
|
||||
send('Usage: !limit [<number> [<type>]]')
|
||||
else:
|
||||
send('No such command !%s' % (arg[0]))
|
||||
elif len(arg) == 2:
|
||||
if arg[0] == 'deck':
|
||||
if arg[1] == 'add':
|
||||
send('Usage: !deck add <code> | random')
|
||||
elif arg[1] == 'remove':
|
||||
send('Usage: !deck remove <code>')
|
||||
elif arg[1] == 'list':
|
||||
send('Usage: !deck list')
|
||||
else:
|
||||
send('No such subcommand !%s %s' % (arg[0], arg[1]))
|
||||
elif arg[0] == 'bot':
|
||||
if arg[1] == 'add':
|
||||
send('Usage: !bot add <type> [<name>]')
|
||||
elif arg[1] == 'remove':
|
||||
send('Usage: !bot remove <name>')
|
||||
else:
|
||||
send('No such subcommand !%s %s' % (arg[0], arg[1]))
|
||||
else:
|
||||
send('No such subcommand !%s %s' % (arg[0], arg[1]))
|
||||
|
||||
else:
|
||||
send('Uh, how did we get %i args?' % len(arg))
|
||||
send(usage(arg))
|
||||
|
||||
# initialize(*, config)
|
||||
# Called to initialize the IRC bot
|
||||
|
|
Loading…
Reference in New Issue