Skip to content

Commit

Permalink
core: Fix issues with reloading folder modules
Browse files Browse the repository at this point in the history
Closes sopel-irc#899, obviates and closes sopel-irc#932.
  • Loading branch information
embolalia authored and fatalis committed Jan 7, 2016
1 parent fe67c27 commit 0ee01ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ def setup(self):
stderr("Warning: Couldn't load any modules")

def unregister(self, obj):
if not callable(obj):
return
if hasattr(obj, 'rule'): # commands and intents have it added
for rule in obj.rule:
self._callables[obj.priority][rule].remove(obj)
callb_list = self._callables[obj.priority][rule]
if obj in callb_list:
callb_list.remove(obj)
if hasattr(obj, 'interval'):
# TODO this should somehow find the right job to remove, rather than
# clearing the entire queue. Issue #831
self.scheduler.clear_jobs()
if getattr(obj, '__name__', None) == 'shutdown':
if (getattr(obj, '__name__', None) == 'shutdown'
and obj in self.shutdown_methods):
self.shutdown_methods.remove(obj)

def register(self, callables, jobs, shutdowns):
Expand Down
7 changes: 7 additions & 0 deletions sopel/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
if sys.version_info.major >= 3:
basestring = (str, bytes)

# Can be implementation-dependent
_regex_type = type(re.compile(''))


def get_module_description(path):
good_file = (os.path.isfile(path) and path.endswith('.py')
Expand Down Expand Up @@ -108,6 +111,10 @@ def enumerate_modules(config, show_all=False):


def compile_rule(nick, pattern):
# Not sure why this happens on reloads, but it shouldn't cause problems…
if isinstance(pattern, _regex_type):
return pattern

pattern = pattern.replace('$nickname', nick)
pattern = pattern.replace('$nick', r'{}[,:]\s+'.format(nick))
flags = re.IGNORECASE
Expand Down

0 comments on commit 0ee01ac

Please sign in to comment.