Fix some things
This commit is contained in:
parent
bf4c062d43
commit
0a7f80df21
4 changed files with 37 additions and 3 deletions
|
@ -24,6 +24,7 @@ from mautrix.types import (UserID, SyncToken, FilterID, ContentURI, StrippedStat
|
||||||
EventType, Filter, RoomFilter, RoomEventFilter)
|
EventType, Filter, RoomFilter, RoomEventFilter)
|
||||||
from mautrix.client import InternalEventType
|
from mautrix.client import InternalEventType
|
||||||
|
|
||||||
|
from .lib.store_proxy import ClientStoreProxy
|
||||||
from .db import DBClient
|
from .db import DBClient
|
||||||
from .matrix import MaubotMatrixClient
|
from .matrix import MaubotMatrixClient
|
||||||
|
|
||||||
|
@ -58,7 +59,8 @@ class Client:
|
||||||
self.remote_avatar_url = None
|
self.remote_avatar_url = None
|
||||||
self.client = MaubotMatrixClient(mxid=self.id, base_url=self.homeserver,
|
self.client = MaubotMatrixClient(mxid=self.id, base_url=self.homeserver,
|
||||||
token=self.access_token, client_session=self.http_client,
|
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_initial_sync = True
|
||||||
self.client.ignore_first_sync = True
|
self.client.ignore_first_sync = True
|
||||||
if self.autojoin:
|
if self.autojoin:
|
||||||
|
@ -107,13 +109,13 @@ class Client:
|
||||||
self.db_instance.enabled = False
|
self.db_instance.enabled = False
|
||||||
return
|
return
|
||||||
if not self.filter_id:
|
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(
|
room=RoomFilter(
|
||||||
timeline=RoomEventFilter(
|
timeline=RoomEventFilter(
|
||||||
limit=50,
|
limit=50,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
))
|
)))
|
||||||
if self.displayname != "disable":
|
if self.displayname != "disable":
|
||||||
await self.client.set_displayname(self.displayname)
|
await self.client.set_displayname(self.displayname)
|
||||||
if self.avatar_url != "disable":
|
if self.avatar_url != "disable":
|
||||||
|
|
30
maubot/lib/store_proxy.py
Normal file
30
maubot/lib/store_proxy.py
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
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)
|
|
@ -57,6 +57,7 @@ class PluginMeta(SerializableAttrs['PluginMeta']):
|
||||||
|
|
||||||
maubot: Version = Version(__version__)
|
maubot: Version = Version(__version__)
|
||||||
database: bool = False
|
database: bool = False
|
||||||
|
config: bool = False
|
||||||
webapp: bool = False
|
webapp: bool = False
|
||||||
license: str = ""
|
license: str = ""
|
||||||
extra_files: List[str] = []
|
extra_files: List[str] = []
|
||||||
|
|
|
@ -18,6 +18,7 @@ from http import HTTPStatus
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from sqlalchemy.exc import OperationalError, IntegrityError
|
from sqlalchemy.exc import OperationalError, IntegrityError
|
||||||
|
|
||||||
|
|
||||||
class _Response:
|
class _Response:
|
||||||
@property
|
@property
|
||||||
def body_not_json(self) -> web.Response:
|
def body_not_json(self) -> web.Response:
|
||||||
|
|
Loading…
Reference in a new issue