Update type hints and allow InternalEventTypes for @event.on
This commit is contained in:
parent
ed6055744f
commit
7fcb7cbf0a
@ -16,19 +16,20 @@
|
||||
from typing import Callable, Union, NewType
|
||||
|
||||
from mautrix.types import EventType
|
||||
from mautrix.client import EventHandler
|
||||
from mautrix.client import EventHandler, InternalEventType
|
||||
|
||||
EventHandlerDecorator = NewType("EventHandlerDecorator", Callable[[EventHandler], EventHandler])
|
||||
|
||||
|
||||
def on(var: Union[EventType, EventHandler]) -> Union[EventHandlerDecorator, EventHandler]:
|
||||
def on(var: Union[EventType, InternalEventType, EventHandler]
|
||||
) -> Union[EventHandlerDecorator, EventHandler]:
|
||||
def decorator(func: EventHandler) -> EventHandler:
|
||||
func.__mb_event_handler__ = True
|
||||
if isinstance(var, EventType):
|
||||
if isinstance(var, (EventType, InternalEventType)):
|
||||
func.__mb_event_type__ = var
|
||||
else:
|
||||
func.__mb_event_type__ = EventType.ALL
|
||||
|
||||
return func
|
||||
|
||||
return decorator if isinstance(var, EventType) else decorator(var)
|
||||
return decorator if isinstance(var, (EventType, InternalEventType)) else decorator(var)
|
||||
|
@ -73,7 +73,7 @@ class MaubotMessageEvent(MessageEvent):
|
||||
def mark_read(self) -> Awaitable[None]:
|
||||
return self.client.send_receipt(self.room_id, self.event_id, "m.read")
|
||||
|
||||
def react(self, key: str) -> Awaitable[None]:
|
||||
def react(self, key: str) -> Awaitable[EventID]:
|
||||
return self.client.react(self.room_id, self.event_id, key)
|
||||
|
||||
def edit(self, content: Union[str, MessageEventContent],
|
||||
|
Loading…
Reference in New Issue
Block a user