aboutsummaryrefslogtreecommitdiff
path: root/EventManager.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-07-02 12:23:33 +0100
committerGravatar jesopo2018-07-02 12:23:33 +0100
commit035d62f9d4543346d72a08b4b42f23afec9ace49 (patch)
tree8e73212d213bf186b797541803dab2bba5534b97 /EventManager.py
parentDon't make a database cursor per thread as there should only be 1 thread (diff)
signature
Added an event hook priority system
Diffstat (limited to 'EventManager.py')
-rw-r--r--EventManager.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/EventManager.py b/EventManager.py
index 486cc0ec..c1b58d4a 100644
--- a/EventManager.py
+++ b/EventManager.py
@@ -16,9 +16,15 @@ class Event(object):
self.eaten = True
class EventCallback(object):
- def __init__(self, function, bot, **kwargs):
+ PRIORITY_URGENT = 0
+ PRIORITY_HIGH = 1
+ PRIORITY_MEDIUM = 2
+ PRIORITY_LOW = 3
+
+ def __init__(self, function, bot, priority, **kwargs):
self.function = function
self.bot = bot
+ self.priority = priority
self.kwargs = kwargs
def call(self, event):
return self.function(event)
@@ -45,11 +51,13 @@ class EventHook(object):
self._child_notify = None
self._call_notify = None
self._stored_events = []
- def hook(self, function, replay=False, **kwargs):
- callback = EventCallback(function, self.bot, **kwargs)
+ def hook(self, function, priority=EventCallback.PRIORITY_LOW,
+ replay=False, **kwargs):
+ callback = EventCallback(function, self.bot, priority, **kwargs)
if self._hook_notify:
self._hook_notify(self, callback)
self._hooks.append(callback)
+ self._hooks.sort(key=lambda x: x.priority)
if replay:
for event in self._stored_events: