From 0a7f80df21ce3f5a86fa919bd39f10a2343d3ca1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 23 Oct 2019 01:14:39 +0300 Subject: [PATCH] Fix some things --- maubot/client.py | 8 +++++--- maubot/lib/store_proxy.py | 30 ++++++++++++++++++++++++++++++ maubot/loader/abc.py | 1 + maubot/management/api/responses.py | 1 + 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 maubot/lib/store_proxy.py diff --git a/maubot/client.py b/maubot/client.py index 9e1c9cc..41bba84 100644 --- a/maubot/client.py +++ b/maubot/client.py @@ -24,6 +24,7 @@ EventType, Filter, RoomFilter, RoomEventFilter) from mautrix.client import InternalEventType +from .lib.store_proxy import ClientStoreProxy from .db import DBClient from .matrix import MaubotMatrixClient @@ -58,7 +59,8 @@ def __init__(self, db_instance: DBClient) -> None: self.remote_avatar_url = None self.client = MaubotMatrixClient(mxid=self.id, base_url=self.homeserver, token=self.access_token, client_session=self.http_client, - log=self.log, loop=self.loop, store=self.db_instance) + log=self.log, loop=self.loop, + store=ClientStoreProxy(self.db_instance)) self.client.ignore_initial_sync = True self.client.ignore_first_sync = True if self.autojoin: @@ -107,13 +109,13 @@ async def _start(self, try_n: Optional[int] = 0) -> None: self.db_instance.enabled = False return if not self.filter_id: - self.db_instance.filter_id = await self.client.create_filter(Filter( + self.db_instance.edit(filter_id=await self.client.create_filter(Filter( room=RoomFilter( timeline=RoomEventFilter( limit=50, ), ), - )) + ))) if self.displayname != "disable": await self.client.set_displayname(self.displayname) if self.avatar_url != "disable": diff --git a/maubot/lib/store_proxy.py b/maubot/lib/store_proxy.py new file mode 100644 index 0000000..83bec7c --- /dev/null +++ b/maubot/lib/store_proxy.py @@ -0,0 +1,30 @@ +# maubot - A plugin-based Matrix bot system. +# Copyright (C) 2019 Tulir Asokan +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +from mautrix.client import ClientStore +from mautrix.types import SyncToken + + +class ClientStoreProxy(ClientStore): + def __init__(self, db_instance) -> None: + self.db_instance = db_instance + + @property + def next_batch(self) -> SyncToken: + return self.db_instance.next_batch + + @next_batch.setter + def next_batch(self, value: SyncToken) -> None: + self.db_instance.edit(next_batch=value) diff --git a/maubot/loader/abc.py b/maubot/loader/abc.py index eabc728..cb46a4c 100644 --- a/maubot/loader/abc.py +++ b/maubot/loader/abc.py @@ -57,6 +57,7 @@ class PluginMeta(SerializableAttrs['PluginMeta']): maubot: Version = Version(__version__) database: bool = False + config: bool = False webapp: bool = False license: str = "" extra_files: List[str] = [] diff --git a/maubot/management/api/responses.py b/maubot/management/api/responses.py index 5fac09b..b30d49d 100644 --- a/maubot/management/api/responses.py +++ b/maubot/management/api/responses.py @@ -18,6 +18,7 @@ from aiohttp import web from sqlalchemy.exc import OperationalError, IntegrityError + class _Response: @property def body_not_json(self) -> web.Response: