# Copyright (C) 2007-2012 Thomas Perl <thp.io/about>
# Copyright (C) 2010, 2011 Anaël Verrier <elghinn@free.fr>
-# Copyright (C) 2014, 2015, 2020 kaliko <kaliko@azylum.org>
+# Copyright (C) 2014, 2015, 2020, 2023 kaliko <kaliko@azylum.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
import slixmpp
-from sid import __url__
+from sid import __url__, __doc__
def botcmd(*args, **kwargs):
self.add_event_handler('message', self.message)
self.add_event_handler('got_online', self._view)
+ # Handles disconnection
+ self.add_event_handler('disconnected', self.disconn)
+
# Discover bot internal command (ie. help)
for name, value in inspect.getmembers(self):
if inspect.ismethod(value) and \
self.log.setLevel(log_level)
self.log.debug('set logger, log level : %s', log_level)
+ def disconn(self, event):
+ """disconnected handler"""
+ msg = ": %s" % event if event else "‽"
+ self.log.info('Disconnected from server%s', msg)
+ self.connect()
+
def message(self, msg):
"""Messages handler
body = msg['body'].strip()
if not body.startswith(MUCBot.prefix):
return
- if msg['from'] not in self.__seen:
- self.log.warning('Will not handle message from unseen jid: %s', msg['from'])
- #return
+ self.log.debug(msg['from'])
+ if msg['from'] not in self.__seen and msg['type'] == 'chat':
+ self.log.warning('Will not handle direct message'
+ 'from unseen jid: %s', msg['from'])
+ return
args = body[1:].split()
cmd = args.pop(0)
if cmd not in self.commands:
"""
await self.get_roster()
self.send_presence()
- self.plugin['xep_0045'].join_muc(self.room,
+ await self.plugin['xep_0045'].join_muc_wait(self.room,
self.nick,
+ # Do not fetch history
+ seconds=0,
# If a room password is needed, use:
# password=the_room_password,
- wait=True)
+ )
def register_bot_plugin(self, plugin_cls):
"""Registers plugin, takes a class, the method instanciates the plugin
Automatically assigned to the "help" command."""
help_cmd = ('Type {}help <command name>'.format(self.prefix) +
' to get more info about that specific command.\n\n' +
+ f'DOC: {__doc__}\n' +
f'SRC: {__url__}')
if not args:
if self.__doc__: