diff --git a/maubot/__init__.py b/maubot/__init__.py index 9ca0322..71755b9 100644 --- a/maubot/__init__.py +++ b/maubot/__init__.py @@ -1,3 +1,4 @@ from .plugin_base import Plugin from .plugin_server import PluginWebApp from .matrix import MaubotMatrixClient as Client, MaubotMessageEvent as MessageEvent +from .__meta__ import __version__ diff --git a/maubot/cli/commands/auth.py b/maubot/cli/commands/auth.py index 66c8b6e..390363f 100644 --- a/maubot/cli/commands/auth.py +++ b/maubot/cli/commands/auth.py @@ -20,7 +20,6 @@ from yarl import URL import aiohttp import click -from ..config import get_token from ..cliq import cliq history_count: int = 10 diff --git a/maubot/client.py b/maubot/client.py index 7d0a6de..074e85e 100644 --- a/maubot/client.py +++ b/maubot/client.py @@ -110,6 +110,19 @@ class Client: self.crypto = OlmMachine(self.client, self.crypto_store, self.global_state_store) self.client.crypto = self.crypto + def _remove_crypto_event_handlers(self) -> None: + if not self.crypto: + return + handlers = [ + (InternalEventType.DEVICE_OTK_COUNT, self.crypto.handle_otk_count), + (InternalEventType.DEVICE_LISTS, self.crypto.handle_device_lists), + (EventType.TO_DEVICE_ENCRYPTED, self.crypto.handle_to_device_event), + (EventType.ROOM_KEY_REQUEST, self.crypto.handle_room_key_request), + (EventType.ROOM_MEMBER, self.crypto.handle_member_event), + ] + for event_type, func in handlers: + self.client.remove_event_handler(event_type, func) + def _set_sync_ok(self, ok: bool) -> Callable[[Dict[str, Any]], Awaitable[None]]: async def handler(data: Dict[str, Any]) -> None: self.sync_ok = ok @@ -156,7 +169,7 @@ class Client: self.db_instance.enabled = False else: self.log.warning(f"Failed to get /account/whoami, " - f"retrying in {(try_n + 1) * 10}s: {e}") + f"retrying in {(try_n + 1) * 10}s: {e}") _ = asyncio.ensure_future(self.start(try_n + 1), loop=self.loop) return if whoami.user_id != self.id: @@ -316,6 +329,9 @@ class Client: raise ValueError(f"Device ID mismatch: {whoami.device_id}") new_client.sync_store = SyncStoreProxy(self.db_instance) self.stop_sync() + self._remove_crypto_event_handlers() + new_client.event_handlers = self.client.event_handlers + new_client.global_event_handlers = self.client.global_event_handlers self.client = new_client self.db_instance.homeserver = homeserver self.db_instance.access_token = access_token diff --git a/requirements.txt b/requirements.txt index bc888b7..27126f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -mautrix>=0.11,<0.12 +mautrix>=0.11,<0.13 aiohttp>=3,<4 yarl>=1,<2 SQLAlchemy>=1,<1.4