From a6d44ebb0b455ae5d24bce091b1f0ba0062e5163 Mon Sep 17 00:00:00 2001 From: Edward Powell Date: Sun, 19 May 2013 15:07:12 -0400 Subject: [PATCH] [core, reload] Sove long-standing error where function names in different modules could conflict. Our issue number for this is #258. myano also has it in his as #45. --- willie/bot.py | 14 +++++++------- willie/modules/reload.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/willie/bot.py b/willie/bot.py index 144d8782c6..2412bb338a 100644 --- a/willie/bot.py +++ b/willie/bot.py @@ -118,7 +118,7 @@ def contains(self, key): def setup(self): stderr("\nWelcome to Willie. Loading modules...\n\n") - self.variables = {} + self.callables = set() filenames = self.config.enumerate_modules() # Coretasks is special. No custom user coretasks. @@ -158,17 +158,18 @@ def register(self, variables): trigger commands and rules to allow the function to be triggered. """ # This is used by reload.py, hence it being methodised - for name, obj in variables.iteritems(): + for obj in variables.itervalues(): if hasattr(obj, 'commands') or hasattr(obj, 'rule'): - self.variables[name] = obj + self.callables.add(obj) def bind_commands(self): self.commands = {'high': {}, 'medium': {}, 'low': {}} def bind(self, priority, regexp, func): - # register documentation + # Function name is no longer used for anything, as far as I know, + # but we're going to keep it around anyway. if not hasattr(func, 'name'): - func.name = func.__name__ + func.name = __name__ # At least for now, only account for the first command listed. if func.__doc__ and hasattr(func, 'commands') and func.commands[0]: if hasattr(func, 'example'): @@ -184,8 +185,7 @@ def sub(pattern, self=self): pattern = pattern.replace('$nickname', r'%s' % re.escape(self.nick)) return pattern.replace('$nick', r'%s[,:] +' % re.escape(self.nick)) - for name, func in self.variables.iteritems(): - # print name, func + for func in self.callables: if not hasattr(func, 'priority'): func.priority = 'medium' diff --git a/willie/modules/reload.py b/willie/modules/reload.py index 9853a9cbbf..28306bcc36 100644 --- a/willie/modules/reload.py +++ b/willie/modules/reload.py @@ -23,8 +23,8 @@ def f_reload(willie, trigger): if name == willie.config.owner: return willie.reply('What?') - if (not name) or (name == '*') or (name == 'ALL THE THINGS'): - willie.variables = None + if (not name) or (name == '*') or (name.upper() == 'ALL THE THINGS'): + willie.callables = None willie.commands = None willie.setup() return willie.reply('done')