Add sync filter for bots

This commit is contained in:
Tulir Asokan 2018-10-17 23:43:56 +03:00
parent 3c565c76ec
commit a13fa556a9

View File

@ -19,7 +19,7 @@ import asyncio
import logging import logging
from mautrix.types import (UserID, SyncToken, FilterID, ContentURI, StrippedStateEvent, Membership, from mautrix.types import (UserID, SyncToken, FilterID, ContentURI, StrippedStateEvent, Membership,
EventType) EventType, Filter, RoomFilter, RoomEventFilter)
from .db import DBClient from .db import DBClient
from .matrix import MaubotMatrixClient from .matrix import MaubotMatrixClient
@ -50,11 +50,19 @@ class Client:
async def _start(self) -> None: async def _start(self) -> None:
try: try:
if not self.filter_id:
self.filter_id = await self.client.create_filter(Filter(
room=RoomFilter(
timeline=RoomEventFilter(
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":
await self.client.set_avatar_url(self.avatar_url) await self.client.set_avatar_url(self.avatar_url)
await self.client.start() await self.client.start(self.filter_id)
except Exception: except Exception:
self.log.exception("starting raised exception") self.log.exception("starting raised exception")