]> git.aero2k.de Git - urlbot-v3.git/commitdiff
some more debug logs, add group invite
authorThorsten <mail@aero2k.de>
Thu, 29 Jul 2021 16:57:08 +0000 (18:57 +0200)
committerThorsten <mail@aero2k.de>
Thu, 29 Jul 2021 16:57:08 +0000 (18:57 +0200)
distbot/bot/action_worker.py
distbot/bot/bot.py

index 207ae0b0ba527ea21d1c4570a86d362caf431d85..a57d47c34ee6fdba55e6ea0cf1ed31773d7139a5 100644 (file)
@@ -35,16 +35,21 @@ class ActionWorker(object):
         self.idle_task = self.loop.create_task(self.tick())
 
     def open_connection(self, connection):
+        logger.debug("opened connection for actionworker")
         self._connection = connection
         connection.channel(on_open_callback=self.open_channel)
 
     def open_channel(self, channel: Channel):
+        logger.debug("opened channel")
         # self.add_on_channel_close_callback()
         # self.setup_exchange(self.EXCHANGE)
         self._channel = channel
         channel.add_on_close_callback(lambda *_: self._bot.disconnect())
         channel.queue_declare(queue=self._queue_name, durable=True, callback=lambda _: self.start_consuming())
-        channel.add_on_cancel_callback(lambda _: channel.close())
+        def cancel(_):
+            logger.debug("cancel channel")
+            channel.close()
+        channel.add_on_cancel_callback(lambda _: cancel)
 
     def start_consuming(self):
         """This method sets up the consumer by first calling
@@ -164,4 +169,5 @@ class ActionWorker(object):
         conf_set('request_counter', request_counter + 1)
 
     def die(self):
-        self._connection.close()
+        if self._connection:
+            self._connection.close()
index e551dee7816a0c20f52a1761f3c78597357d5127..c5170aedbf4b97782ffdde8568d06a8ca87633c9 100644 (file)
@@ -32,6 +32,7 @@ class Bot(slixmpp.ClientXMPP):
         self.add_event_handler('session_start', self.session_start)
         self.add_event_handler('groupchat_message', self.muc_message)
         self.add_event_handler('message', self.message_handler)
+        self.add_event_handler("groupchat_invite", self.group_invite)
         for room in self.rooms:
             self.add_event_handler('muc::%s::got_online' % room, self.muc_online)
 
@@ -50,8 +51,11 @@ class Bot(slixmpp.ClientXMPP):
     def initialize_actionworker(self):
         connection = AsyncioConnection(
             pika.URLParameters(conf_get("amqp_uri")),
-            on_open_callback=self.action_worker.open_connection
+            on_open_callback=self.action_worker.open_connection,
+            on_open_error_callback=lambda con, err: logger.error("Could not connect: %s", err),
+            on_close_callback=lambda con, e, x: logger.info("closing connection of actionworker (%s)", e)
         )
+        logger.debug("connection state: %s", connection.connection_state)
 
     def disconnect(self, reconnect=False, wait=None, send_close=True):
         logger.info("Stopping all workers...")
@@ -59,22 +63,27 @@ class Bot(slixmpp.ClientXMPP):
         logger.info("Stopping self...")
         super(Bot, self).disconnect(reconnect)
         logger.info("Gudbai...")
+        # TODO: cleaner shutdown?
         raise SystemExit()
 
     def session_start(self, _):
         self.get_roster()
         self.send_presence(ppriority=0, pstatus=None, pshow=None)
+        self.initialize_actionworker()
         for room in self.rooms:
             logger.info('%s: joining' % room)
-            ret = self.plugin['xep_0045'].join_muc(room, self.nick, wait=True)
+            ret = self.plugin['xep_0045'].join_muc(room, self.nick)
             logger.info('%s: joined with code %s' % (room, ret))
-        self.initialize_actionworker()
 
     def muc_message(self, msg):
         if msg['mucnick'] == self.nick or 'groupchat' != msg['type']:
             return False
         return self.message(msg)
 
+    def group_invite(self, msg):
+        self.plugin["xep_0045"].join_muc(msg["from"], self.nick)
+        logger.info("Joining %s (by invitation)" % (msg["from"]))
+
     def message_handler(self, msg):
         # disabled, as currently history leaks from groupchat chats
         return False
@@ -164,6 +173,7 @@ class Bot(slixmpp.ClientXMPP):
             )
 
     def echo(self, body, recipient=None):
+        logger.debug("echo: %s", body)
         if not recipient:
             rooms = self.rooms
         else: