Exemplo n.º 1
0
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)
Exemplo n.º 2
0
 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("&lt;b&gt;", "*")
     txt = txt.replace("&lt;/b&gt;", "*")
     txt = txt.replace("&lt;i&gt;", "")
     txt = txt.replace("&lt;/i&gt;", "")
     return txt
Exemplo n.º 3
0
 def normalize(self, txt):
     txt = stripcolor(txt)
     txt = txt.replace("\n", "<br>");
     txt = txt.replace("<", "&lt;")
     txt = txt.replace(">", "&gt;")
     txt = strippedtxt(txt)
     txt = txt.replace("&lt;br&gt;", "<br>")
     txt = txt.replace("&lt;b&gt;", "<b>")
     txt = txt.replace("&lt;/b&gt;", "</b>")
     txt = txt.replace("&lt;i&gt;", "<i>")
     txt = txt.replace("&lt;/i&gt;", "</i>")   
     txt = txt.replace("&lt;h2&gt;", "<h2>")
     txt = txt.replace("&lt;/h2&gt;", "</h2>")
     txt = txt.replace("&lt;h3&gt;", "<h3>")
     txt = txt.replace("&lt;/h3&gt;", "</h3>")
     txt = txt.replace("&lt;li&gt;", "<li>")
     txt = txt.replace("&lt;/li&gt;", "</li>")
     return txt
Exemplo n.º 4
0
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())
Exemplo n.º 5
0
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