From 7679a0e97cf842f47f083c01baa1ba4199266f9a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 4 Mar 2022 15:38:34 +0200 Subject: [PATCH] Update mautrix-python --- maubot/client.py | 1 + maubot/matrix.py | 38 ++++++++++++++++++++------------------ requirements.txt | 2 +- setup.py | 4 ++-- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/maubot/client.py b/maubot/client.py index 9601712..0ebbaf7 100644 --- a/maubot/client.py +++ b/maubot/client.py @@ -168,6 +168,7 @@ class Client: self.log.warning("Ignoring start() call to started client") return try: + await self.client.versions() whoami = await self.client.whoami() except MatrixInvalidToken as e: self.log.error(f"Invalid token: {e}. Disabling client") diff --git a/maubot/matrix.py b/maubot/matrix.py index beca521..8481036 100644 --- a/maubot/matrix.py +++ b/maubot/matrix.py @@ -39,15 +39,15 @@ class MaubotHTMLParser(MatrixParser[HumanReadableString]): fs = HumanReadableString -def parse_formatted(message: str, allow_html: bool = False, render_markdown: bool = True - ) -> Tuple[str, str]: +async def parse_formatted(message: str, allow_html: bool = False, render_markdown: bool = True + ) -> Tuple[str, str]: if render_markdown: html = markdown.render(message, allow_html=allow_html) elif allow_html: html = message else: return message, escape(message) - return MaubotHTMLParser.parse(html).text, html + return (await MaubotHTMLParser().parse(html)).text, html class MaubotMessageEvent(MessageEvent): @@ -60,17 +60,17 @@ class MaubotMessageEvent(MessageEvent): self.client = client self.disable_reply = client.disable_replies - def respond(self, content: Union[str, MessageEventContent], - event_type: EventType = EventType.ROOM_MESSAGE, markdown: bool = True, - allow_html: bool = False, reply: Union[bool, str] = False, - edits: Optional[Union[EventID, MessageEvent]] = None) -> Awaitable[EventID]: + async def respond(self, content: Union[str, MessageEventContent], + event_type: EventType = EventType.ROOM_MESSAGE, markdown: bool = True, + allow_html: bool = False, reply: Union[bool, str] = False, + edits: Optional[Union[EventID, MessageEvent]] = None) -> EventID: if isinstance(content, str): content = TextMessageEventContent(msgtype=MessageType.NOTICE, body=content) if allow_html or markdown: content.format = Format.HTML - content.body, content.formatted_body = parse_formatted(content.body, - render_markdown=markdown, - allow_html=allow_html) + content.body, content.formatted_body = await parse_formatted( + content.body, render_markdown=markdown, allow_html=allow_html + ) if edits: content.set_edit(edits) elif reply: @@ -82,7 +82,7 @@ class MaubotMessageEvent(MessageEvent): f': {fmt_body}') else: content.set_reply(self) - return self.client.send_message_event(self.room_id, event_type, content) + return await self.client.send_message_event(self.room_id, event_type, content) def reply(self, content: Union[str, MessageEventContent], event_type: EventType = EventType.ROOM_MESSAGE, markdown: bool = True, @@ -110,20 +110,22 @@ class MaubotMatrixClient(MatrixClient): super().__init__(*args, **kwargs) self.disable_replies = False - def send_markdown(self, room_id: RoomID, markdown: str, *, allow_html: bool = False, - msgtype: MessageType = MessageType.TEXT, - edits: Optional[Union[EventID, MessageEvent]] = None, - relates_to: Optional[RelatesTo] = None, **kwargs - ) -> Awaitable[EventID]: + async def send_markdown(self, room_id: RoomID, markdown: str, *, allow_html: bool = False, + msgtype: MessageType = MessageType.TEXT, + edits: Optional[Union[EventID, MessageEvent]] = None, + relates_to: Optional[RelatesTo] = None, **kwargs + ) -> EventID: content = TextMessageEventContent(msgtype=msgtype, format=Format.HTML) - content.body, content.formatted_body = parse_formatted(markdown, allow_html=allow_html) + content.body, content.formatted_body = await parse_formatted( + markdown, allow_html=allow_html + ) if relates_to: if edits: raise ValueError("Can't use edits and relates_to at the same time.") content.relates_to = relates_to elif edits: content.set_edit(edits) - return self.send_message(room_id, content, **kwargs) + return await self.send_message(room_id, content, **kwargs) def dispatch_event(self, event: Event, source: SyncStream) -> List[asyncio.Task]: if isinstance(event, MessageEvent) and not isinstance(event, MaubotMessageEvent): diff --git a/requirements.txt b/requirements.txt index f1f5e4d..e221b22 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -mautrix>=0.12.2,<0.13 +mautrix==0.15.0rc4 aiohttp>=3,<4 yarl>=1,<2 SQLAlchemy>=1,<1.4 diff --git a/setup.py b/setup.py index eca1e05..574a1c6 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ setuptools.setup( install_requires=install_requires, extras_require=extras_require, - python_requires="~=3.7", + python_requires="~=3.8", classifiers=[ "Development Status :: 4 - Beta", @@ -48,9 +48,9 @@ setuptools.setup( "Framework :: AsyncIO", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", ], entry_points=""" [console_scripts]