def handle_twittercmnd(bot, ievent): """ arguments: <API cmnd> - do a twitter API cmommand. """ if not go: ievent.reply("the twitter plugin needs the credentials.py file in the .jsb/data//config dir. see .jsb/data/examples") ; return if not ievent.args: ievent.missing('<API cmnd>') ; return target = strippedtxt(ievent.args[0]) try: from jsb.utils.twitter import get_token token = get_token(ievent.user.data.name) if not token: ievent.reply("you are not logged in yet .. run the twitter-auth command.") ; return key, secret = getcreds(getdatadir()) token = tweepy.oauth.OAuthToken(key, secret).from_string(token) twitter = twitterapi(key, secret, token) cmndlist = dir(twitter) cmnds = [] for cmnd in cmndlist: if cmnd.startswith("_") or cmnd == "auth": continue else: cmnds.append(cmnd) if target not in cmnds: ievent.reply("choose one of: %s" % ", ".join(cmnds)) ; return try: method = getattr(twitter, target) except AttributeError: ievent.reply("choose one of: %s" % ", ".join(cmnds)) ; return result = method() res = [] for item in result: try: res.append("%s - %s" % (item.screen_name, item.text)) except AttributeError: try: res.append("%s - %s" % (item.screen_name, item.description)) except AttributeError: try: res.append(unicode(item.__getstate__())) except AttributeError: res.append(dir(i)) ; res.append(unicode(item)) ievent.reply("result of %s: " % target, res) except KeyError: ievent.reply('you are not logged in yet. see the twitter-auth command.') except (tweepy.TweepError, urllib2.HTTPError), e: ievent.reply('twitter failed: %s' % (str(e),))
def normalize(self, what): what = strippedtxt(what) what = what.replace("<b>", self.GREEN) what = what.replace("</b>", self.ENDC) what = what.replace("<b>", self.GREEN) what = what.replace("</b>", self.ENDC) if what.count(self.ENDC) % 2: what = "%s%s" % (self.ENDC, what) return what
def handle_twittercmnd(bot, ievent): """ arguments: <API cmnd> - do a twitter API cmommand. """ if not go: ievent.reply( "the twitter plugin needs the credentials.py file in the .jsb/data//config dir. see .jsb/data/examples" ) return if not ievent.args: ievent.missing('<API cmnd>') return target = strippedtxt(ievent.args[0]) try: from jsb.utils.twitter import get_token token = get_token(ievent.user.data.name) if not token: ievent.reply( "you are not logged in yet .. run the twitter-auth command.") return key, secret = getcreds(getdatadir()) token = tweepy.oauth.OAuthToken(key, secret).from_string(token) twitter = twitterapi(key, secret, token) cmndlist = dir(twitter) cmnds = [] for cmnd in cmndlist: if cmnd.startswith("_") or cmnd == "auth": continue else: cmnds.append(cmnd) if target not in cmnds: ievent.reply("choose one of: %s" % ", ".join(cmnds)) return try: method = getattr(twitter, target) except AttributeError: ievent.reply("choose one of: %s" % ", ".join(cmnds)) return result = method() res = [] for item in result: try: res.append("%s - %s" % (item.screen_name, item.text)) except AttributeError: try: res.append("%s - %s" % (item.screen_name, item.description)) except AttributeError: try: res.append(unicode(item.__getstate__())) except AttributeError: res.append(dir(i)) res.append(unicode(item)) ievent.reply("result of %s: " % target, res) except KeyError: ievent.reply( 'you are not logged in yet. see the twitter-auth command.') except (tweepy.TweepError, urllib2.HTTPError), e: ievent.reply('twitter failed: %s' % (str(e), ))
def normalize(self, what): """ remove markup code as its not yet supported by our GAE XMPP bot. """ what = strippedtxt(unicode(what)) what = what.replace("<b>", "") what = what.replace("</b>", "") what = what.replace("<b>", "") what = what.replace("</b>", "") what = what.replace("<i>", "") what = what.replace("</i>", "") what = what.replace("<i>", "") what = what.replace("</i>", "") return what
def normalize(self, what): """ convert markup to IRC bold. """ txt = strippedtxt(what, ["\002", "\003"]) txt = re.sub("\s+", " ", what) txt = stripcolor(txt) txt = txt.replace("\002", "*") txt = txt.replace("<b>", "") txt = txt.replace("</b>", "") txt = txt.replace("<i>", "") txt = txt.replace("</i>", "") txt = txt.replace("<b>", "*") txt = txt.replace("</b>", "*") txt = txt.replace("<i>", "") txt = txt.replace("</i>", "") return txt
def normalize(self, what): """ convert markup to IRC bold. """ txt = strippedtxt(what, ["\002", "\003"]) txt = re.sub("\s+", " ", what) txt = stripcolor(txt) txt = txt.replace("\002", "*") txt = txt.replace("<b>", "*") txt = txt.replace("</b>", "*") txt = txt.replace("<i>", "") txt = txt.replace("</i>", "") txt = txt.replace("<b>", "*") txt = txt.replace("</b>", "*") txt = txt.replace("<i>", "") txt = txt.replace("</i>", "") return txt
def normalize(self, what): what = strippedtxt(what, allowed="\n") what = what.replace("<b>", self.BLUE) what = what.replace("</b>", self.ENDC) what = what.replace("<i>", self.YELLOW) what = what.replace("</i>", self.ENDC) what = what.replace("<h2>", self.GREEN) what = what.replace("</h2>", self.ENDC) what = what.replace("<h3>", self.GREEN) what = what.replace("</h3>", self.ENDC) what = what.replace("<b>", self.BOLD) what = what.replace("</b>", self.ENDC) what = what.replace("<br>", "\n") what = what.replace("<li>", "* ") what = what.replace("</li>", "\n") if what.count(self.ENDC) % 2: what = "%s%s" % (self.ENDC, what) return what
def normalize(self, txt): #txt = cgi.escape(txt) txt = txt.replace("<br>", "<br>") txt = txt.replace("<b>", "<b>") txt = txt.replace("</b>", "</b>") txt = txt.replace("<i>", "<i>") txt = txt.replace("</i>", "</i>") txt = txt.replace("<h2>", "<h2>") txt = txt.replace("</h2>", "</h2>") txt = txt.replace("<h3>", "<h3>") txt = txt.replace("</h3>", "</h3>") txt = txt.replace("<li>", "<li>") txt = txt.replace("</li>", "</li>") #txt = txt.replace("<", "<") #txt = txt.replace(">", ">") txt = strippedtxt(txt) return txt
def normalize(self, txt): txt = stripcolor(txt) txt = txt.replace("\n", "<br>") txt = txt.replace("<", "<") txt = txt.replace(">", ">") txt = strippedtxt(txt) txt = txt.replace("<br>", "<br>") txt = txt.replace("<b>", "<b>") txt = txt.replace("</b>", "</b>") txt = txt.replace("<i>", "<i>") txt = txt.replace("</i>", "</i>") txt = txt.replace("<h2>", "<h2>") txt = txt.replace("</h2>", "</h2>") txt = txt.replace("<h3>", "<h3>") txt = txt.replace("</h3>", "</h3>") txt = txt.replace("<li>", "<li>") txt = txt.replace("</li>", "</li>") return txt
def normalize(self, what): """ convert markup to IRC bold. """ txt = strippedtxt(what) txt = txt.replace("<b>", "") txt = txt.replace("</b>", "") txt = txt.replace("<i>", "") txt = txt.replace("</i>", "") txt = txt.replace("<b>", "") txt = txt.replace("</b>", "") txt = txt.replace("<i>", "") txt = txt.replace("</i>", "") txt = txt.replace("<h2>", "") txt = txt.replace("</h2>", "") txt = txt.replace("<h3>", "") txt = txt.replace("</h3>", "") txt = txt.replace("<li>", "") txt = txt.replace("</li>", "") return txt
def normalize(self, txt): txt = stripcolor(txt) txt = txt.replace("\n", "<br>"); txt = txt.replace("<", "<") txt = txt.replace(">", ">") txt = strippedtxt(txt) txt = txt.replace("<br>", "<br>") txt = txt.replace("<b>", "<b>") txt = txt.replace("</b>", "</b>") txt = txt.replace("<i>", "<i>") txt = txt.replace("</i>", "</i>") txt = txt.replace("<h2>", "<h2>") txt = txt.replace("</h2>", "</h2>") txt = txt.replace("<h3>", "<h3>") txt = txt.replace("</h3>", "</h3>") txt = txt.replace("<li>", "<li>") txt = txt.replace("</li>", "</li>") return txt
def normalize(self, what): txt = strippedtxt(what, ["\001", "\002", "\003"]) txt = txt.replace("<b>", "\002") txt = txt.replace("</b>", "\002") txt = txt.replace("<i>", "\0032") txt = txt.replace("</i>", "\003") txt = txt.replace("<li>", "\0033*\003 ") txt = txt.replace("</li>", "") txt = txt.replace("<br><br>", " [!] ") txt = txt.replace("<br>", " - ") txt = txt.replace("<b>", "\002") txt = txt.replace("</b>", "\002") txt = txt.replace("<i>", "\003") txt = txt.replace("</i>", "") txt = txt.replace("<h2>", "\0033") txt = txt.replace("</h2>", "\003") txt = txt.replace("<h3>", "\0034") txt = txt.replace("</h3>", "\003") txt = txt.replace("<li>", "\0034") txt = txt.replace("</li>", "\003") return txt
if self.stop: break self.queue.put((input, addr)) logging.info('udp - shutting down main loop') def handle(self, input, addr): """ handle an incoming udp packet. """ if cfg['udpseed']: data = "" for i in range(len(input)/16): try: data += crypt.decrypt(input[i*16:i*16+16]) except Exception, ex: logging.warn("udp - can't decrypt: %s" % str(ex)) data = input break else: data = input if cfg['udpstrip']: data = strippedtxt(data) # check if udp is enabled and source ip is in udpallow list if cfg['udp'] and (addr[0] in cfg['udpallow'] or _inmask(addr[0])): # get printto and passwd data header = re.search('(\S+) (\S+) (.*)', data) if header: # check password if header.group(1) == cfg['udppassword']: printto = header.group(2) # is the nick/channel # check if printto is in allowednicks if not printto in cfg['udpallowednicks']: logging.warn("udp - udp denied %s" % printto ) return logging.debug('udp - ' + str(addr[0]) + " - udp allowed") text = header.group(3) # is the text self.say(printto, text)
""" if cfg['udpseed']: data = "" for i in range(len(input)/16): try: data += crypt.decrypt(input[i*16:i*16+16]) except Exception, ex: logging.warn("udp - can't decrypt: %s" % str(ex)) data = input break else: data = input if cfg['udpstrip']: data = strippedtxt(data) # check if udp is enabled and source ip is in udpallow list if cfg['udp'] and (addr[0] in cfg['udpallow'] or \ _inmask(addr[0])): # get printto and passwd data header = re.search('(\S+) (\S+) (.*)', data) if header: # check password if header.group(1) == cfg['udppassword']: printto = header.group(2) # is the nick/channel # check if printto is in allowednicks if not printto in cfg['udpallowednicks']: logging.warn("udp - udp denied %s" % printto ) return logging.debug('udp - ' + str(addr[0]) + " - udp allowed") text = header.group(3) # is the text
def _readloop(self): """ loop on the socketfile. """ self.stopreadloop = False self.stopped = False doreconnect = True timeout = 1 logging.debug('%s - starting readloop' % self.cfg.name) prevtxt = "" while not self.stopped and not self.stopreadloop and self.sock and self.fsock: try: time.sleep(0.01) if self.cfg.has_key('ssl') and self.cfg['ssl']: intxt = inputmorphs.do(self.sock.read()).split('\n') else: intxt = inputmorphs.do(self.fsock.readline()).split('\n') if self.stopreadloop or self.stopped: doreconnect = 0 break if intxt == ["",]: logging.error("remote disconnected") doreconnect = 1 break if prevtxt: intxt[0] = prevtxt + intxt[0] prevtxt = "" if intxt[-1] != '': prevtxt = intxt[-1] intxt = intxt[:-1] for r in intxt: if not r: continue try: r = strippedtxt(r.rstrip(), ["\001", "\002", "\003"]) rr = unicode(fromenc(r.rstrip(), self.encoding)) except UnicodeDecodeError: if not r: logging.warn("decode error - ignoring (%s)" % self.cfg.name) ; continue rr = r if not rr: continue res = rr try: ievent = IrcEvent().parse(self, res) except Exception, ex: handle_exception() continue try: if int(ievent.cmnd) > 400: logging.error(u"< %s (%s)" % (res, self.cfg.name)) elif int(ievent.cmnd) >= 300: logging.info(u"< %s (%s)" % (res, self.cfg.name)) except ValueError: if not res.startswith("PING") and not res.startswith("NOTICE"): logging.warn(u"< %s (%s)" % (res, self.cfg.name)) else: logging.info(u"< %s (%s)" % (res, self.cfg.name)) if ievent: self.handle_ievent(ievent) timeout = 1 except UnicodeError: handle_exception() continue except socket.timeout, ex: logging.warn("socket timeout (%s)" % self.cfg.name) self.error = str(ex) if self.stopped or self.stopreadloop: break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('no pong received (%s)' % self.cfg.name) break pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except socket.sslerror, ex: self.error = str(ex) 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 logging.warn('no pong received (%s)' % self.cfg.name) break logging.warn("socket timeout (%s)" % self.cfg.name) pingsend = self.ping() if not pingsend: doreconnect = 1 break continue
def _readloop(self): """ loop on the socketfile. """ self.stopreadloop = False self.stopped = False doreconnect = True timeout = 1 logging.debug('%s - starting readloop' % self.cfg.name) prevtxt = "" while not self.stopped and not self.stopreadloop and self.sock and self.fsock: try: time.sleep(0.01) if self.cfg.has_key('ssl') and self.cfg['ssl']: intxt = inputmorphs.do(self.sock.read()).split('\n') else: intxt = inputmorphs.do(self.fsock.readline()).split('\n') if self.stopreadloop or self.stopped: doreconnect = 0 break if intxt == [ "", ]: logging.error("remote disconnected") doreconnect = 1 break if prevtxt: intxt[0] = prevtxt + intxt[0] prevtxt = "" if intxt[-1] != '': prevtxt = intxt[-1] intxt = intxt[:-1] for r in intxt: if not r: continue try: r = strippedtxt(r.rstrip(), ["\001", "\002", "\003"]) rr = unicode(fromenc(r.rstrip(), self.encoding)) except UnicodeDecodeError: if not r: logging.warn("decode error - ignoring (%s)" % self.cfg.name) continue rr = r if not rr: continue res = rr try: ievent = IrcEvent().parse(self, res) except Exception, ex: handle_exception() continue try: if int(ievent.cmnd) > 400: logging.error(u"< %s (%s)" % (res, self.cfg.name)) elif int(ievent.cmnd) >= 300: logging.info(u"< %s (%s)" % (res, self.cfg.name)) except ValueError: if not res.startswith("PING") and not res.startswith( "NOTICE"): logging.warn(u"< %s (%s)" % (res, self.cfg.name)) else: logging.info(u"< %s (%s)" % (res, self.cfg.name)) if ievent: self.handle_ievent(ievent) timeout = 1 except UnicodeError: handle_exception() continue except socket.timeout, ex: logging.warn("socket timeout (%s)" % self.cfg.name) self.error = str(ex) if self.stopped or self.stopreadloop: break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('no pong received (%s)' % self.cfg.name) break pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except socket.sslerror, ex: self.error = str(ex) 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 logging.warn('no pong received (%s)' % self.cfg.name) break logging.warn("socket timeout (%s)" % self.cfg.name) pingsend = self.ping() if not pingsend: doreconnect = 1 break continue
""" if cfg['udpseed']: data = "" for i in range(len(input) / 16): try: data += crypt.decrypt(input[i * 16:i * 16 + 16]) except Exception, ex: logging.warn("udp - can't decrypt: %s" % str(ex)) data = input break else: data = input if cfg['udpstrip']: data = strippedtxt(data) # check if udp is enabled and source ip is in udpallow list if cfg['udp'] and (addr[0] in cfg['udpallow'] or \ _inmask(addr[0])): # get printto and passwd data header = re.search('(\S+) (\S+) (.*)', data) if header: # check password if header.group(1) == cfg['udppassword']: printto = header.group(2) # is the nick/channel # check if printto is in allowednicks if not printto in cfg['udpallowednicks']: logging.warn("udp - udp denied %s" % printto) return logging.debug('udp - ' + str(addr[0]) + " - udp allowed") text = header.group(3) # is the text
def _readloop(self): """ loop on the socketfile. """ self.stopreadloop = False self.stopped = False doreconnect = True timeout = 1 logging.warn('%s - starting readloop' % self.cfg.name) prevtxt = "" while not self.stopped and not self.stopreadloop and self.sock and self.fsock: try: time.sleep(0.01) if self.cfg.has_key('ssl') and self.cfg['ssl']: intxt = inputmorphs.do(self.sock.read()).split('\n') #else: intxt = inputmorphs.do(self.fsock.readline()).split('\n') else: try: [i, o, e] = select.select([self.sock], [], []) except socket.error: doreconnect = False ; break if i: intxt = inputmorphs.do(self.sock.recv(600)).split('\n') if self.stopreadloop or self.stopped: doreconnect = 0 break if not i: time.sleep(0.1) ; continue if not intxt: doreconnect = 1 break if prevtxt: intxt[0] = prevtxt + intxt[0] prevtxt = "" if intxt[-1] != '': prevtxt = intxt[-1] intxt = intxt[:-1] for r in intxt: if not r: continue try: r = strippedtxt(r.rstrip(), ["\001", "\002", "\003"]) rr = unicode(fromenc(r.rstrip(), self.encoding)) except UnicodeDecodeError: logging.warn("%s - decode error - ignoring" % self.cfg.name) continue if not rr: continue res = rr logging.info(u"%s - %s" % (self.cfg.name, res)) try: ievent = IrcEvent().parse(self, res) except Exception, ex: handle_exception() continue if ievent: self.handle_ievent(ievent) timeout = 1 except UnicodeError: handle_exception() continue #except socket.SSLError, ex: logging.error("%s - ssl error: %s" % (self.cfg.name, str(ex))) ; break except socket.timeout, ex: logging.debug("%s - socket timeout" % self.cfg.name) self.error = str(ex) if self.stopped or self.stopreadloop: break timeout += 1 if timeout > 2: doreconnect = 1 logging.warn('%s - no pong received' % self.cfg.name) break pingsend = self.ping() if not pingsend: doreconnect = 1 break continue except socket.sslerror, ex: self.error = str(ex) 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 logging.warn('%s - no pong received' % self.cfg.name) break logging.error("%s - socket timeout" % self.cfg.name) pingsend = self.ping() if not pingsend: doreconnect = 1 break continue
if self.stop: break self.queue.put((input, addr)) logging.info('udp - shutting down main loop') def handle(self, input, addr): """ handle an incoming udp packet. """ if cfg['udpseed']: data = "" for i in range(len(input)/16): try: data += crypt.decrypt(input[i*16:i*16+16]) except Exception, ex: logging.warn("udp - can't decrypt: %s" % str(ex)) data = input break else: data = input if cfg['udpstrip']: data = strippedtxt(data) # check if udp is enabled and source ip is in udpallow list if cfg['udp'] and (addr[0] in cfg['udpallow'] or _inmask(addr[0])): # get printto and passwd data header = re.search('(\S+) (\S+) (.*)', data) if header: # check password if header.group(1) == cfg['udppassword']: printto = header.group(2) # is the nick/channel # check if printto is in allowednicks if cfg['udpalloednicks'] and not printto in cfg['udpallowednicks']: logging.warn("udp - udp denied %s" % printto ) return logging.debug('udp - ' + str(addr[0]) + " - udp allowed") text = header.group(3) # is the text