Browse Source

support command aliases in bot help

tags/v0.1
Ben Kurtovic 13 years ago
parent
commit
50ef200a22
2 changed files with 21 additions and 6 deletions
  1. +8
    -3
      irc/commands/help.py
  2. +13
    -3
      irc/triggers.py

+ 8
- 3
irc/commands/help.py View File

@@ -2,6 +2,8 @@


"""Generates help information.""" """Generates help information."""


from irc import triggers

connection, data = None, None connection, data = None, None


def call(c, d): def call(c, d):
@@ -22,9 +24,12 @@ def do_command_help():


try: try:
exec "from irc.commands import %s as this_command" % command exec "from irc.commands import %s as this_command" % command
except ImportError:
connection.reply(data.chan, data.nick, "command \x0303%s\x0301 not found!" % command)
return
except ImportError: # if we can't find it directly, this could be an alias for another command
try:
this_command = triggers.get_alias(command)
except KeyError:
connection.reply(data.chan, data.nick, "command \x0303%s\x0301 not found!" % command)
return


info = this_command.__doc__ info = this_command.__doc__




+ 13
- 3
irc/triggers.py View File

@@ -4,9 +4,19 @@


from irc.commands import test, help, git, link, chanops from irc.commands import test, help, git, link, chanops


def get_alias(key):
"""used by help.py, e.g. so we know !voice corresponds to chanops.py"""
aliases = {
"voice": chanops,
"devoice": chanops,
"op": chanops,
"deop": chanops,
}
return aliases[key]

def check(connection, data, hook): def check(connection, data, hook):
data.parse_args() # parse command arguments into data.command and data.args data.parse_args() # parse command arguments into data.command and data.args
if hook == "join": if hook == "join":
pass pass


@@ -19,10 +29,10 @@ def check(connection, data, hook):
if hook == "msg": if hook == "msg":
if data.command == "!test": if data.command == "!test":
test.call(connection, data) test.call(connection, data)
elif data.command == "!help": elif data.command == "!help":
help.call(connection, data) help.call(connection, data)
elif data.command == "!git": elif data.command == "!git":
git.call(connection, data) git.call(connection, data)




Loading…
Cancel
Save