From bbedd387037bfc3e4019149620765adeb3a3ed19 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 27 Sep 2015 10:53:25 -0700 Subject: [PATCH] world: rename command_hooks=>hooks, bot_commands=>commands --- classes.py | 6 +++--- plugins/commands.py | 8 ++++---- tests/test_utils.py | 12 ++++++------ utils.py | 4 ++-- world.py | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/classes.py b/classes.py index c920719..dc0e273 100644 --- a/classes.py +++ b/classes.py @@ -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__) diff --git a/plugins/commands.py b/plugins/commands.py index 1ae0cc6..c44ed3e 100644 --- a/plugins/commands.py +++ b/plugins/commands.py @@ -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]))) diff --git a/tests/test_utils.py b/tests/test_utils.py index 8e0346d..cb88486 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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)) diff --git a/utils.py b/utils.py index 1f68af9..746dd01 100644 --- a/utils.py +++ b/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 for 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 diff --git a/world.py b/world.py index 955bf7e..77c5fa7 100644 --- a/world.py +++ b/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 = {}