mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-24 03:33:10 +01:00
world: rename command_hooks=>hooks, bot_commands=>commands
This commit is contained in:
parent
cc171eb79a
commit
bbedd38703
@ -175,11 +175,11 @@ class Irc():
|
||||
cmd_args = text.strip().split(' ')
|
||||
cmd = cmd_args[0].lower()
|
||||
cmd_args = cmd_args[1:]
|
||||
if cmd not in world.bot_commands:
|
||||
if cmd not in world.commands:
|
||||
self.msg(self.called_by or source, 'Error: Unknown command %r.' % cmd)
|
||||
return
|
||||
log.info('(%s) Calling command %r for %s', self.name, cmd, utils.getHostmask(self, source))
|
||||
for func in world.bot_commands[cmd]:
|
||||
for func in world.commands[cmd]:
|
||||
try:
|
||||
func(self, source, cmd_args)
|
||||
except utils.NotAuthenticatedError:
|
||||
@ -267,7 +267,7 @@ class Irc():
|
||||
log.debug('(%s) Parsed args %r received from %s handler (calling hook %s)',
|
||||
self.name, parsed_args, command, hook_cmd)
|
||||
# Iterate over hooked functions, catching errors accordingly
|
||||
for hook_func in world.command_hooks[hook_cmd]:
|
||||
for hook_func in world.hooks[hook_cmd]:
|
||||
try:
|
||||
log.debug('(%s) Calling hook function %s from plugin "%s"', self.name,
|
||||
hook_func, hook_func.__module__)
|
||||
|
@ -51,10 +51,10 @@ def listcommands(irc, source, args):
|
||||
"""takes no arguments.
|
||||
|
||||
Returns a list of available commands PyLink has to offer."""
|
||||
cmds = list(world.bot_commands.keys())
|
||||
cmds = list(world.commands.keys())
|
||||
cmds.sort()
|
||||
for idx, cmd in enumerate(cmds):
|
||||
nfuncs = len(world.bot_commands[cmd])
|
||||
nfuncs = len(world.commands[cmd])
|
||||
if nfuncs > 1:
|
||||
cmds[idx] = '%s(x%s)' % (cmd, nfuncs)
|
||||
irc.msg(irc.called_by, 'Available commands include: %s' % ', '.join(cmds))
|
||||
@ -71,11 +71,11 @@ def help(irc, source, args):
|
||||
except IndexError: # No argument given, just return 'list' output
|
||||
listcommands(irc, source, args)
|
||||
return
|
||||
if command not in world.bot_commands:
|
||||
if command not in world.commands:
|
||||
irc.msg(source, 'Error: Unknown command %r.' % command)
|
||||
return
|
||||
else:
|
||||
funcs = world.bot_commands[command]
|
||||
funcs = world.commands[command]
|
||||
if len(funcs) > 1:
|
||||
irc.msg(irc.called_by, 'The following \x02%s\x02 plugins bind to the \x02%s\x02 command: %s'
|
||||
% (len(funcs), command, ', '.join([func.__module__ for func in funcs])))
|
||||
|
@ -26,16 +26,16 @@ class TestUtils(unittest.TestCase):
|
||||
utils.add_cmd(dummyf)
|
||||
utils.add_cmd(dummyf, 'TEST')
|
||||
# All command names should be automatically lowercased.
|
||||
self.assertIn('dummyf', world.bot_commands)
|
||||
self.assertIn('test', world.bot_commands)
|
||||
self.assertNotIn('TEST', world.bot_commands)
|
||||
self.assertIn('dummyf', world.commands)
|
||||
self.assertIn('test', world.commands)
|
||||
self.assertNotIn('TEST', world.commands)
|
||||
|
||||
def test_add_hook(self):
|
||||
utils.add_hook(dummyf, 'join')
|
||||
self.assertIn('JOIN', world.command_hooks)
|
||||
self.assertIn('JOIN', world.hooks)
|
||||
# Command names stored in uppercase.
|
||||
self.assertNotIn('join', world.command_hooks)
|
||||
self.assertIn(dummyf, world.command_hooks['JOIN'])
|
||||
self.assertNotIn('join', world.hooks)
|
||||
self.assertIn(dummyf, world.hooks['JOIN'])
|
||||
|
||||
def testIsNick(self):
|
||||
self.assertFalse(utils.isNick('abcdefgh', nicklen=3))
|
||||
|
4
utils.py
4
utils.py
@ -106,12 +106,12 @@ def add_cmd(func, name=None):
|
||||
if name is None:
|
||||
name = func.__name__
|
||||
name = name.lower()
|
||||
world.bot_commands[name].append(func)
|
||||
world.commands[name].append(func)
|
||||
|
||||
def add_hook(func, command):
|
||||
"""Add a hook <func> for command <command>."""
|
||||
command = command.upper()
|
||||
world.command_hooks[command].append(func)
|
||||
world.hooks[command].append(func)
|
||||
|
||||
def toLower(irc, text):
|
||||
"""Returns a lowercase representation of text based on the IRC object's
|
||||
|
6
world.py
6
world.py
@ -8,10 +8,10 @@ import subprocess
|
||||
# for a testcase.
|
||||
testing = True
|
||||
|
||||
global bot_commands, command_hooks
|
||||
global commands, hooks
|
||||
# This should be a mapping of command names to functions
|
||||
bot_commands = defaultdict(list)
|
||||
command_hooks = defaultdict(list)
|
||||
commands = defaultdict(list)
|
||||
hooks = defaultdict(list)
|
||||
networkobjects = {}
|
||||
schedulers = {}
|
||||
plugins = {}
|
||||
|
Loading…
Reference in New Issue
Block a user