mirror of
https://github.com/maubot/rss.git
synced 2024-10-01 08:25:36 -04:00
Update to use new event handling system
TODO: Switch to new command handling system
This commit is contained in:
parent
5e9e1595a3
commit
4cb519a210
@ -9,3 +9,4 @@ extra_files:
|
|||||||
soft_dependencies:
|
soft_dependencies:
|
||||||
- python-magic>=0.4
|
- python-magic>=0.4
|
||||||
- pillow>=5
|
- pillow>=5
|
||||||
|
database: true
|
||||||
|
10
rss/bot.py
10
rss/bot.py
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user