From: Thorsten Date: Sat, 24 Jun 2023 19:24:58 +0000 (+0200) Subject: fix meta plugin X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=f7816b59856c9af1ad955e61b8695c4e06c9157a;p=urlbot-v3.git fix meta plugin --- diff --git a/distbot/bot/worker.py b/distbot/bot/worker.py index 4ce5053..86bb9ea 100644 --- a/distbot/bot/worker.py +++ b/distbot/bot/worker.py @@ -57,6 +57,18 @@ class Worker(threading.Thread): self.channel = self.connection.channel() self.channel.exchange_declare(exchange='classifier', exchange_type='topic') + def init_queue(self): + result = self.channel.queue_declare(exclusive=True, queue="") + self.queue = result.method.queue + + for binding_key in self.binding_keys: + logger.info("Registering plugin %s for %s to queue %s", self.get_subclass_name(), binding_key, self.queue) + self.channel.queue_bind( + exchange='classifier', + queue=self.queue, + routing_key=binding_key + ) + def callback(self, ch, method, properties, body): logger.debug("Reacting on %s in %s", str(method.routing_key), self.get_subclass_name()) body = json.loads(body.decode("utf-8")) @@ -103,16 +115,7 @@ class Worker(threading.Thread): except: logger.exception("Oops. Registration failed") self.init_channel() - - result = self.channel.queue_declare(exclusive=True, queue="") - self.queue = result.method.queue - for binding_key in self.binding_keys: - logger.info("Registering plugin %s for %s", self.get_subclass_name(), binding_key) - self.channel.queue_bind( - exchange='classifier', - queue=self.queue, - routing_key=binding_key - ) + self.init_queue() self.channel.basic_consume(queue=self.queue, on_message_callback=self.callback) self.channel.start_consuming() diff --git a/distbot/plugins/plugin_help.py b/distbot/plugins/plugin_help.py index 7974454..9a15e59 100644 --- a/distbot/plugins/plugin_help.py +++ b/distbot/plugins/plugin_help.py @@ -28,17 +28,13 @@ class Plugins(Worker): plugin_storage = {} reverse_lookup = {} - def init_channel(self): - super().init_channel() - self.channel.exchange_declare(exchange='plugin_exc', exchange_type='fanout') - result = self.channel.queue_declare(exclusive=True, queue=self.queue) - plugin_queue = result.method.queue - self.channel.queue_bind(exchange='plugin_exc', queue=plugin_queue) + def init_queue(self): + super().init_queue() self.channel.basic_consume(queue='plugin_registry', on_message_callback=self.callback_plugins) def callback_plugins(self, ch, method, properties, body): body = json.loads(body.decode("utf-8")) - logger.debug("received plugin in registry") + logger.debug("received plugin in registry: %s", body.get("name", "ERROR")) self.plugin_storage[body["name"].lower()] = body ch.basic_ack(delivery_tag=method.delivery_tag)