From 20b90f955b6425d36716b2bf52e50bb034ecba7f Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 28 Aug 2018 12:24:39 +0100 Subject: [PATCH] Check if event objects should be purged after an event is called --- EventManager.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/EventManager.py b/EventManager.py index e17800ae..23faba1b 100644 --- a/EventManager.py +++ b/EventManager.py @@ -127,6 +127,8 @@ class EventHook(object): total_milliseconds = (end - start) * 1000 self.bot.log.debug("event called in %fms", [total_milliseconds]) + self.check_purge() + return returns def get_child(self, child_name): @@ -138,6 +140,17 @@ class EventHook(object): self._child_notify(self, self._children[ child_name_lower]) return self._children[child_name_lower] + + def remove_child(self, child_name): + child_name_lower = child_name.lower() + if child_name_lower in self._children: + del self._children[child_name_lower] + def check_purge(self): + if len(self._hooks) == 0 and len(self._children + ) == 0 and not self.parent == None: + self.parent.remove_child(self.name) + self.parent.check_purge() + def get_hooks(self): return self._hooks def get_children(self):