forked from adekmaulana/aioaria2-mirror-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistener.py
executable file
·49 lines (35 loc) · 1.22 KB
/
listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from typing import Any, Callable, Optional
from pyrogram.filters import Filter
ListenerFunc = Callable[..., Any]
Decorator = Callable[[ListenerFunc], ListenerFunc]
def priority(_prio: int) -> Decorator:
"""Sets priority on the given listener function."""
def prio_decorator(func: ListenerFunc) -> ListenerFunc:
setattr(func, "_listener_priority", _prio)
return func
return prio_decorator
def filters(_filters: Filter) -> Decorator:
"""Sets filters on the given listener function."""
def filters_decorator(func: ListenerFunc) -> ListenerFunc:
setattr(func, "_listener_filters", _filters)
return func
return filters_decorator
class Listener:
event: str
func: ListenerFunc
plugin: Any
priority: int
filters: Optional[Filter]
def __init__(self,
event: str,
func: ListenerFunc,
plugin: Any,
prio: int,
_filters: Filter = None) -> None:
self.event = event
self.func = func
self.plugin = plugin
self.priority = prio
self.filters = _filters
def __lt__(self, other: "Listener") -> bool:
return self.priority < other.priority