Example #1
0
def handle_karmawhoup(bot, event):
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    sd = StatDict(item.data.whoup)
    res = []
    for i in sd.top():
        res.append("%s: %s" % i)
    if res: event.reply("uppers of %s are: " % k, res)
    else: event.reply("nobody upped %s yet" % k)
Example #2
0
def handle_karmawhoup(bot, event):
    """ arguments: <item> - show who increased the karma of an item. """
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    sd = StatDict(item.data.whoup)
    res = []
    for i in sd.top():
        res.append("%s: %s" % i)
    if res: event.reply("uppers of %s are: " % k, res)
    else: event.reply("nobody upped %s yet" % k)
Example #3
0
 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()
Example #4
0
 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()  
Example #5
0
 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)
Example #6
0
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)
Example #7
0
def handle_karmagood(bot, event):
    """ arguments: none - show top karma items of a channel. """
    collection = PlugPersistCollection()
    stats = StatDict()
    objs = collection.objects(event.channel.lower())
    for name, obj in objs.iteritems():
       if not obj.data: logging.warn("%s is empty" % name) ; continue
       item = stripname(name).split("-")[-1]
       stats.upitem(item, obj.data.count)
    res = []
    for item in stats.top():
        res.append("%s - %s" % item)
    event.reply("top karma items of %s: " % event.channel, res)
Example #8
0
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[1:])
        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))
Example #9
0
def handle_karmawhoup(bot, event):
    """ arguments: <item> - show who increased the karma of an item. """
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    sd = StatDict(item.data.whoup)
    #    res = []
    #    for i in sorted(sd.top(),key=itemgetter(1), reverse=True):
    #        res.append("%s: %s" % i)
    res = ""
    for item in sorted(sd.top(), key=itemgetter(1), reverse=True):
        res += (str(item[0]) + ':' + str(item[1]) + ' ')
    if res: event.reply("uppers of " + k + " are: " + res)
    else: event.reply("nobody upped " + k + " yet")
Example #10
0
def handle_threads(bot, ievent):
    """ no arguments - show running threads. """
    try: import threading
    except ImportError:
         ievent.reply("threading is not enabled.")
         return
    stats = StatDict()
    threadlist = threading.enumerate()
    for thread in threadlist: stats.upitem(thread.getName())
    result = []
    for item in stats.top(): result.append("%s = %s" % (item[0], item[1]))
    result.sort()
    ievent.reply("threads running: ", result)
Example #11
0
def handle_karmawhoup(bot, event):
    """ arguments: <item> - show who increased the karma of an item. """
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    sd = StatDict(item.data.whoup)
#    res = []
#    for i in sorted(sd.top(),key=itemgetter(1), reverse=True):
#        res.append("%s: %s" % i)
    res = ""
    for item in sorted(sd.top(),key=itemgetter(1), reverse=True):
        res += (str(item[0])+':'+str(item[1])+' ')
    if res: event.reply("uppers of "+k+" are: "+ res)
    else: event.reply("nobody upped "+k+" yet")
Example #12
0
 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)
Example #13
0
 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()
Example #14
0
def handle_threads(bot, ievent):
    """ no arguments - show running threads. """
    try:
        import threading
    except ImportError:
        ievent.reply("threading is not enabled.")
        return
    stats = StatDict()
    threadlist = threading.enumerate()
    for thread in threadlist:
        stats.upitem(thread.getName())
    result = []
    for item in stats.top():
        result.append("%s = %s" % (item[0], item[1]))
    result.sort()
    ievent.reply("threads running: ", result)
Example #15
0
def handle_karmagood(bot, event):
    """ arguments: none - show top karma items of a channel. """
    collection = PlugPersistCollection()
#    event.reply('Processing karma list.')
    stats = StatDict()
    objs = collection.objects()
    for name, obj in objs.iteritems():
       if not obj.data: logging.warn("%s is empty" % name) ; continue
       item = stripname(name).split("-",2)[-1]
       if stripname(name).split("-",2)[1] == event.channel.lower()[1:]:
           stats.upitem(item, obj.data.count)
    ktop = stats.top(limit=20)
#    event.reply(str(ktop))
    res = ""
    for item in ktop:
        res += (str(item[0])+':'+str(item[1])+' ')
    event.reply('Top 20 Karma for '+event.channel+': '+ res)
Example #16
0
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)
Example #17
0
def handle_karmagood(bot, event):
    """ arguments: none - show top karma items of a channel. """
    collection = PlugPersistCollection()
    #    event.reply('Processing karma list.')
    stats = StatDict()
    objs = collection.objects()
    for name, obj in objs.iteritems():
        if not obj.data:
            logging.warn("%s is empty" % name)
            continue
        item = stripname(name).split("-", 2)[-1]
        if stripname(name).split("-", 2)[1] == event.channel.lower()[1:]:
            stats.upitem(item, obj.data.count)
    ktop = stats.top(limit=20)
    #    event.reply(str(ktop))
    res = ""
    for item in ktop:
        res += (str(item[0]) + ':' + str(item[1]) + ' ')
    event.reply('Top 20 Karma for ' + event.channel + ': ' + res)