Skip to content

Commit

Permalink
[core, reload] Sove long-standing error where function names in diffe…
Browse files Browse the repository at this point in the history
…rent modules could conflict.

Our issue number for this is #258. myano also has it in his as #45.
  • Loading branch information
embolalia committed May 19, 2013
1 parent 632b291 commit a6d44eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions willie/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'):
Expand All @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions willie/modules/reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit a6d44eb

Please sign in to comment.