mirror of
https://github.com/jlu5/PyLink.git
synced 2025-02-17 14:01:03 +01:00
commands: add a 'help' command (closes #8)
Fetch the docstring of the command function if it exists, and format appropriately.
This commit is contained in:
parent
bbcd70b175
commit
6508cb3c38
@ -17,6 +17,9 @@ def debug(irc, source, args):
|
|||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def status(irc, source, args):
|
def status(irc, source, args):
|
||||||
|
"""takes no arguments.
|
||||||
|
|
||||||
|
Returns your current PyLink login status."""
|
||||||
identified = irc.users[source].identified
|
identified = irc.users[source].identified
|
||||||
if identified:
|
if identified:
|
||||||
utils.msg(irc, source, 'You are identified as %s.' % identified)
|
utils.msg(irc, source, 'You are identified as %s.' % identified)
|
||||||
@ -25,11 +28,15 @@ def status(irc, source, args):
|
|||||||
|
|
||||||
@utils.add_cmd
|
@utils.add_cmd
|
||||||
def identify(irc, source, args):
|
def identify(irc, source, args):
|
||||||
|
"""<username> <password>
|
||||||
|
|
||||||
|
Logs in to PyLink using the configured administrator account."""
|
||||||
try:
|
try:
|
||||||
username, password = args[0], args[1]
|
username, password = args[0], args[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
utils.msg(irc, source, 'Error: not enough arguments.')
|
utils.msg(irc, source, 'Error: not enough arguments.')
|
||||||
return
|
return
|
||||||
|
# Usernames are case-insensitive, passwords are NOT.
|
||||||
if username.lower() == conf['login']['user'].lower() and password == conf['login']['password']:
|
if username.lower() == conf['login']['user'].lower() and password == conf['login']['password']:
|
||||||
realuser = conf['login']['user']
|
realuser = conf['login']['user']
|
||||||
irc.users[source].identified = realuser
|
irc.users[source].identified = realuser
|
||||||
@ -41,7 +48,39 @@ def identify(irc, source, args):
|
|||||||
irc.name, username, u.nick, u.ident, u.host, u.uid)
|
irc.name, username, u.nick, u.ident, u.host, u.uid)
|
||||||
|
|
||||||
def listcommands(irc, source, args):
|
def listcommands(irc, source, args):
|
||||||
|
"""takes no arguments.
|
||||||
|
|
||||||
|
Returns a list of available commands PyLink has to offer."""
|
||||||
cmds = list(utils.bot_commands.keys())
|
cmds = list(utils.bot_commands.keys())
|
||||||
cmds.sort()
|
cmds.sort()
|
||||||
utils.msg(irc, source, 'Available commands include: %s' % ', '.join(cmds))
|
utils.msg(irc, source, 'Available commands include: %s' % ', '.join(cmds))
|
||||||
|
utils.msg(irc, source, 'To see help on a specific command, type \x02help <command>\x02.')
|
||||||
utils.add_cmd(listcommands, 'list')
|
utils.add_cmd(listcommands, 'list')
|
||||||
|
|
||||||
|
@utils.add_cmd
|
||||||
|
def help(irc, source, args):
|
||||||
|
"""<command>
|
||||||
|
|
||||||
|
Gives help for <command>, if it is available."""
|
||||||
|
try:
|
||||||
|
command = args[0].lower()
|
||||||
|
except IndexError: # No argument given, just return 'list' output
|
||||||
|
listcommands(irc, source, args)
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
func = utils.bot_commands[command]
|
||||||
|
except KeyError:
|
||||||
|
utils.msg(irc, source, 'Error: no such command %r.' % command)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
doc = func.__doc__
|
||||||
|
if doc:
|
||||||
|
lines = doc.split('\n')
|
||||||
|
# Bold the first line, which usually just tells you what
|
||||||
|
# arguments the command takes.
|
||||||
|
lines[0] = '\x02%s %s\x02' % (command, lines[0])
|
||||||
|
for line in lines:
|
||||||
|
utils.msg(irc, source, line.strip())
|
||||||
|
else:
|
||||||
|
utils.msg(irc, source, 'Error: Command %r doesn\'t offer any help.' % command)
|
||||||
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user