Example #1
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)
        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())
Example #2
0
File: relay.py Project: code2u/jsb
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
Example #3
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.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())
Example #4
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)
Example #5
0
 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("&lt;b&gt;", "*")
     txt = txt.replace("&lt;/b&gt;", "*")
     txt = txt.replace("&lt;i&gt;", "")
     txt = txt.replace("&lt;/i&gt;", "")
     return txt
Example #6
0
 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("&lt;b&gt;", "*")
     txt = txt.replace("&lt;/b&gt;", "*")
     txt = txt.replace("&lt;i&gt;", "")
     txt = txt.replace("&lt;/i&gt;", "")
     return txt
Example #7
0
 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("&lt;b&gt;", "")
     what = what.replace("&lt;/b&gt;", "")
     what = what.replace("<i>", "")
     what = what.replace("</i>", "")
     what = what.replace("&lt;i&gt;", "")
     what = what.replace("&lt;/i&gt;", "")
     return what
Example #8
0
 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("&lt;b&gt;", "")
     what = what.replace("&lt;/b&gt;", "")
     what = what.replace("<i>", "")
     what = what.replace("</i>", "")
     what = what.replace("&lt;i&gt;", "")
     what = what.replace("&lt;/i&gt;", "")
     return what
Example #9
0
File: bot.py Project: code2u/jsb
 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
Example #10
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
Example #11
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 = 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
Example #12
0
    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("&lt;b&gt;", "")
        what = what.replace("&lt;/b&gt;", "")
        what = what.replace("<i>", "")
        what = what.replace("</i>", "")
        what = what.replace("&lt;i&gt;", "")
        what = what.replace("&lt;/i&gt;", "")
        return what

    #def doreconnect(self, first=False):
        """ reconnect to the server. """
        """botjid = self.cfg.user
Example #13
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()
    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())
Example #14
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()
    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())
Example #15
0
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