Add an option in events to make reply() act as respond()

Should be a command handler argument or have some other way of making
it configurable in the future.
This commit is contained in:
Tulir Asokan 2019-06-09 18:22:27 +03:00
parent 4210f3195f
commit c5337f96a3

View File

@ -40,11 +40,13 @@ def parse_markdown(markdown: str, allow_html: bool = False) -> Tuple[str, str]:
class MaubotMessageEvent(MessageEvent): class MaubotMessageEvent(MessageEvent):
client: MatrixClient client: MatrixClient
disable_reply: bool
def __init__(self, base: MessageEvent, client: MatrixClient): def __init__(self, base: MessageEvent, client: MatrixClient):
super().__init__(**{a.name.lstrip("_"): getattr(base, a.name) super().__init__(**{a.name.lstrip("_"): getattr(base, a.name)
for a in attr.fields(MessageEvent)}) for a in attr.fields(MessageEvent)})
self.client = client self.client = client
self.disable_reply = False
def respond(self, content: Union[str, MessageEventContent], def respond(self, content: Union[str, MessageEventContent],
event_type: EventType = EventType.ROOM_MESSAGE, markdown: bool = True, event_type: EventType = EventType.ROOM_MESSAGE, markdown: bool = True,
@ -55,7 +57,7 @@ class MaubotMessageEvent(MessageEvent):
content.format = Format.HTML content.format = Format.HTML
content.body, content.formatted_body = parse_markdown(content.body, content.body, content.formatted_body = parse_markdown(content.body,
allow_html=html_in_markdown) allow_html=html_in_markdown)
if reply: if reply and not self.disable_reply:
content.set_reply(self) content.set_reply(self)
return self.client.send_message_event(self.room_id, event_type, content) return self.client.send_message_event(self.room_id, event_type, content)