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. """ if not what: return what 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, 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 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) 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 #event.isrelayed = True e = cpy(event) origin = str((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 origin in block.data: 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.outnocb(target, txt, "normal", event=e) else: logging.info("can't find bot for (%s,%s,%s)" % (botname, type, target)) except Exception as ex: handle_exception() except KeyError: pass