aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-02-14 10:36:11 +0000
committerGravatar jesopo2019-02-14 10:36:11 +0000
commit708ba2ddc7cfdded43451ea2508b96bd357c86ae (patch)
tree2e3bd28a2f023d0b7ca2e0b54eabe2fd53e4452c /src
parentDon't crash when we try to send a message to channel we're not in (diff)
signature
Support one-shot event hooks (src/EventManager.py)
Diffstat (limited to 'src')
-rw-r--r--src/EventManager.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/EventManager.py b/src/EventManager.py
index 01f00342..12ec524c 100644
--- a/src/EventManager.py
+++ b/src/EventManager.py
@@ -28,11 +28,13 @@ class Event(object):
self.eaten = True
class EventCallback(object):
- def __init__(self, function: CALLBACK_TYPE, priority: int, kwargs: dict):
+ def __init__(self, function: CALLBACK_TYPE, priority: int, kwargs: dict,
+ one_shot: bool=False):
self.function = function
self.priority = priority
self.kwargs = kwargs
self.docstring = utils.parse.docstring(function.__doc__ or "")
+ self._one_shot = one_shot
def call(self, event: Event) -> typing.Any:
return self.function(event)
@@ -206,6 +208,9 @@ class EventHook(object):
else:
raise
+ if hook._one_shot:
+ self.unhook(hook)
+
total_milliseconds = (time.monotonic() - start) * 1000
self.log.trace("event \"%s\" called in %fms",
[event_path, total_milliseconds])