mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
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 typing import Callable, Union, NewType
|
||||||
|
|
||||||
from mautrix.types import EventType
|
from mautrix.types import EventType
|
||||||
from mautrix.client import EventHandler
|
from mautrix.client import EventHandler, InternalEventType
|
||||||
|
|
||||||
EventHandlerDecorator = NewType("EventHandlerDecorator", Callable[[EventHandler], EventHandler])
|
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:
|
def decorator(func: EventHandler) -> EventHandler:
|
||||||
func.__mb_event_handler__ = True
|
func.__mb_event_handler__ = True
|
||||||
if isinstance(var, EventType):
|
if isinstance(var, (EventType, InternalEventType)):
|
||||||
func.__mb_event_type__ = var
|
func.__mb_event_type__ = var
|
||||||
else:
|
else:
|
||||||
func.__mb_event_type__ = EventType.ALL
|
func.__mb_event_type__ = EventType.ALL
|
||||||
|
|
||||||
return func
|
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]:
|
def mark_read(self) -> Awaitable[None]:
|
||||||
return self.client.send_receipt(self.room_id, self.event_id, "m.read")
|
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)
|
return self.client.react(self.room_id, self.event_id, key)
|
||||||
|
|
||||||
def edit(self, content: Union[str, MessageEventContent],
|
def edit(self, content: Union[str, MessageEventContent],
|
||||||
|
Loading…
Reference in New Issue
Block a user