Rework methods to manage event handlers

This commit is contained in:
Lonami Exo
2022-01-28 14:12:32 +01:00
parent 9726169a8c
commit 0802f7e6b2
8 changed files with 184 additions and 54 deletions

View File

@@ -1,4 +1,5 @@
import abc
import functools
class StopPropagation(Exception):
@@ -41,3 +42,23 @@ class EventBuilder(abc.ABC):
`self_id` should be the current user's ID, since it is required
for some events which lack this information but still need it.
"""
@functools.total_ordering
class EventHandler:
__slots__ = ('_event', '_callback', '_priority', '_filter')
def __init__(self, event, callback, priority, filter):
self._event = event
self._callback = callback
self._priority = priority
self._filter = filter
def __eq__(self, other):
return self is other
def __lt__(self, other):
return self._priority < other._priority
def __call__(self, *args, **kwargs):
return self._callback(*args, **kwargs)