mirror of
https://github.com/maubot/rss.git
synced 2025-11-29 14:56:30 -05:00
Update to use new event handling system
TODO: Switch to new command handling system
This commit is contained in:
parent
5e9e1595a3
commit
4cb519a210
2 changed files with 7 additions and 4 deletions
10
rss/bot.py
10
rss/bot.py
|
|
@ -22,9 +22,10 @@ import asyncio
|
|||
import aiohttp
|
||||
import feedparser
|
||||
|
||||
from maubot import Plugin, MessageEvent
|
||||
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
|
||||
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
|
||||
|
||||
|
|
@ -65,9 +66,9 @@ class RSSBot(Plugin):
|
|||
self.cmd_prefix = self.config["command_prefix"]
|
||||
|
||||
async def start(self) -> None:
|
||||
await super().start()
|
||||
self.config.load_and_update()
|
||||
self.db = Database(self.request_db_engine())
|
||||
self.client.add_event_handler(self.event_handler, EventType.ROOM_MESSAGE)
|
||||
self.db = Database(self.database)
|
||||
self.http = self.client.api.session
|
||||
self.power_level_cache = {}
|
||||
self.poll_task = asyncio.ensure_future(self.poll_feeds(), loop=self.loop)
|
||||
|
|
@ -81,7 +82,7 @@ class RSSBot(Plugin):
|
|||
self.commands[alias] = handler
|
||||
|
||||
async def stop(self) -> None:
|
||||
self.client.remove_event_handler(self.event_handler, EventType.ROOM_MESSAGE)
|
||||
await super().stop()
|
||||
self.poll_task.cancel()
|
||||
|
||||
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} **help** - Print this message")
|
||||
|
||||
@event.on(EventType.ROOM_MESSAGE)
|
||||
async def event_handler(self, evt: MessageEvent) -> None:
|
||||
if evt.content.msgtype != MessageType.TEXT or not evt.content.body.startswith(
|
||||
self.cmd_prefix):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue