예제 #1
0
파일: core.py 프로젝트: buzzworkers/tl
def handle_threads(bot, ievent):
    """ no arguments - show running threads. """
    try: import threading
    except ImportError:
         ievent.reply("threading is not enabled.")
         return
    stats = StatDict()
    names = Dol()
    threadlist = threading.enumerate()
    for thread in threadlist:
        name = thread.getName()
        try: type = thread.type
        except AttributeError: type = name
        stats.upitem(type)
        try: names.add(type, thread.nowrunning)
        except AttributeError: pass
    if ievent.rest:
        result = []
        for item, n in names.items():
            if not n: continue
            res = "%s: " % item
            for name in n: res += "%s, " % name
            result.append(res[:-2])
        result.sort()
        ievent.reply("nowrunning: ", result, dot="<br>")
    result = []
    for item in stats.top(): result.append("%s = %s" % (item[0], item[1]))
    result.sort()
    ievent.reply(", ".join(result))
예제 #2
0
파일: karma.py 프로젝트: buzzworkers/tl
 def whatup(self, nick):
     """ show what items are upped by nick """
     global db
     if not db: logging.error("plugin isnt initialised yet") ; return []
     nick = nick.lower()
     statdict = StatDict()
     result = db.execute(""" SELECT item FROM whokarma WHERE nick = %s AND updown = 'up' """, nick)
     if not result: return []
     for i in result: statdict.upitem(i[0])
     return statdict.top()
예제 #3
0
파일: hubbub.py 프로젝트: buzzworkers/tl
 def scan(self, name):
     """ scan a rss url for tokens. """
     keys = []
     items = self.fetchdata(name)
     for item in items:
         for key in item:
             if key in allowedtokens: keys.append(key)            
     statdict = StatDict()
     for key in keys: statdict.upitem(key)
     return statdict.top()  
예제 #4
0
파일: karma.py 프로젝트: buzzworkers/tl
 def quotegood(self, limit=10):
     """ show top 10 of karma items """
     global db
     if not db: logging.error("plugin isnt initialised yet") ; return []
     statdict = StatDict()
     result = db.execute(""" SELECT item, value FROM karma """)
     if not result: return []
     for i in result:
         if not i[0].startswith('quote '): continue
         statdict.upitem(i[0], value=i[1])
     return statdict.top(limit=limit)
예제 #5
0
파일: karma.py 프로젝트: buzzworkers/tl
def handle_whokarmadown(bot, ievent):
    """ karma-whodown <item> .. show who decreased a karma item """
    if not ievent.rest: ievent.missing('<item>') ; return
    item = ievent.rest
    result = karma.getwhodown(item)
    statdict = StatDict()
    if result:
        for i in result: statdict.upitem(i)
        res = []
        for i in statdict.top(): res.append("%s=%s" % i)
        ievent.reply("whokarmadown of %s: " % item, res)
    else: ievent.reply('no whokarmadown data available for %s' % item)
예제 #6
0
파일: chatlog.py 프로젝트: buzzworkers/tl
def handle_chatlogstats(bot, event):
    """ no arguments - create log stats of the channel, possible options: --chan <channel> """
    what = event.rest.strip()
    chatlogdir = getdatadir() + os.sep + "chatlogs"
    if event.options and event.options.channel: chan = event.options.channel
    else: chan = event.channel
    logs = os.listdir(chatlogdir)
    if not logs: event.reply("no logs available for %s" % chan) ; return
    now = time.time()
    if what: timetarget = strtotime2(what) ; what = striptime(what)
    else: timetarget = 0 ; what = None
    event.reply("creating stats for channel %s (%s)" % (chan, time.ctime(timetarget)))
    userstats = StatDict()
    wordstats = StatDict()
    stop = False
    for f in logs[::-1]:
        filename = stripname(f)
        channel = stripname(chan)
        if not channel in filename: continue
        for line in open(chatlogdir + os.sep + filename, 'r'):
            splitted = line.strip().split()
            if len(splitted) < 2: continue
            who = "unknown"
            for i in splitted:
               if i.startswith("<"): who = i[1:-1]
            if what and who != what: continue
            timestr = "%s %s" % (splitted[0], splitted[1])
            logtime = strtotime2(timestr)
            if logtime:
                if logtime > timetarget: userstats.upitem(who)
                else: continue
            else: userstats.upitem(who)
            for word in splitted[4:]: wordstats.upitem(word)
    if what: result = wordstats.top()
    else: result = userstats.top()
    if result:
        res = ["%s: %s" % item for item in result]
        event.reply("stat results for %s: " % (what or chan), res)
    else: event.reply("no result found for %s" % (what or chan))