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
conf_set('request_counter', request_counter + 1)
def die(self):
- self._connection.close()
+ if self._connection:
+ self._connection.close()
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)
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...")
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
)
def echo(self, body, recipient=None):
+ logger.debug("echo: %s", body)
if not recipient:
rooms = self.rooms
else: