<commit_before>from datetime import datetime
from toflib import cmd, Plugin
import re

class TimeSlice():

    def __init__(self):
        t = datetime.now()
        self.date = t.date()
        self.hour = t.hour
        self.count = 0

    def __str__(self):
        return "%s %02dh-%02dh : %d lolz" % ( self.date.strftime("%d %b")
                                            , self.hour
                                            , self.hour+1 % 24
                                            , self.count
                                            )

    def __cmp__(self, other):
        return cmp ( (self.date, self.hour)
                   , (other.date, other.hour)
                   )

    def __hash__(self):
        return hash(self.date) + hash(self.hour)

    def __iadd__(self, other):
        self.count += other
        return self

class PluginLolrate(Plugin):

    def __init__(self, bot):
        Plugin.__init__(self, bot)
        self.lolRate = [TimeSlice()]
        bot._mutable_attributes['lolRateDepth'] = int

    def handle_msg(self, msg_text, chan, nick):
        lulz = len(re.findall("[Ll]+[oO]+[Ll]+", msg_text))
        if lulz > 0:
            ts = TimeSlice()
            if ts != self.lolRate[0]:
                self.lolRate.insert(0,ts)

            if len(self.lolRate) > self.bot.lolRateDepth:
                self.lolRate.pop()

            self.lolRate[0] += lulz

    @cmd(0)
    def cmd_lulz(self, chan, args):
        for lolade in self.lolRate:
            self.say(str(lolade))<commit_msg>Add !kevin (get most prolific loler) in lolrate.<commit_after>from datetime import datetime
from toflib import cmd, Plugin
import re

class TimeSlice():

    def __init__(self):
        t = datetime.now()
        self.date = t.date()
        self.hour = t.hour
        self.kevins = dict()
        self.count = 0

    def __str__(self):
        return "%s %02dh-%02dh : %d lolz" % ( self.date.strftime("%d %b")
                                            , self.hour
                                            , self.hour+1 % 24
                                            , self.count
                                            )
      

    def __cmp__(self, other):
        return cmp ( (self.date, self.hour)
                   , (other.date, other.hour)
                   )

    def __hash__(self):
        return hash(self.date) + hash(self.hour)

    def lol(self, nick, count):
      self.kevins.setdefault(nick,0)
      self.kevins[nick] += count
      self.count += count

class PluginLolrate(Plugin):

    def __init__(self, bot):
        Plugin.__init__(self, bot)
        self.lolRate = [TimeSlice()]
        bot._mutable_attributes['lolRateDepth'] = int

    def handle_msg(self, msg_text, chan, nick):
        lulz = len(re.findall("[Ll]+[oO]+[Ll]+", msg_text))
        if lulz > 0:
            ts = TimeSlice()
            if ts != self.lolRate[0]:
                self.lolRate.insert(0,ts)

            if len(self.lolRate) > self.bot.lolRateDepth:
                self.lolRate.pop()

            self.lolRate[0].lol(nick,lulz)

    @cmd(0)
    def cmd_lulz(self, chan, args):
        for lolade in self.lolRate:
            self.say(str(lolade))

    @cmd(0)
    def cmd_kevin(self, chan, args):
      kevins = dict()
      for lolade in self.lolRate:
        for kevin in lolade.kevins.iteritems():
          kevins.setdefault(kevin[0],0)
          kevins[kevin[0]] += kevin[1]

      if len(kevins) > 0:
        kevin = max(kevins,key=lambda a: kevins.get(a))
        lolades = kevins[kevin]
        self.say(str(kevin) + " est le Kevin du moment avec " + str(lolades) + " lolade" + ("s" if lolades > 1 else ""))
      else:
        self.say("pas de Kevin")

{'fraction_non_alphanumeric': 0.1239247311827957, 'fraction_numerical': 0.00913978494623656, 'mean_word_length': 1.5451436388508892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5787634', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1161, 'n_words': 256}