3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

Merge branch 'hide-aliases' into devel

This commit is contained in:
James Lu 2017-07-10 22:00:29 -07:00
commit 6437721ec9
6 changed files with 32 additions and 30 deletions

View File

@ -208,9 +208,7 @@ def setacc(irc, source, args):
# Join the Automode bot to the channel if not explicitly told to.
modebot.join(ircobj, channel)
modebot.add_cmd(setacc, 'setaccess')
modebot.add_cmd(setacc, 'set')
modebot.add_cmd(setacc, featured=True)
modebot.add_cmd(setacc, aliases=('setaccess', 'set'), featured=True)
def delacc(irc, source, args):
"""<channel/chanpair> <mask>
@ -243,9 +241,7 @@ def delacc(irc, source, args):
log.debug("Automode: purging empty channel pair %s/%s", ircobj.name, channel)
del db[ircobj.name+channel]
modebot.add_cmd(delacc, 'delaccess')
modebot.add_cmd(delacc, 'del')
modebot.add_cmd(delacc, featured=True)
modebot.add_cmd(delacc, aliases=('delaccess', 'del'), featured=True)
def listacc(irc, source, args):
"""<channel/chanpair>
@ -273,8 +269,7 @@ def listacc(irc, source, args):
reply(irc, "[%s] \x02%s\x02 has modes +\x02%s\x02" % (entrynum, mask, modes), private=True)
reply(irc, "End of Automode entries list.", private=True)
modebot.add_cmd(listacc, featured=True)
modebot.add_cmd(listacc, 'listaccess')
modebot.add_cmd(listacc, featured=True, aliases=('listacc',))
def save(irc, source, args):
"""takes no arguments.
@ -304,9 +299,7 @@ def syncacc(irc, source, args):
reply(irc, 'Done.')
modebot.add_cmd(syncacc, featured=True)
modebot.add_cmd(syncacc, 'sync')
modebot.add_cmd(syncacc, 'syncaccess')
modebot.add_cmd(syncacc, featured=True, aliases=('sync', 'syncaccess'))
def clearacc(irc, source, args):
"""<channel>
@ -329,6 +322,4 @@ def clearacc(irc, source, args):
else:
error(irc, "No Automode access entries exist for \x02%s\x02." % channel)
modebot.add_cmd(clearacc, 'clearaccess')
modebot.add_cmd(clearacc, 'clear')
modebot.add_cmd(clearacc, featured=True)
modebot.add_cmd(clearacc, aliases=('clearaccess', 'clearacc'), featured=True)

View File

@ -193,7 +193,6 @@ def part(irc, source, args):
irc.reply("Done.")
irc.call_hooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}])
@utils.add_cmd
def msg(irc, source, args):
"""[<source>] <target> <text>
@ -239,4 +238,4 @@ def msg(irc, source, args):
irc.message(sourceuid, real_target, text)
irc.reply("Done.")
irc.call_hooks([sourceuid, 'PYLINK_BOTSPLUGIN_MSG', {'target': real_target, 'text': text, 'parse_as': 'PRIVMSG'}])
utils.add_cmd(msg, 'say')
utils.add_cmd(msg, aliases=('say',))

View File

@ -31,7 +31,8 @@ utils.add_hook(hook_privmsg, 'PRIVMSG')
# Example command function. @utils.add_cmd binds it to an IRC command of the same name,
# but you can also use a different name by specifying a second 'name' argument (see below).
@utils.add_cmd
#@utils.add_cmd
# irc: The IRC object where the command was called.
# source: The UID/numeric of the calling user.
# args: A list of command args (excluding the command name) that the command was called with.
@ -64,6 +65,5 @@ def randint(irc, source, args):
# it will send replies into the channel instead of in your PM.
irc.reply(str(n))
# You can also bind a command function multiple times, and/or to different command names via a
# second argument.
utils.add_cmd(randint, "random")
# You can bind a command function to multiple names using the 'aliases' option.
utils.add_cmd(randint, "random", aliases=("randint", "getrandint"))

View File

@ -59,4 +59,3 @@ def greet(irc, source, args):
# 2) Instead of using utils.add_cmd(function, 'name'), bind functions to your ServiceBot instance.
# You can also use the featured=True argument to display the command's syntax directly in 'list'.
servicebot.add_cmd(greet, featured=True)
servicebot.add_cmd(greet, 'g')

View File

@ -40,8 +40,7 @@ def dice(irc, source, args):
s = 'You rolled %s: %s (total: %s)' % (args[0], ' '.join([str(x) for x in results]), sum(results))
reply(irc, s)
gameclient.add_cmd(dice, 'd')
gameclient.add_cmd(dice, featured=True)
gameclient.add_cmd(dice, aliases=('d'), featured=True)
eightball_responses = ["It is certain.",
"It is decidedly so.",
@ -69,9 +68,7 @@ def eightball(irc, source, args):
Asks the Magic 8-ball a question.
"""
reply(irc, random.choice(eightball_responses))
gameclient.add_cmd(eightball, featured=True)
gameclient.add_cmd(eightball, '8ball')
gameclient.add_cmd(eightball, '8b')
gameclient.add_cmd(eightball, featured=True, aliases=('8ball', '8b'))
def die(irc=None):
utils.unregisterService('games')

View File

@ -217,6 +217,9 @@ class ServiceBot():
# List of command names to "feature"
self.featured_cmds = set()
# Maps command aliases to the respective primary commands
self.alias_cmds = {}
if default_help:
self.add_cmd(self.help)
@ -337,7 +340,7 @@ class ServiceBot():
log.exception('Unhandled exception caught in command %r', cmd)
self.reply(irc, 'Uncaught exception in command %r: %s: %s' % (cmd, type(e).__name__, str(e)))
def add_cmd(self, func, name=None, featured=False):
def add_cmd(self, func, name=None, featured=False, aliases=None):
"""Binds an IRC command function to the given command name."""
if name is None:
name = func.__name__
@ -347,6 +350,12 @@ class ServiceBot():
if featured:
self.featured_cmds.add(name)
# If this is an alias, store the primary command in the alias_cmds dict
if aliases is not None:
for alias in aliases:
self.add_cmd(func, name=alias) # Bind the alias as well.
self.alias_cmds[alias] = name
self.commands[name].append(func)
return func
@ -417,7 +426,14 @@ class ServiceBot():
_reply_format(next_line)
else:
_reply("Error: Command %r doesn't offer any help." % command)
return
# Regardless of whether help text is available, mention aliases.
if not shortform:
if command in self.alias_cmds:
_reply('Alias for %s.' % self.alias_cmds[command])
aliases = set(alias for alias, primary in self.alias_cmds.items() if primary == command)
if aliases:
_reply('Available aliases: %s' % ', '.join(aliases))
def help(self, irc, source, args):
"""<command>
@ -449,8 +465,8 @@ class ServiceBot():
except IndexError:
plugin_filter = None
# Don't show CTCP handlers in the public command list.
cmds = sorted(cmd for cmd in self.commands.keys() if '\x01' not in cmd)
# Don't show CTCP handlers or aliases in the public command list.
cmds = sorted(cmd for cmd in self.commands.keys() if '\x01' not in cmd and cmd not in self.alias_cmds)
if plugin_filter is not None:
# Filter by plugin, if the option was given.