def forwardoutcb(bot, event): """ forward callback. """ e = cpy(event) logging.debug("forward - cbtype is %s - %s" % (event.cbtype, event.how)) e.forwarded = True e.source = bot.cfg.user e.botname = bot.cfg.server or bot.cfg.name if not event.chan: event.bind(bot) if event.chan: e.allowwatch = event.chan.data.allowwatch fleet = getfleet() for jid in forward.data.channels[event.channel.lower()]: if not "@" in jid: logging.error("forward - %s is not a valid JID" % jid) ; continue logging.info("forward - sending to %s" % jid) if jid == "twitter": try: postmsg(forward.data.outs[jid], e.txt) except Exception, ex: handle_exception() continue outbot = fleet.getfirstjabber(bot.isgae) if not outbot and bot.isgae: outbot = fleet.makebot('xmpp', 'forwardbot') if outbot: e.source = outbot.cfg.user txt = outbot.normalize(e.tojson()) txt = stripcolor(txt) #txt = e.tojson() container = Container(outbot.cfg.user, txt) outbot.outnocb(jid, container.tojson()) else: logging.info("forward - no xmpp bot found in fleet".upper())
def relaycallback(bot, event): """ this is the callbacks that handles the responses to questions. """ # determine where the event came from e = cpy(event) origin = e.channel e.isrelayed = True e.headlines = True try: # loop over relays for origin for botname, type, target in relay.data[origin]: try: logging.debug('trying relay of %s to (%s,%s)' % (origin, type, target)) #if target == origin: continue # tests to prevent looping if botname == bot.cfg.name and origin == target: continue # check whether relay is blocked if block.data.has_key(origin): if [botname, type, target] in block.data[origin]: continue # retrieve the bot from fleet (based on type) fleet = getfleet() outbot = fleet.byname(botname) if not outbot: outbot = fleet.makebot(type, botname) if outbot: logging.info('relay - outbot found - %s - %s' % (outbot.cfg.name, outbot.type)) # we got bot .. use it to send the relayed message if e.nick == bot.cfg.nick: txt = "[!] %s" % e.txt else: txt = "[%s] %s" % (e.nick, e.txt) if event: t = "[%s]" % outbot.cfg.nick logging.debug("relay - sending to %s (%s)" % (target, outbot.cfg.name)) txt = stripcolor(txt) outbot.outnocb(target, txt, "normal", event=e) else: logging.info("can't find bot for (%s,%s,%s)" % (botname, type, target)) except Exception, ex: handle_exception() except KeyError: pass
def forwardoutcb(bot, event): """ forward callback. """ e = cpy(event) logging.debug("forward - cbtype is %s - %s" % (event.cbtype, event.how)) e.forwarded = True e.source = bot.jid e.botname = bot.server or bot.name if not event.chan: event.bind(bot) if event.chan: e.allowwatch = event.chan.data.allowwatch fleet = getfleet() for jid in forward.data.channels[event.channel.lower()]: logging.info("forward - sending to %s" % jid) if jid == "twitter": try: postmsg(forward.data.outs[jid], e.txt) except Exception, ex: handle_exception() continue outbot = fleet.getfirstjabber(bot.isgae) if not outbot and bot.isgae: outbot = fleet.makebot('xmpp', 'forwardbot') if outbot: e.source = outbot.jid txt = outbot.normalize(e.tojson()) txt = stripcolor(txt) #txt = e.tojson() container = Container(outbot.jid, txt) outbot.outnocb(jid, container.tojson()) else: logging.info("forward - no xmpp bot found in fleet".upper())
def writeout(botname, type, channel, txt, eventjson): """ output the watched event to the channel. """ event = EventBase().load(eventjson) global bots watchbot = None if botname in bots: watchbot = bots[botname] if not watchbot: watchbot = getfleet().byname(botname) if not watchbot: watchbot = getfleet().makebot(type, botname) if watchbot: if not botname in bots: bots[botname] = watchbot txt = watchbot.normalize(txt) txt = stripcolor(txt) watchbot.outnocb(channel, txt, event=event)
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 = stripcolor(what) what = what.replace("\002", "") what = what.replace("\003", "") #what = what.replace("\n", "<br>") what = what.replace("<br>", "\n") what = what.replace("<li>", "*") what = what.replace("</li>", "") 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, 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, 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 relaycallback(bot, event): """ this is the callbacks that handles the responses to questions. """ # determine where the event came from #event.isrelayed = True e = cpy(event) origin = unicode((bot.cfg.name, e.channel)) e.isrelayed = True e.headlines = True try: # loop over relays for origin for botname, type, target in relay.data[origin]: try: logging.debug('trying relay of %s to (%s,%s)' % (origin, type, target)) #if target == origin: continue # tests to prevent looping if origin == (botname, target): continue # check whether relay is blocked if block.data.has_key(origin): if [botname, type, target] in block.data[origin]: continue # retrieve the bot from fleet (based on type) fleet = getfleet() outbot = fleet.byname(botname) if not outbot: outbot = fleet.makebot(type, botname) if outbot: logging.info('outbot found - %s - %s' % (outbot.cfg.name, outbot.type)) # we got bot .. use it to send the relayed message if e.nick == bot.cfg.nick: txt = "[!] %s" % e.txt else: txt = "[%s] %s" % (e.nick, e.txt) if event: t = "[%s]" % outbot.cfg.nick logging.debug("sending to %s (%s)" % (target, outbot.cfg.name)) txt = outbot.normalize(txt) txt = stripcolor(txt) outbot.putonqueue(-1, target, txt, "normal", event=e) else: logging.info("can't find bot for (%s,%s,%s)" % (botname, type, target)) except Exception, ex: handle_exception() except KeyError: pass
def normalize(self, what): what = stripcolor(what) what = what.replace("\002", "") what = what.replace("\003", "") what = what.replace("<br>", "\n") what = what.replace("<li>", "*") what = what.replace("</li>", "") 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 doreconnect(self, first=False): """ reconnect to the server. """ """botjid = self.cfg.user
def forwardoutcb(bot, event): """ forward callback. """ e = cpy(event) logging.debug("forward - cbtype is %s - %s" % (event.cbtype, event.how)) e.forwarded = True e.source = bot.cfg.user e.botname = bot.cfg.server or bot.cfg.name if not event.chan: event.bind(bot) if event.chan: e.allowwatch = event.chan.data.allowwatch fleet = getfleet() txt = e.txt for jid in forward.data.channels[event.channel.lower()]: if not "@" in jid and jid != "twitter": logging.error("forward - %s is not a valid JID" % jid) continue logging.info("forward - sending to %s" % jid) if jid == "twitter": if event.cbtype == "JOIN": continue txt = bot.normalize(txt) try: twitter_out(forward.data.outs[jid], txt, event) except KeyError: logging.warn("no forwards found for %s" % jid) except Exception, ex: handle_exception() continue outbot = fleet.getfirstjabber() if outbot: e.source = outbot.cfg.user txt = outbot.normalize(e.tojson()) txt = stripcolor(txt) # txt = e.tojson() container = Container(outbot.cfg.user, txt) outbot.outnocb(jid, container.tojson()) else: logging.info("forward - no xmpp bot found in fleet".upper())
def forwardoutcb(bot, event): """ forward callback. """ e = cpy(event) logging.debug("forward - cbtype is %s - %s" % (event.cbtype, event.how)) e.forwarded = True e.source = bot.cfg.user e.botname = bot.cfg.server or bot.cfg.name if not event.chan: event.bind(bot) if event.chan: e.allowwatch = event.chan.data.allowwatch fleet = getfleet() txt = e.txt for jid in forward.data.channels[event.channel.lower()]: if not "@" in jid and jid != "twitter": logging.error("forward - %s is not a valid JID" % jid) continue logging.info("forward - sending to %s" % jid) if jid == "twitter": if event.cbtype == "JOIN": continue txt = bot.normalize(txt) try: twitter_out(forward.data.outs[jid], txt, event) except KeyError: logging.warn("no forwards found for %s" % jid) except Exception, ex: handle_exception() continue outbot = fleet.getfirstjabber() if outbot: e.source = outbot.cfg.user txt = outbot.normalize(e.tojson()) txt = stripcolor(txt) #txt = e.tojson() container = Container(outbot.cfg.user, txt) outbot.outnocb(jid, container.tojson()) else: logging.info("forward - no xmpp bot found in fleet".upper())
def relaycallback(bot, event): """ this is the callbacks that handles the responses to questions. """ # determine where the event came from origin = event.printto or event.channel try: # loop over relays for origin for botname, type, target in relay.data[origin]: try: logging.debug('trying relay of %s to (%s,%s)' % (origin, type, target)) # tests to prevent looping if botname == bot.botname and origin == target: continue if bot.name in event.relayed: continue # check whether relay is blocked if block.data.has_key(origin): if [botname, type, target] in block.data[origin]: continue # retrieve the bot from fleet (based on type) fleet = getfleet() outbot = fleet.byname(botname) if not outbot: outbot = fleet.makebot(type, botname) if outbot: logging.debug('relay - outbot found - %s - %s' % (outbot.name, outbot.type)) # we got bot .. use it to send the relayed message if event.nick == "bot": txt = event.txt else: txt = "[%s] %s" % (event.nick, event.txt) txt = stripcolor(txt) outbot.outnocb(target, txt, event=event) else: logging.error("can't find %s bot" % type) except Exception, ex: handle_exception() except KeyError: pass