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 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

View file

@ -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"