Add html_in_markdown option to reply() and respond()

This commit is contained in:
Tulir Asokan 2019-01-07 09:05:47 +02:00
parent ac69c50b80
commit 401643afba

View File

@ -47,21 +47,23 @@ class MaubotMessageEvent(MessageEvent):
self.client = client self.client = client
def respond(self, content: Union[str, MessageEventContent], def respond(self, content: Union[str, MessageEventContent],
event_type: EventType = EventType.ROOM_MESSAGE, event_type: EventType = EventType.ROOM_MESSAGE, markdown: bool = True,
markdown: bool = True, reply: bool = False) -> Awaitable[EventID]: html_in_markdown: bool = False, reply: bool = False) -> Awaitable[EventID]:
if isinstance(content, str): if isinstance(content, str):
content = TextMessageEventContent(msgtype=MessageType.NOTICE, body=content) content = TextMessageEventContent(msgtype=MessageType.NOTICE, body=content)
if markdown: if markdown:
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)
if reply: if 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)
def reply(self, content: Union[str, MessageEventContent], def reply(self, content: Union[str, MessageEventContent],
event_type: EventType = EventType.ROOM_MESSAGE, event_type: EventType = EventType.ROOM_MESSAGE, markdown: bool = True,
markdown: bool = True) -> Awaitable[EventID]: html_in_markdown: bool = False) -> Awaitable[EventID]:
return self.respond(content, event_type, markdown, reply=True) return self.respond(content, event_type, markdown, reply=True,
html_in_markdown=html_in_markdown)
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")