From: Thorsten Date: Sun, 9 Jul 2023 10:53:40 +0000 (+0200) Subject: autostart dsa-watcher, broadcast messages X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=e2c3b341ec27c91ea0cd2a456aa3b7cf8f8b2983;p=urlbot-v3.git autostart dsa-watcher, broadcast messages broadcast messages if not targeted at one room specifically - more like a workaround, as I cannot decide a target in feeds.py at the time hint: this creates infinite loops with other bots parsing DSA-** in the same room --- diff --git a/distbot/bot/bot.py b/distbot/bot/bot.py index bfc7401..cda24d9 100644 --- a/distbot/bot/bot.py +++ b/distbot/bot/bot.py @@ -185,12 +185,18 @@ class Bot(slixmpp.ClientXMPP): rooms = [recipient] for r in rooms: - if recipient.split("/")[0] in self.rooms: + if recipient and recipient.split("/")[0] in self.rooms: self.send_message( mto=r, mbody=body, mtype='groupchat' if recipient in self.rooms else 'chat' ) + elif not recipient: + self.send_message( + mto=r, + mbody=body, + mtype='groupchat' + ) def run(): diff --git a/distbot/plugins/feeds.py b/distbot/plugins/feeds.py index d4cc97e..e270e10 100644 --- a/distbot/plugins/feeds.py +++ b/distbot/plugins/feeds.py @@ -7,7 +7,7 @@ import requests from lxml import etree from distbot.bot.worker import Worker -from distbot.common.action import Action +from distbot.common.action import Action, send_action from distbot.common.config import conf_get, conf_set from distbot.common.message import get_words @@ -100,6 +100,11 @@ class DSAWatcher(Worker): return Action(time=crawl_at, command="nick.dsa-watcher.run", mutex="dsa-watcher") + def init_queue(self): + # some semantic misuse here to get the thing started after connecting + super().init_queue() + send_action(self.actionqueue, self.start_crawling()) + def parse_body(self, msg): words = get_words(msg)[1:] cmd = None @@ -113,10 +118,7 @@ class DSAWatcher(Worker): logger.debug("dsa-crawler: active {}, cmd {}, last_crawl at {}".format(active, str(cmd), format(last_dsa_date))) if cmd == "start": - msg = self.crawl() - event = self.get_next_schedule() - conf_set("plugins.dsa-watcher.active", True) - return Action(event=event, msg=msg) + return self.start_crawling() if cmd == "run": msg = self.crawl() event = self.get_next_schedule() @@ -135,5 +137,11 @@ class DSAWatcher(Worker): return Action(msg=msg) + def start_crawling(self): + msg = self.crawl() + event = self.get_next_schedule() + conf_set("plugins.dsa-watcher.active", True) + return Action(event=event, msg=msg) + ALL = [DSAWatcher]