def __init__(self, jid, password, room, nick, address=()): log.info('creating bot with {} {} {} {} {}' .format(jid, password, room, nick, address)) self.nick = nick self.room = room self.jid = JID(jid) self._presence_callbacks = [] self._message_callbacks = [] bot = ClientXMPP(jid, password) # disable ipv6 for now since we're getting errors using it bot.use_ipv6 = False # Fix certain Jabber clients not showing messages by giving them an ID bot.use_message_ids = True # Don't try to auto reconnect after disconnections (we'll restart the # process and retry that way) bot.auto_reconnect = False bot.add_event_handler('session_start', self.on_start) bot.add_event_handler('message', self.on_message) bot.add_event_handler('groupchat_presence', self.on_presence) bot.add_event_handler('groupchat_subject', self.on_room_joined) bot.add_event_handler('disconnected', self.on_disconnect) bot.register_plugin('xep_0045') self._muc = bot.plugin['xep_0045'] bot.register_plugin('xep_0199') bot.plugin['xep_0199'].enable_keepalive(5, 10) self.unknown_command_callback = None def on_unknown_callback(message): if self.unknown_command_callback is not None: return self.unknown_command_callback(message) self.message_processor = MessageProcessor(on_unknown_callback) log.info('sb connect') if bot.connect(address=address, reattempt=False): log.info('sb process') bot.process() else: log.error('failed to connect at first attempt') self.on_disconnect(None) self.add_presence_handler(self.rejoin_if_kicked) self._bot = bot
def xmpp_connect(config): bot = ClientXMPP(config.username, config.password) bot.register_plugin('xep_0045') muc = bot.plugin['xep_0045'] bot.register_plugin('xep_0199') ping = bot.plugin['xep_0199'] ping.enable_keepalive(30, 30) bot.use_ipv6 = False bot.add_event_handler( 'session_start', join_rooms_on_connect_handler(bot, muc, config.muc_domain, config.chats, config.nickname)) bot.add_event_handler('message', on_message_handler(config)) if not bot.connect(): raise 'could not connect' return bot
def __init__(self, jid, password, room, nick): print('creating bot with {} {} {} {} '.format(jid, password, room, nick)) self.nick = nick self.room = room self.jid = JID(jid) self._presence_callbacks = [] self._message_callbacks = [] bot = ClientXMPP(jid, password) # disable ipv6 for now since we're getting errors using it bot.use_ipv6 = False bot.add_event_handler('session_start', self.on_start) bot.add_event_handler('message', self.on_message) bot.add_event_handler('groupchat_presence', self.on_presence) bot.add_event_handler('groupchat_subject', self.on_room_joined) bot.register_plugin('xep_0045') self._muc = bot.plugin['xep_0045'] bot.register_plugin('xep_0199') bot.plugin['xep_0199'].enable_keepalive(30, 30) self.unknown_command_callback = None def on_unknown_callback(message): if self.unknown_command_callback is not None: return self.unknown_command_callback(message) self.message_processor = MessageProcessor(on_unknown_callback) log.info('sb connect') if bot.connect(): log.info('sb process') bot.process() else: raise 'could not connect' self.add_presence_handler(self.rejoin_if_kicked) self._bot = bot