def __init__(self, cfg=None, usersin=None, plugs=None, jid=None, *args, **kwargs): BotBase.__init__(self, cfg, usersin, plugs, jid, *args, **kwargs) self.port = 5222 if not self.host: self.host = self.cfg.host if not self.host: raise Exception("%s - host not set - %s" % (self.name, str(self.cfg))) self.username = self.user.split('@')[0] XMLStream.__init__(self, self.host, self.port, self.name) self.type = 'sxmpp' self.sock = None self.me = self.cfg.user self.jid = self.me self.lastin = None self.test = 0 self.password = "" self.connecttime = 0 self.connection = None self.privwait = XMPPWait() self.errorwait = XMPPErrorWait() self.jabber = True self.jids = {} self.topics = {} self.timejoined = {} self.channels409 = [] if self.state and not self.state.data.ratelimit: self.state.data.ratelimit = 0.05 if self.port == 0: self.port = 5222
def logon(self, user, password, iq): """ logon on the xmpp server. """ try: self.auth(user, password, iq) except CannotAuth: logging.warn("%s - sleeping 20 seconds before register" % self.cfg.name) time.sleep(20) self.failure = "" self.stopped = False try: self.register(user, password) except Exception, ex: self.exit() ; raise time.sleep(5) iq = self.auth_sasl(user, password, iq, False) #self.auth(user, password, iq) XMLStream.logon(self)
def logon(self, user, password): """ logon on the xmpp server. """ iq = self.initstream() if not iq: logging.error("sxmpp - cannot init stream") ; return if not self.auth(user, password, iq.id): logging.warn("%s - sleeping 20 seconds before register" % self.name) time.sleep(20) if self.register(user, password): time.sleep(5) self.auth(user, password) else: time.sleep(10) self.exit() return XMLStream.logon(self)
def __init__(self, cfg=None, usersin=None, plugs=None, jid=None, *args, **kwargs): BotBase.__init__(self, cfg, usersin, plugs, jid, *args, **kwargs) if not self.cfg: raise Exception("sxmpp - config is not set.") if not self.cfg.user: raise NoUserProvided("please make sure the user config variable is set in %s (or use -u)" % cfg.cfile) try: self.cfg.username, self.cfg.host = self.cfg.user.split('@') except (ValueError, TypeError): raise Exception("%s - user not set - %s" % (self.cfg.name, str(self.cfg))) XMLStream.__init__(self, self.cfg.name) self.type = 'sxmpp' self.sock = None self.lastin = None self.test = 0 self.connecttime = 0 self.connection = None self.jabber = True self.jids = {} self.topics = {} self.timejoined = {} self.channels409 = [] if self.state and not self.state.data.ratelimit: self.state.data.ratelimit = 0.02 try: self.cfg.port = int(self.cfg.port) except (ValueError, TypeError): self.cfg.port = 5222 logging.debug("%s - user is %s" % (self.cfg.name, self.cfg.user))
def __init__(self, cfg=None, usersin=None, plugs=None, jid=None, *args, **kwargs): BotBase.__init__(self, cfg, usersin, plugs, jid, *args, **kwargs) if not self.cfg: raise Exception("sxmpp - config is not set.") if not self.cfg.user: raise NoUserProvided( "please make sure the user config variable is set in %s (or use -u)" % cfg.cfile) try: self.cfg.username, self.cfg.host = self.cfg.user.split('@') except (ValueError, TypeError): raise Exception("%s - user not set - %s" % (self.cfg.name, str(self.cfg))) XMLStream.__init__(self, self.cfg.name) self.type = 'sxmpp' self.sock = None self.lastin = None self.test = 0 self.connecttime = 0 self.connection = None self.jabber = True self.jids = {} self.topics = {} self.timejoined = {} self.channels409 = [] if self.state and not self.state.data.ratelimit: self.state.data.ratelimit = 0.02 try: self.cfg.port = int(self.cfg.port) except (ValueError, TypeError): self.cfg.port = 5222 logging.debug("%s - user is %s" % (self.cfg.name, self.cfg.user))
def connect(self, reconnect=False): """ connect the xmpp server. """ if not XMLStream.doconnect(self): return False iq = self.makeready() if not iq: logging.error('%s - connect to %s:%s (%s) failed' % (self.cfg.name, self.cfg.host, self.cfg.port, self.cfg.server)) return self.logon(self.cfg.user, self.cfg.password, iq) self._raw("<presence/>") start_new_thread(self._keepalive, ()) if self.cfg.keepchannelsalive: start_new_thread(self._keepchannelsalive, ()) if self.cfg.doroster: self.requestroster() self.connectok.set() self.sock.settimeout(None) return True
def connect(self, reconnect=True): """ connect the xmpp server. """ try: if not XMLStream.connect(self): logging.error('%s - connect to %s:%s failed' % (self.name, self.host, self.port)) return else: logging.warn('%s - connected' % self.name) self.logon(self.cfg.user, self.cfg.password) start_new_thread(self._keepalive, ()) self.requestroster() self._raw("<presence/>") self.connectok.set() self.sock.settimeout(None) return True except Exception, ex: handle_exception() if reconnect: return self.reconnect()
def connect(self, reconnect=False): """ connect the xmpp server. """ if not XMLStream.doconnect(self): return False self.connection = None iq = self.makeready() if not iq: logging.error( '%s - connect to %s:%s (%s) failed' % (self.cfg.name, self.cfg.host, self.cfg.port, self.cfg.server)) return self.logon(self.cfg.user, self.cfg.password, iq) time.sleep(1) self.sendpresence() #self._raw("<presence/>") #start_new_thread(self._keepalive, ()) #if self.cfg.keepchannelsalive: start_new_thread(self._keepchannelsalive, ()) if self.cfg.doroster: self.requestroster() self.connectok.set() self.sock.settimeout(None) return True
self.stopped = False try: if not self.register(user, password): self.exit() return except Exception, ex: self.exit() raise time.sleep(5) iq = self.auth_sasl(user, password, iq, False) else: logging.error( "stopping .. you can try to use --register to register the bot with the server" ) raise CantLogon(user) XMLStream.logon(self) return True def register(self, jid, password): """ register the jid to the server. """ try: resource = jid.split("/")[1] except IndexError: resource = "jsb" logging.debug('%s - registering %s' % (self.cfg.name, jid)) iq = self.waiter( """<iq type='get'><query xmlns='jabber:iq:register'/></iq>""") if not iq: logging.error("%s - unable to register" % self.cfg.name) return iq = self.waiter(