def testasync(self, txt, timeout=0, kw={}): """ run txt with test ievent. don't close queues on exit.""" txt = txt.strip() ievent = Ircevent() ievent.bot = self ievent.cmnd = 'PRIVMSG' ievent.nick = 'test' ievent.userhost = 'test@test' ievent.origtxt = txt ievent.txt = ievent.origtxt ievent.channel = '#test' ievent.allowqueue = False ievent.closequeue = False if kw: for i, j in kw.iteritems(): setattr(ievent, i, j) if timeout: result = plugins.cmnd(self, ievent, timeout) else: result = plugins.cmnd(self, ievent, 10) rlog(100, self.name, str(result)) return result
def fakein(self, txt): """ do a fake ircevent. """ if not txt: return rlog(10, self.name + '.fakein', txt) self.handle_ievent(Ircevent().parse(self, txt))
def handle_ievent(self, ievent): """ check for callbacks, call Irc method. """ try: # call parent method Irc.handle_ievent(self, ievent) # check for callbacks if ievent.cmnd == 'JOIN' or ievent.msg: if ievent.nick.lower() in self.nicks401: self.nicks401.remove(ievent.nick.lower()) i = Ircevent() i.copyin(ievent) i.bot = self i.sock = self.sock callbacks.check(self, i) except: handle_exception()
def _readloop(self): """ loop on the socketfile. """ self.stopreadloop = 0 self.stopped = 0 doreconnect = 0 timeout = 1 rlog(5, self.name, 'starting readloop') prevtxt = "" while not self.stopped and not self.stopreadloop: try: time.sleep(0.01) if self.ssl: intxt = inputmorhps.do(self.sock.read()).split('\n') else: intxt = inputmorphs.do(self.fsock.readline()).split('\n') # if intxt == "" the other side has disconnected if self.stopreadloop or self.stopped: doreconnect = 0 break if not intxt or not intxt[0]: doreconnect = 1 break if prevtxt: intxt[0] = prevtxt + intxt[0] prevtxt = "" if intxt[-1] != '': prevtxt = intxt[-1] intxt = intxt[:-1] for r in intxt: r = r.rstrip() rr = fromenc(r, self.encoding) if not rr: continue res = strippedtxt(rr) res = rr rlog(2, self.name, res) # parse txt read into an ircevent try: ievent = Ircevent().parse(self, res) except Exception, ex: handle_exception() continue # call handle_ievent if ievent: self.handle_ievent(ievent) timeout = 1 except UnicodeError: handle_exception() continue except socket.timeout: # timeout occured .. first time send ping .. reconnect if # second timeout follows if self.stopped: break timeout += 1 if timeout > 2: doreconnect = 1 rlog(10, self.name, 'no pong received') break rlog(1, self.name, "socket timeout") pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except socket.sslerror, ex: # timeout occured .. first time send ping .. reconnect if # second timeout follows if self.stopped or self.stopreadloop: break if not 'timed out' in str(ex): handle_exception() doreconnect = 1 break timeout += 1 if timeout > 2: doreconnect = 1 rlog(10, self.name, 'no pong received') break rlog(1, self.name, "socket timeout") pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except IOError, ex: if 'temporarily' in str(ex): continue
except Exception, ex: # other exception occured .. close connection handle_exception() rlog(10, self.name, 'closing dcc with ' + nick) partyline.del_party(nick) return try: # see if user provided channel res = strippedtxt(res.strip()) chan = checkchan(self, res) if chan != None: (channel, res) = chan else: channel = nick # create ircevent ievent = Ircevent() ievent.nick = nick ievent.userhost = userhost ievent.channel = channel ievent.origtxt = res ievent.txt = res ievent.cmnd = 'DCC' ievent.bot = self ievent.sock = sock ievent.speed = 1 ievent.isdcc = True # check if its a command if so dispatch if ievent.txt[0] == "!": ievent.txt = ievent.txt[1:] plugins.trydispatch(self, ievent) continue