aboutsummaryrefslogtreecommitdiff
path: root/EventManager.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-08-28 12:23:57 +0100
committerGravatar jesopo2018-08-28 12:23:57 +0100
commite5a5fa5c4b40918247be8486d27a1676b6d2b044 (patch)
tree70e61a968a20134b01ea4e4f5611e4e254df06ae /EventManager.py
parentPrevent users sending coins to themselves (diff)
signature
modules/logging.py -> IRCLogging.py; IRCLog.py -> IRCBuffer.py; change logging
to be an object on the server object instead of an event call
Diffstat (limited to 'EventManager.py')
-rw-r--r--EventManager.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/EventManager.py b/EventManager.py
index e46d682b..e17800ae 100644
--- a/EventManager.py
+++ b/EventManager.py
@@ -1,4 +1,4 @@
-import traceback
+import time, traceback
PRIORITY_URGENT = 0
PRIORITY_HIGH = 1
@@ -42,9 +42,10 @@ class MultipleEventHook(object):
event_hook.call(max, **kwargs)
class EventHook(object):
- def __init__(self, bot, name=None):
+ def __init__(self, bot, name=None, parent=None):
self.bot = bot
self.name = name
+ self.parent = parent
self._children = {}
self._hooks = []
self._hook_notify = None
@@ -52,6 +53,14 @@ class EventHook(object):
self._call_notify = None
self._stored_events = []
+ def _get_path(self):
+ path = [self.name]
+ parent = self.parent
+ while not parent == None and not parent.name == None:
+ path.append(parent.name)
+ parent = parent.parent
+ return ".".join(path[::-1])
+
def hook(self, function, priority=PRIORITY_LOW, replay=False, **kwargs):
callback = EventCallback(function, self.bot, priority, **kwargs)
if self._hook_notify:
@@ -87,6 +96,10 @@ class EventHook(object):
results = self.call(max=max, **kwargs)
return default if not len(results) else results[0]
def call(self, max=None, **kwargs):
+ self.bot.log.debug("calling event: \"%s\" (params: %s)",
+ [self._get_path(), kwargs])
+ start = time.monotonic()
+
event = Event(self.bot, self.name, **kwargs)
if self._call_notify:
self._call_notify(self, event)
@@ -109,13 +122,18 @@ class EventHook(object):
# message="Failed to call event callback",
# data=traceback.format_exc())
called += 1
+
+ end = time.monotonic()
+ total_milliseconds = (end - start) * 1000
+ self.bot.log.debug("event called in %fms", [total_milliseconds])
+
return returns
def get_child(self, child_name):
child_name_lower = child_name.lower()
if not child_name_lower in self._children:
self._children[child_name_lower] = EventHook(self.bot,
- child_name)
+ child_name, self)
if self._child_notify:
self._child_notify(self, self._children[
child_name_lower])