From: Thorsten <mail@aero2k.de>
Date: Sat, 24 Jun 2023 19:47:11 +0000 (+0200)
Subject: fix naming
X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5fefa0ff4418ab9e9bb88bc2bad3232358c96e74;p=urlbot-v3.git

fix naming

channel is something entirely different than routing key... technically, at least
---

diff --git a/distbot/bot/worker.py b/distbot/bot/worker.py
index 70160b4..05c79a3 100644
--- a/distbot/bot/worker.py
+++ b/distbot/bot/worker.py
@@ -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"]]
diff --git a/distbot/plugins/basic.py b/distbot/plugins/basic.py
index 139fa9b..5b4bce4 100644
--- a/distbot/plugins/basic.py
+++ b/distbot/plugins/basic.py
@@ -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 []
diff --git a/distbot/plugins/debug.py b/distbot/plugins/debug.py
index c4bb3b3..329f561 100644
--- a/distbot/plugins/debug.py
+++ b/distbot/plugins/debug.py
@@ -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"])
 
 
diff --git a/distbot/plugins/fun.py b/distbot/plugins/fun.py
index baa9a9b..72cd02b 100644
--- a/distbot/plugins/fun.py
+++ b/distbot/plugins/fun.py
@@ -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!")
diff --git a/distbot/plugins/lookup.py b/distbot/plugins/lookup.py
index cc7e583..0baa538 100644
--- a/distbot/plugins/lookup.py
+++ b/distbot/plugins/lookup.py
@@ -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 = []
diff --git a/distbot/plugins/meta.py b/distbot/plugins/meta.py
index f279679..2d55a9f 100644
--- a/distbot/plugins/meta.py
+++ b/distbot/plugins/meta.py
@@ -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
diff --git a/distbot/plugins/morse.py b/distbot/plugins/morse.py
index 394b892..e8ecfd4 100644
--- a/distbot/plugins/morse.py
+++ b/distbot/plugins/morse.py
@@ -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)))
diff --git a/distbot/plugins/muc.py b/distbot/plugins/muc.py
index 4195d3b..f67d171 100644
--- a/distbot/plugins/muc.py
+++ b/distbot/plugins/muc.py
@@ -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":
diff --git a/distbot/plugins/plugin_help.py b/distbot/plugins/plugin_help.py
index 9a15e59..cb9cb29 100644
--- a/distbot/plugins/plugin_help.py
+++ b/distbot/plugins/plugin_help.py
@@ -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:
diff --git a/tests/test_unit/test_plugin.py b/tests/test_unit/test_plugin.py
index 9dc99b4..7ec5c22 100644
--- a/tests/test_unit/test_plugin.py
+++ b/tests/test_unit/test_plugin.py
@@ -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."})