]> git.aero2k.de Git - urlbot-v3.git/commitdiff
autostart dsa-watcher, broadcast messages
authorThorsten <mail@aero2k.de>
Sun, 9 Jul 2023 10:53:40 +0000 (12:53 +0200)
committerThorsten <mail@aero2k.de>
Sun, 9 Jul 2023 10:53:40 +0000 (12:53 +0200)
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

distbot/bot/bot.py
distbot/plugins/feeds.py

index bfc7401396df3c77f51a32b34468786fcd59aaed..cda24d95fe401556aeb2a75664781acab5317bfb 100644 (file)
@@ -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():
index d4cc97e9a714c6dee1f3b45d4b17076fc1c86e02..e270e108b7895ebe9357f1128f1a0be833ccda40 100644 (file)
@@ -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]