示例#1
0
文件: admin.py 项目: buzzworkers/tl
def handle_adminsave(bot, ievent):
    """ no arguments - boot the bot .. do some initialisation. """
    ievent.reply("saving mainconfig")
    getmainconfig().save()
    ievent.reply("saving fleet bots")
    getfleet().save()
    ievent.reply("saving all plugins")
    plugs.save()
    ievent.done()
示例#2
0
文件: irc.py 项目: buzzworkers/tl
def handle_broadcast(bot, ievent):
    """ arguments: <txt> - broadcast txt to all joined channels. """
    if not ievent.rest:
         ievent.missing('<txt>')
         return
    ievent.reply('broadcasting')
    getfleet().broadcast(ievent.rest)
    partyline.say_broadcast(ievent.rest)
    ievent.reply('done')
示例#3
0
文件: alarm.py 项目: buzzworkers/tl
 def alarmsay(self, item):
     """ say alarm txt """
     logging.warn("trying to deliver on %s" % str(item))
     bot = getfleet().byname(item.botname)
     if not bot: bot = getfleet().get(None, item.botname)
     if bot:
         if bot.type == "irc": bot.connectok.wait()
         if item.printto: bot.say(item.printto, "[%s] %s" % (item.nick, item.txt), speed=1)
         else: bot.say(item.nick, item.txt, speed=1)
     else: logging.warn("can't find %s bot in fleet" % item.botname)
     self.delete(item.idnr)
示例#4
0
文件: watcher.py 项目: buzzworkers/tl
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)
示例#5
0
文件: core.py 项目: buzzworkers/tl
def handle_reboot(bot, ievent):
    """ no arguments - reboot the bot. """
    ievent.reply("rebooting")
    #time.sleep(3)
    if ievent.rest == "cold": stateful = False
    else: stateful = True
    if stateful:
        if bot.type == "tornado": 
            callback = functools.partial(reboot_stateful, bot, ievent, getfleet(), partyline)
            bot.server.io_loop.add_callback(callback)
        else: mainhandler.put(0, reboot_stateful, bot, ievent, getfleet(), partyline)
    else:
        getfleet().exit()
        mainhandler.put(0, reboot)
示例#6
0
文件: fleet.py 项目: buzzworkers/tl
def fleet_cmnd(bot, ievent):
    """ arguments: <botname> <cmndstring> - do cmnd on fleet bot(s). """
    try: (name, channel, cmndtxt) = ievent.rest.split(" ", 2)
    except ValueError: ievent.missing("<botname> <channel> <cmndstring>") ; return
    fleet = getfleet()
    if name.startswith("@"): name = name[1:] ; power = True
    else: power = False
    if not cmndtxt.startswith(";"): cmndtxt = ";" + cmndtxt
    if name == "all":
        for b in fleet.bots:
            e = b.make_event(ievent.userhost, channel, cmndtxt)
            if not e: ievent.reply("can't make event on %s bot (%s)" % (b.cfg.name, b.type)) ; continue
            if not power:  e.nooutput = True
            e.nodispatch = False
            ee = e.execute(direct=True)
            if ee: res = ee.wait()
            else: res = ["no result", ] 
            ievent.reply("%s ==> " % b.cfg.name, res, dot=" -=- ")
    else:
        b = fleet.byname(name)
        if not b: ievent.reply("can't find %s bot in fleet" % name) ; return
        e = b.make_event(ievent.userhost, channel, cmndtxt)
        e.nodispatch = False
        if not e: ievent.reply("can't make event on %s bot (%s)" % (b.cfg.name, b.type)) ; return
        if not power: e.nooutput = True
        ee = e.execute(direct=True)
        ievent.reply("%s ==> " % b.cfg.name, ee.wait(500), dot=" -=- ")
    ievent.done()
示例#7
0
文件: reboot.py 项目: buzzworkers/tl
def reboot_stateful(bot, ievent, fleet, partyline):
    """ reboot the bot, but keep the connections (IRC only). """
    logging.warn("reboot - doing statefull reboot")
    session = {'bots': {}, 'name': bot.cfg.name, 'channel': ievent.channel, 'partyline': []}
    fleet = getfleet()
    for i in fleet.bots:
        logging.warn("reboot - updating %s" % i.cfg.name)
        data = i._resumedata()
        if not data: continue
        session['bots'].update(data)
        if i.type == "sxmpp": i.exit() ; continue
        if i.type == "convore": i.exit() ; continue
        if i.type == "tornado":
            i.exit()
            time.sleep(0.1)
            for socketlist in list(i.websockets.values()):
                for sock in socketlist: sock.stream.close()
    session['partyline'] = partyline._resumedata()
    sfile, sessionfile = tempfile.mkstemp('-session', 'tl-', text=True)
    logging.warn("writing session file %s" % sessionfile)
    json.dump(session, open(sessionfile, "w"))
    args = []
    skip = False
    for a in sys.argv[1:]:
        if skip: skip = False ; continue
        if a == "-r": skip = True ; continue
        args.append(a)
    os.execl(sys.argv[0], sys.argv[0], '-r', sessionfile, *args)
示例#8
0
文件: udp.py 项目: buzzworkers/tl
 def _listen(self):
     """ listen for udp messages .. /msg via bot"""
     if not cfg['udp']: return
     fleet = getfleet()
     for botname in cfg['udpbots']:
         if not fleet.byname(botname): logging.info("udp - can't find %s bot" % botname)
     try:
         fleet.startok.wait(5)
         logging.warn('udp listening on %s %s' % (cfg['udphost'], cfg['udpport']))
         self.sock.bind((cfg['udphost'], cfg['udpport']))
         self.stop = 0
     except IOError:
         handle_exception()
         self.sock = None
         self.stop = 1
         return
     # loop on listening udp socket
     while not self.stop:
         try: input, addr = self.sock.recvfrom(64000)
         except socket.timeout: continue
         except Exception as ex:
             try: (errno, errstr) = ex
             except ValueError: errno = 0 ; errstr = str(ex)
             if errno == 4: logging.warn("udp - %s - %s" % (self.name, str(ex))) ; break
             if errno == 35: continue
             else: handle_exception() ; break
         if self.stop: break
         self.queue.put((input, addr))
     logging.info('udp - shutting down main loop')
示例#9
0
文件: plus.py 项目: buzzworkers/tl
def plusscan(skip=False):
    global teller
    teller += 1
    if teller % 5 != 0: return 
    logging.warn("running plus scan")
    fleet = getfleet()
    for id, channels in state.data.ids.items():
        if not id in state.data.seen: state.data.seen[id] = []
        for botname, chan in channels:
            try:
                res = getplus(id)
                if not res: logging.warn("no result from %s" % id) ; continue
                bot = fleet.byname(botname)
                if bot:
                    todo = []
                    for r in res:
                        stamp = uuid.uuid3(uuid.NAMESPACE_URL, str(r)).hex
                        if stamp not in state.data.seen[id]:
                            state.data.seen[id].append(stamp)
                            todo.append(r)
                    if todo: bot.say(chan, "new plus update: " , todo)
                else: logging.warn("no %s bot in fleet" % botname)
            except AttributeError as ex: logging.error(str(ex))
            except Exception as ex: handle_exception()
    state.save()
示例#10
0
文件: ask.py 项目: buzzworkers/tl
def handle_ask(bot, event):
    """ 
        arguments: <subject> <question> - this command lets you ask a question that gets dispatched to jabber 
        users that have registered themselves for that particular subject. 

    """
    try:
        subject, question = event.rest.split(" ", 1)
    except ValueError:
        event.missing("<subject> <question>")
        return
    try:
        expertslist = experts.data[subject]
    except KeyError:
        if "@" in subject:
            expertslist = [subject]
        else:
            expertslist = [defaultJID]
    fleet = getfleet()
    xmppbot = fleet.getfirstjabber()
    if xmppbot:
        for expert in expertslist:
            xmppbot.say(expert, "%s (%s) asks you: %s" % (event.userhost, bot.cfg.name, question))
    else:
        event.reply("can't find jabber bot in fleet")
        return
    asker = event.userhost
    for expert in expertslist:
        if expert not in questions.data:
            questions.data[expert] = []
        questions.data[expert].append([bot.cfg.name, bot.type, event.userhost, event.channel])
    questions.save()
    event.reply("question is sent to %s" % " .. ".join(expertslist))
示例#11
0
文件: ask.py 项目: buzzworkers/tl
def askcallback(bot, event):
    """ this is the callbacks that handles the responses to questions. """
    sendto = questions.data[event.userhost]
    jid = []
    channels = []
    try:
        (printto, txt) = event.txt.split(":", 1)
    except ValueError:
        printto = False
        txt = event.txt
    txt = txt.strip()
    done = []
    fleet = getfleet()
    for botname, type, userhost, channel in sendto:
        if not printto or userhost != printto:
            continue
        askbot = fleet.makebot(type)
        if not askbot:
            askbot = fleet.makebot("xmpp", "askxmppbot")
        logging.debug("ask - %s %s %s %s" % (botname, type, userhost, channel))
        if askbot:
            for jid in channel:
                askbot.say(channel, "%s says: %s" % (event.userhost, txt))
        else:
            logging.warn("ask - can't find %s bot in fleet" % type)
            continue
        try:
            questions.data[event.userhost].remove([botname, type, userhost, channel])
            questions.save()
        except ValueError:
            pass
        done.append(channel)
        break
    if done:
        event.reply("answer sent to ", done)
示例#12
0
def scan(skip=False):
    global teller, dostop
    if dostop: return
    teller += 1
    try: do = int(cfg.sleep)
    except ValueError: do = 5
    if do < 1: do = 5
    if teller % do != 0: return 
    logging.info("running")
    fleet = getfleet()
    todo = sync()
    if not todo: logging.info("nothing todo") ; return
    for b in todo:
        uid = str(b.user_id)
        if not uid in state.data.ids: logging.warn("we don't follow id %s" % uid) ; continue
        for channel in state.data.ids[uid]:
            if dostop: return
            botname, chan = channel
            bot = fleet.byname(botname)
            if bot:
                if b.post_id: url = ("http://stackoverflow.com/questions/%s" % b.post_id) or "no url found"
                bot.say(chan, "*%s* %s - *%s* - %s - %s - %s (%s)" % (state.data.names[uid].upper(), b.action, b.description, url, time.ctime(b.creation_date), b.detail or "no detail", b.post_type))
                if b.action == "answered":
                    aa = getanswers(b.post_id)
                    if aa:
                        a = aa[-1]
                        try: body = a['body']
                        except KeyError: continue
                        (urls, c) = geturls(body)
                        if c: bot.say(chan, "> " + c)
                        else: bot.say(chan, "can't find answers")
                        if urls: bot.say(chan, "urls: %s" % " -=- ".join(urls))
            else: logging.warn("no %s bot in fleet" % botname)
示例#13
0
文件: fleet.py 项目: buzzworkers/tl
def fleet_add(bot, ievent):
    """ arguments: <name> <type> <server>|<botjid> <nick>|<jabberpasswd> [<ircpass>] - add a newly created bot to the fleet. """
    try: 
        name, type, server, nick, password = ievent.rest.split()
    except ValueError:
        try:
            name, type, server, nick = ievent.rest.split()
            password = ""
        except ValueError:
            ievent.missing("<name> <type> <server>|<botjid> <nick>|<jabberpass> [<ircpasswd>]") ; return
    type = type.lower()
    fleet = getfleet() 
    bot = fleet.byname(name)
    if bot: ievent.reply("%s bot already exists" % name) ; return
    cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config')
    cfg.disable = 0
    if type == "irc":
        cfg.port = 6667
        cfg.server = server
        cfg.nick = nick
        cfg.password = password
    elif type in ["xmpp", "sxmpp"]:
        cfg.port = 4442
        cfg.host = server
        try: n, serv = cfg.host.split("@")
        except (ValueError, TypeError): pass
        cfg.server = serv
        cfg.password = nick
    cfg.save()
    bot = fleet.makebot(type, name, cfg)
    fleet.addbot(bot)
    if bot:
        ievent.reply('enabled and started %s bot - %s' % (name, cfg.filename))
        start_new_thread(bot.start, ())
    else: ievent.reply("can't make %s bot" % cfg.name)
示例#14
0
文件: fleet.py 项目: buzzworkers/tl
def fleet_enable(bot, ievent):
    """ arguments: <list of botnames> - enable a fleet bot. """
    if not ievent.rest:
        ievent.missing("<list of botnames>")
        return
    bots = ievent.rest.split()
    fleet = getfleet()
    for name in bots:
        bot = fleet.byname(name)
        if bot:
            #bot.cfg.load()
            bot.cfg['disable'] = 0
            if not bot.cfg.name: bot.cfg.name = name
            bot.cfg.save()
            ievent.reply('enabled %s' % name)
            #start_new_thread(bot.connect, ())
        elif name in fleet.avail():
            cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config')
            cfg['disable'] = 0
            if not cfg.name: cfg.name = name
            cfg.save()
            bot = fleet.makebot(cfg.type, cfg.name, cfg)
            if not bot: ievent.reply("can't make %s bot - %s" % (cfg.name, cfg.type)) ; return
            ievent.reply('enabled %s bot' % name)
            #start_new_thread(bot.start, ())
        else: ievent.reply('no %s bot in fleet' % name)
示例#15
0
文件: datadir.py 项目: buzzworkers/tl
def makeconfigs():
    from tl.lib.config import makedefaultconfig
    fleet = getfleet()
    makedefaultconfig('irc', ddir)
    fleet.addnametype("default-irc", "irc")
    makedefaultconfig('sleek', ddir)
    fleet.addnametype("default-sleek", "sleek")
示例#16
0
文件: fleet.py 项目: buzzworkers/tl
def handle_fleetconnect(bot, ievent):
    """ arguments: <botname> - connect a fleet bot to it's server. """
    try: botname = ievent.args[0]
    except IndexError:
        ievent.missing('<botname>')
        return
    try:
        fleet = getfleet()
        fleetbot = fleet.byname(botname)
        if fleetbot:
            start_new_thread(fleetbot.connect, ())
            ievent.reply('%s connect thread started' % botname)
        else:
            ievent.reply("can't connect %s .. trying enable" % botname)
            cfg = Config('fleet' + os.sep + stripname(botname) + os.sep + 'config')
            cfg['disable'] = 0
            if not cfg.name: cfg.name = botname
            cfg.save()
            bot = fleet.makebot(cfg.type, cfg.name, cfg)
            if bot:
                ievent.reply('enabled and started %s bot' % botname)
                start_new_thread(bot.start, ())
            else: ievent.reply("can't make %s bot" % cfg.name)
    except Exception as ex:
        ievent.reply(str(ex))
示例#17
0
文件: hubbub.py 项目: buzzworkers/tl
 def work(self, botname, type, channel, entries, url, *args, **kwargs):
     logging.debug("in work .. %s" % str(entries))
     try:
         item = self.byurl(url)
         name = item.data.name
         try:
             fleet = getfleet()
             bot = fleet.byname(botname)
             if not bot: logging.warn("can't find %s bot in fleet" % botname) ; return
         except NoSuchBotType as ex: logging.warn("%s" % str(ex)) ; return
         if not bot: logging.error("can't find %s bot in fleet" % type) ; return
         res2 = entries
         if not res2: logging.info("no updates for %s (%s) feed available" % (item.data.name, channel)) ; return
         if item.markup.get(jsonstring([name, channel]), 'reverse-order'): res2 = res2[::-1]
         if item.markup.get(jsonstring([name, channel]), 'all-lines'):
             for i in res2:
                 response = self.makeresponse(name, [i, ], channel)
                 try: bot.say(channel, response)
                 except Exception as ex: handle_exception()
         else:
             sep =  item.markup.get(jsonstring([name, channel]), 'separator')
             if sep: response = self.makeresponse(name, res2, channel, sep=sep)
             else: response = self.makeresponse(name, res2, channel)
             bot.say(channel, response)
     except Exception as ex: handle_exception()
示例#18
0
文件: datadir.py 项目: buzzworkers/tl
def makeplugs():
    from tl.lib.fleet import getfleet
    from tl.lib.plugins import plugs
    plugs.loadall(force=True)
    plugs.save()
    fleet = getfleet()
    fleet.loadall()
    fleet.save()   
示例#19
0
文件: fleet.py 项目: buzzworkers/tl
def handle_fleetdel(bot, ievent):
    """ arguments: <botname> - delete bot from fleet. """
    try: name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    try:
        if getfleet().delete(name): ievent.reply('%s deleted' % name)
        else: ievent.reply('%s delete failed' % name)
    except Exception as ex: ievent.reply(str(ex))
示例#20
0
文件: xmpp.py 项目: buzzworkers/tl
def handle_xmppinvite(bot, event):
    """ arguments: <list of JIDs> - invite (subscribe to) a different user. """
    if not event.rest:
        event.missing("<list of JIDs>")
        return
    bot = getfleet().getfirstjabber()
    if bot:
        for jid in event.args: bot.invite(jid)
        event.done()
    else: event.reply("can't find jabber bot in fleet")
示例#21
0
文件: udp.py 项目: buzzworkers/tl
 def dosay(self, printto, txt):
     """ send txt to printto .. do some checks. """
     if cfg['udpparty'] and partyline.is_on(printto): partyline.say_nick(printto, txt) ; return
     if not cfg['udpbots']: bots = [cfg['udpbot'], ]
     else: bots = cfg['udpbots']
     for botname in bots:
         bot = getfleet().byname(botname)
         if not bot: logging.warn("udp - can't find %s bot in fleet" % botname) ; continue
         bot.connectok.wait()
         bot.say(printto, txt)
         for i in self.loggers: i.log(printto, txt)
示例#22
0
文件: fleet.py 项目: buzzworkers/tl
def handle_fleetdisconnect(bot, ievent):
    """ arguments: <botname> - disconnect a fleet bot from server. """
    try: botname = ievent.args[0]
    except IndexError:
        ievent.missing('<botname>')
        return
    ievent.reply('exiting %s' % botname)
    try:
        fleet = getfleet()
        if fleet.exit(botname): ievent.reply("%s bot stopped" % botname)
        else: ievent.reply("can't stop %s bot" % botname)
    except Exception as ex: ievent.reply("fleet - %s" % str(ex))
示例#23
0
文件: fleet.py 项目: buzzworkers/tl
def fleet_disable(bot, ievent):
    """ arguments: <list of botnames> - disable a fleet bot. """
    if not ievent.rest:
        ievent.missing("<list of botnames>")
        return
    fleet = getfleet()
    bots = fleet.loadall(ievent.args)
    for bot in bots:
        bot.cfg['disable'] = 1
        bot.cfg.save()
        ievent.reply('disabled %s bot.' % bot.cfg.name)
        fleet.exit(bot.cfg.name)
示例#24
0
def handle_feedback(bot, event):
    """ 
        arguments: <feedbacktxt> - give feedback to [email protected], this needs a jabber server to be able to send the feedback.
        the feedback command can be used in a pipeline.
    
    """ 
    if not event.rest and event.inqueue: payload = waitforqueue(event.inqueue, 2000)
    else: payload = event.rest 
    fleet = getfleet()
    feedbackbot = fleet.getfirstjabber()
    if not feedbackbot: event.reply("can't find an xmpp bot to send the feedback with") ; return
    event.reply("sending to [email protected]")
    feedbackbot.say("*****@*****.**", "%s send you this: %s" % (event.userhost, payload), event=event)
    event.done()
示例#25
0
文件: irccat.py 项目: buzzworkers/tl
 def handle(self):
     try:
         fleet = getfleet()
         msg = str(self.rfile.readline().strip())
         logging.warn("received %s" % msg)
         dest, msg = self.splitMsg(msg)
         for chan in dest:
             logging.info("sending to %s" % chan)
             for botname in fleet.list():
                 if botname not in cfg.botnames: continue
                 bot = fleet.byname(botname)
                 if bot: bot.say(chan, msg)
                 else: logging.error("can't find %s bot in fleet" % botname)
     except Exception as ex: handle_exception()
示例#26
0
def handle_nsauth(bot, ievent):
    """ arguments: [<botname>] - perform an auth request. """
    if bot.jabber: return
    if len(ievent.args) != 1: name = bot.cfg.name
    else: name = ievent.args[0]
    fbot = getfleet().byname(name)
    if not fbot:
        ievent.reply('fleet bot %s not found' % name)
        return
    if not nsauth.has(fbot):
        ievent.reply('nickserv not configured on %s' % fbot.cfg.name)
        return
    nsauth.identify(fbot)
    ievent.reply('ok')
示例#27
0
def handle_nsdel(bot, ievent):
    """ arguments: <botname> - remove a bot from nickserv. """
    if bot.jabber: return
    if len(ievent.args) != 1:
        ievent.missing('<botname>')
        return
    botname = ievent.args[0]
    fbot = getfleet().byname(botname)
    if not fbot:
        ievent.reply('fleet bot %s not found' % botname)
        return
    if not nsauth.has(fbot):
        ievent.reply('nickserv not configured on %s' % fbot.cfg.name)
        return
    nsauth.remove(fbot)
    ievent.reply('ok')
示例#28
0
文件: relay.py 项目: buzzworkers/tl
def handle_relay(bot, event):
    """ arguments: [<botname>] [<type>] <target> .. open a relay to a user. all input from us will be relayed. """
    try: (botname, type, target) = event.args
    except ValueError:
        try: botname = bot.cfg.name ; (type, target) = event.args
        except ValueError:
            try: botname = bot.cfg.name ; type = bot.cfg.bottype ; target = event.args[0]
            except IndexError: event.missing('[<botname>] [<bottype>] <target>') ; return 
    origin = str((bot.cfg.name, event.channel))
    if not getfleet().byname(botname): event.reply("no %s bot in fleet." % botname) ; return
    if origin not in relay.data: relay.data[origin] = []
    try:
        if not [type, target] in relay.data[origin]:
            relay.data[origin].append([botname, type, target])
            relay.save()
    except KeyError: relay.data[origin] = [[botname, type, target], ] ; relay.save()
    event.done()
示例#29
0
 def _resume(self, data, reto=None):
     """ resume a party line connection after reboot. """
     fleet = getfleet()
     for i in data['partyline']:
         logging.warn("partyline - resuming %s" % i)
         bot = fleet.byname(i['botname'])
         if not bot: logging.error("partyline - can't find bot") ; continue
         sock = socket.fromfd(i['fileno'], socket.AF_INET, socket.SOCK_STREAM)
         sock.setblocking(1)
         nick = i['nick']
         userhost = i['userhost']
         channel = i['channel']
         if not bot:
             logging.error("partyline - can't find %s bot in fleet" % i['botname'])
             continue
         self.socks.append({'bot': bot, 'sock': sock, 'nick': nick, 'userhost': userhost, 'channel': channel, 'silent': i['silent']})
         bot._dccresume(sock, nick, userhost, channel)        
         if reto: self.say_nick(nick, 'rebooting done')
示例#30
0
文件: forward.py 项目: buzzworkers/tl
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())