fix: python and enums...
This commit is contained in:
parent
a22886334c
commit
c3783253e1
2 changed files with 5 additions and 9 deletions
|
@ -66,13 +66,9 @@ class AppService:
|
||||||
|
|
||||||
def callback(self, room: str, event: EventType | str = EventType.MESSAGE) -> Callable:
|
def callback(self, room: str, event: EventType | str = EventType.MESSAGE) -> Callable:
|
||||||
def wrapper(func: Callable[[Event], Awaitable[None]]):
|
def wrapper(func: Callable[[Event], Awaitable[None]]):
|
||||||
if isinstance(event, str):
|
if event not in self._callbacks:
|
||||||
key = EventType[event]
|
self._callbacks[event] = {}
|
||||||
else:
|
self._callbacks[event][room] = func
|
||||||
key = event
|
|
||||||
if event.type not in self._callbacks:
|
|
||||||
self._callbacks[event.type] = {}
|
|
||||||
self._callbacks[key][room] = func
|
|
||||||
return func
|
return func
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -7,7 +7,7 @@ class User:
|
||||||
avatar_url: str = ""
|
avatar_url: str = ""
|
||||||
display_name: str = ""
|
display_name: str = ""
|
||||||
|
|
||||||
class EventType(Enum):
|
class EventType(StrEnum):
|
||||||
MESSAGE = "m.room.message"
|
MESSAGE = "m.room.message"
|
||||||
MEMBER = "m.room.member"
|
MEMBER = "m.room.member"
|
||||||
REDACTION = "m.room.redaction"
|
REDACTION = "m.room.redaction"
|
||||||
|
|
Loading…
Reference in a new issue