Update to use new event handling system

TODO: Switch to new command handling system
This commit is contained in:
Tulir Asokan 2018-12-25 00:54:29 +02:00
parent 5e9e1595a3
commit 4cb519a210
2 changed files with 7 additions and 4 deletions

View File

@ -9,3 +9,4 @@ extra_files:
soft_dependencies: soft_dependencies:
- python-magic>=0.4 - python-magic>=0.4
- pillow>=5 - pillow>=5
database: true

View File

@ -22,9 +22,10 @@ import asyncio
import aiohttp import aiohttp
import feedparser import feedparser
from maubot import Plugin, MessageEvent
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from mautrix.types import EventType, MessageType, RoomID, EventID, PowerLevelStateEventContent from mautrix.types import EventType, MessageType, RoomID, EventID, PowerLevelStateEventContent
from maubot import Plugin, MessageEvent
from maubot.handlers import event
from .db import Database, Feed, Entry, Subscription from .db import Database, Feed, Entry, Subscription
@ -65,9 +66,9 @@ class RSSBot(Plugin):
self.cmd_prefix = self.config["command_prefix"] self.cmd_prefix = self.config["command_prefix"]
async def start(self) -> None: async def start(self) -> None:
await super().start()
self.config.load_and_update() self.config.load_and_update()
self.db = Database(self.request_db_engine()) self.db = Database(self.database)
self.client.add_event_handler(self.event_handler, EventType.ROOM_MESSAGE)
self.http = self.client.api.session self.http = self.client.api.session
self.power_level_cache = {} self.power_level_cache = {}
self.poll_task = asyncio.ensure_future(self.poll_feeds(), loop=self.loop) self.poll_task = asyncio.ensure_future(self.poll_feeds(), loop=self.loop)
@ -81,7 +82,7 @@ class RSSBot(Plugin):
self.commands[alias] = handler self.commands[alias] = handler
async def stop(self) -> None: async def stop(self) -> None:
self.client.remove_event_handler(self.event_handler, EventType.ROOM_MESSAGE) await super().stop()
self.poll_task.cancel() self.poll_task.cancel()
async def poll_feeds(self) -> None: async def poll_feeds(self) -> None:
@ -269,6 +270,7 @@ class RSSBot(Plugin):
f"* {self.cmd_prefix} **subscriptions** - List subscriptions in current room\n" f"* {self.cmd_prefix} **subscriptions** - List subscriptions in current room\n"
f"* {self.cmd_prefix} **help** - Print this message") f"* {self.cmd_prefix} **help** - Print this message")
@event.on(EventType.ROOM_MESSAGE)
async def event_handler(self, evt: MessageEvent) -> None: async def event_handler(self, evt: MessageEvent) -> None:
if evt.content.msgtype != MessageType.TEXT or not evt.content.body.startswith( if evt.content.msgtype != MessageType.TEXT or not evt.content.body.startswith(
self.cmd_prefix): self.cmd_prefix):