]> git.aero2k.de Git - urlbot-v3.git/commitdiff
fix naming
authorThorsten <mail@aero2k.de>
Sat, 24 Jun 2023 19:47:11 +0000 (21:47 +0200)
committerThorsten <mail@aero2k.de>
Sat, 24 Jun 2023 19:47:11 +0000 (21:47 +0200)
channel is something entirely different than routing key... technically, at least

distbot/bot/worker.py
distbot/plugins/basic.py
distbot/plugins/debug.py
distbot/plugins/fun.py
distbot/plugins/lookup.py
distbot/plugins/meta.py
distbot/plugins/morse.py
distbot/plugins/muc.py
distbot/plugins/plugin_help.py
tests/test_unit/test_plugin.py

index 70160b4acc00e5f95e4e53b702ea7ea3c2565a36..05c79a3409ceb755cb8442096a5a1b37456e1502 100644 (file)
@@ -48,7 +48,7 @@ class Worker(threading.Thread):
                 self.usage = "{}: {}".format(conf_get("bot_nickname"), "|".join(set(cmds)))
             else:
                 self.usage = "(reaction only)"
-        self.used_channel = None
+        self.used_routing_key = None
         self.connection: Optional[pika.BlockingConnection] = None
         self.channel = None
 
@@ -74,11 +74,11 @@ class Worker(threading.Thread):
         logger.debug("Reacting on %s in %s", str(method.routing_key), self.get_subclass_name())
         body = json.loads(body.decode("utf-8"))
         try:
-            self.used_channel = method.routing_key.split(".")
+            self.used_routing_key = method.routing_key.split(".")
         except TypeError as e:
             logging.error("%s is of type %s", str(method.routing_key), type(method.routing_key))
             logging.exception(e)
-            self.used_channel = ["__error__"]
+            self.used_routing_key = ["__error__"]
 
         if self.uses_history:
             self.history = self.total_history[body["to"]]
index 139fa9bc6ab53d10ea612ee19f62c9201b6cde70..5b4bce49dce2a3a203689f3238dcf337100e0290 100644 (file)
@@ -243,7 +243,7 @@ class Choose(Worker):
     def parse_body(self, msg):
         words = get_words(msg)
         sender = get_nick_from_message(msg)
-        sudo = 'sudo' in self.used_channel
+        sudo = 'sudo' in self.used_routing_key
         if sudo:
             words.pop(0)  # remove sudo from args
             sudoers = conf_get('sudoers') or []
index c4bb3b3bc669ab954faa27326345221c5e607b34..329f561eefa064e02845b21ae91adfe4e6aef344 100644 (file)
@@ -26,7 +26,7 @@ class Parrot(Worker):
     uses_history = True
 
     def parse_body(self, msg):
-        if self.history and 'repeat' in self.used_channel:
+        if self.history and 'repeat' in self.used_routing_key:
             return Action(msg=self.history[-1]["body"])
 
 
index baa9a9b022997b5407ec141714fc89256f5083c2..72cd02b94e544b667e452f3e466f93a766946542 100644 (file)
@@ -189,7 +189,7 @@ class Doctor(Worker):
     description = "machines don't like the doctor."
 
     def parse_body(self, msg):
-        if "doctor" in self.used_channel:
+        if "doctor" in self.used_routing_key:
             return Action(msg="EXTERMINATE! EXTERMINATE!")
         else:
             return Action(msg="ELIMINIEREN! ELIMINIEREN!")
index cc7e5838548c85282c17cab355a733ba33292817..0baa538e36eeba7f4c5d6ccc65e4fc5fd78b3533 100644 (file)
@@ -65,7 +65,7 @@ class UnicodeDecode(Worker):
     def parse_body(self, msg):
         sender = get_nick_from_message(msg)
         words = get_words(msg)[1:]
-        if not words or "decode" not in self.used_channel:
+        if not words or "decode" not in self.used_routing_key:
             return
         logger.debug('decode called for %s' % words[0])
         out = []
index f2796795e52b3eebf25a39db75f3693c1b071037..2d55a9fef9ebbd3f8e07ea98d91bd3e13c8c8b5b 100644 (file)
@@ -44,7 +44,7 @@ class Info(Worker):
 
     def parse_body(self, msg):
         # TODO not totally true regarding task and rate limiting
-        if "info" in self.used_channel:
+        if "info" in self.used_routing_key:
             return Action(msg=f""": I'm a bot named {conf_get('bot_nickname')}, my job is to extract <title> tags from posted URLs. In case I'm annoying or for further
                 questions, please talk to my master {conf_get('bot_owner')}. I'm rate limited.
                 To make me exit immediately, highlight me with 'hangup' in the message
index 394b8929a23da826baefb80682d81585db12dc0b..e8ecfd4f99ba2fa675245c89781275225788ad8d 100644 (file)
@@ -155,14 +155,14 @@ class Morse(Worker):
         words = get_words(msg)
         sender = get_nick_from_message(msg)
 
-        if not ("morse-decode" in self.used_channel or "morse-encode" in self.used_channel):
+        if not ("morse-decode" in self.used_routing_key or "morse-encode" in self.used_routing_key):
             return
 
-        if self.used_channel[2] == "that" and self.history:
+        if self.used_routing_key[2] == "that" and self.history:
             message = self.history[-1]["body"]
         else:
             message = " ".join(words[1:])
-        if self.used_channel[1] == "morse-decode":
+        if self.used_routing_key[1] == "morse-decode":
             return Action(msg="{}: {}".format(sender, morse_decode(message)))
         else:
             return Action(msg="{}: {}".format(sender, morse_encode(message)))
index 4195d3b609bcae83118e1a474ea4a56e13a4b83f..f67d171052e92fce7f0ff16a649d6a83446ef0fb 100644 (file)
@@ -43,7 +43,7 @@ class Recorder(Worker):
 
     def parse_body(self, msg):
         words = get_words(msg)
-        cmd = self.used_channel
+        cmd = self.used_routing_key
         sender = get_nick_from_message(msg)
 
         if cmd[0] == "userjoin":
index 9a15e59806c5f6a64b6cc215641d0df76fe854bf..cb9cb2979930e6b1556cef2d6f5c503e544c9018 100644 (file)
@@ -65,7 +65,7 @@ class Plugins(Worker):
         return Action(msg=msg)
 
     def parse_body(self, msg):
-        bind = self.used_channel
+        bind = self.used_routing_key
         if bind[1] == "help":
             plugin_name = None
             if len(bind) > 2:
index 9dc99b4f2740bf5b7c8bf8f54b3cd0ca96755c6a..7ec5c220120afc4d225a8f93eb113537ea27a1ed 100644 (file)
@@ -31,8 +31,8 @@ def test_doctor_multilingo():
     from distbot.plugins.fun import Doctor
 
     doc = Doctor("_")
-    doc.used_channel = ["call", "the", "doctor"]
+    doc.used_routing_key = ["call", "the", "doctor"]
     assert Action(msg="EXTERMINATE! EXTERMINATE!") == doc.parse_body({"msg": "call the doctor!"})
 
-    doc.used_channel = ["der", "doktor", "hat", "gleich", "zeit"]
+    doc.used_routing_key = ["der", "doktor", "hat", "gleich", "zeit"]
     assert Action(msg="ELIMINIEREN! ELIMINIEREN!") == doc.parse_body({"msg": "der Doktor hat gleich zeit."})