feat: Добавлена обработка сообщений, ивентов и подписок
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import inspect
|
||||
|
||||
_EVENTS = {}
|
||||
|
||||
def event(event_name: str, priority: int = 9999):
|
||||
def inlineEvent(func):
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
raise TypeError(f'Декоратор event поддерживает только подпрограммы')
|
||||
if event_name not in _EVENTS:
|
||||
_EVENTS[event_name] = []
|
||||
|
||||
_EVENTS[event_name].append({'function': func, 'priority': priority})
|
||||
_EVENTS[event_name].sort(key = lambda x: x['priority'])
|
||||
|
||||
return func
|
||||
return inlineEvent
|
||||
|
||||
async def call_event(event_name: str, *args, **kwargs):
|
||||
if event_name not in _EVENTS:
|
||||
return
|
||||
|
||||
for item in _EVENTS[event_name]:
|
||||
await item['function'](*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user