fix: python and enums...

This commit is contained in:
əlemi 2024-01-29 17:57:47 +01:00
parent a22886334c
commit c3783253e1
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 5 additions and 9 deletions

View file

@ -66,13 +66,9 @@ class AppService:
def callback(self, room: str, event: EventType | str = EventType.MESSAGE) -> Callable:
def wrapper(func: Callable[[Event], Awaitable[None]]):
if isinstance(event, str):
key = EventType[event]
else:
key = event
if event.type not in self._callbacks:
self._callbacks[event.type] = {}
self._callbacks[key][room] = func
if event not in self._callbacks:
self._callbacks[event] = {}
self._callbacks[event][room] = func
return func
return wrapper

View file

@ -1,5 +1,5 @@
from typing import Any
from enum import Enum
from enum import StrEnum
from dataclasses import dataclass
@dataclass
@ -7,7 +7,7 @@ class User:
avatar_url: str = ""
display_name: str = ""
class EventType(Enum):
class EventType(StrEnum):
MESSAGE = "m.room.message"
MEMBER = "m.room.member"
REDACTION = "m.room.redaction"