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 main(): startup_q() jid, password = get_info() server = ("chat.facebook.com", 5222) print("Connecting... (it may takes some minutes)") Loading.start() threading.Thread(target=kwit).start() global fbtts fbtts = ClientXMPP(jid, password) fbtts.add_event_handler("session_start", session_start) fbtts.add_event_handler("message", message) fbtts.auto_reconnect = True fbtts.connect(server) fbtts.process(block=True)