aboutsummaryrefslogtreecommitdiff
path: root/EventManager.py
diff options
context:
space:
mode:
authorGravatar Dan2018-09-01 11:40:57 +0100
committerGravatar GitHub2018-09-01 11:40:57 +0100
commitba065ad646748719aa4ca986193e3d40601fc91e (patch)
treed63acad554abd035c0f2a2692a3756b236e440f9 /EventManager.py
parentMove lists out of scope (diff)
omg it's the future (#15)
* Add Database.UserChannelSettings.find_all_by_setting * Turns out we didn't need find_all_by_setting * Actually, we do need find_all_by_setting * Table name typo * Add Utils.bold and Utils.underline * Added functionality to load, unload and reload modules from a command!
Diffstat (limited to 'EventManager.py')
-rw-r--r--EventManager.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/EventManager.py b/EventManager.py
index 4ca5837c..326192ad 100644
--- a/EventManager.py
+++ b/EventManager.py
@@ -179,7 +179,7 @@ class EventHook(object):
returns.append(hook.call(event))
except Exception as e:
traceback.print_exc()
- self.bot.log.error("failed to call event \"%s", [
+ self.bot.log.error("failed to call event \"%s\"", [
event_path], exc_info=True)
called += 1
@@ -202,11 +202,9 @@ class EventHook(object):
child_name_lower = child_name.lower()
if child_name_lower in self._children:
del self._children[child_name_lower]
- def get_children(self):
- return self._children.keys()
def check_purge(self):
- if len(self.get_hooks()) == 0 and len(self._children
+ if len(self.get_hooks()) == 0 and len(self.get_children()
) == 0 and not self.parent == None:
self.parent.remove_child(self.name)
self.parent.check_purge()
@@ -218,9 +216,16 @@ class EventHook(object):
def purge_context(self, context):
if self.has_context(context):
self.remove_context(context)
- for child in self.get_children():
+ for child_name in self.get_children()[:]:
+ child = self.get_child(child_name)
child.purge_context(context)
+ if child.is_empty():
+ self.remove_child(child_name)
def get_hooks(self):
return sorted(self._hooks + list(itertools.chain.from_iterable(
self._context_hooks.values())), key=lambda e: e.priority)
+ def get_children(self):
+ return list(self._children.keys())
+ def is_empty(self):
+ return len(self.get_hooks() + self.get_children()) == 0