<commit_before>from irc import Bot

class Tofbot(Bot):

    def dispatch(self, origin, args):
        print ("o=%s a=%s" % (origin.sender, args))
        if (args[0] == 'End of /MOTD command.'):
            for chan in self.channels:
                self.write(('JOIN', chan))
        if origin.sender is None:
            return
        chan = args[2]
        msg = args[0]
        if (msg == '!blague'):
            self.cmd_blague(chan)
        if (msg == '!chuck'):
            self.cmd_chuck(chan)

    def cmd_blague(self, chan):
        self.msg(chan, "Ceci est une blague")

    def cmd_chuck(self, chan):
        self.msg(chan, "Chuck Norris can solve the halting problem. He kicks the Turing machine's ass.")<commit_msg>Add riddle support<commit_after>from irc import Bot

class Riddle(object):
    def __init__(self, riddle, answer, channel, writeback):
        self.riddle = riddle
        self.answer = answer
        self.channel = channel
        self.writeback = writeback
        self.remaining_msgs = 2
        self.writeback(self.riddle)

    def wait_answer(self, chan):
        if chan != self.channel:
            return False
        self.remaining_msgs -= 1
        if (self.remaining_msgs == 0):
            self.writeback(self.answer)
            return True
        return False

class Tofbot(Bot):

    def dispatch(self, origin, args):
        print ("o=%s a=%s" % (origin.sender, args))
        if (args[0] == 'End of /MOTD command.'):
            for chan in self.channels:
                self.write(('JOIN', chan))
        if origin.sender is None:
            return
        chan = args[2]
        msg = args[0]
        if (msg == '!blague'):
            self.cmd_blague(chan)
        if (msg == '!chuck'):
            self.cmd_chuck(chan)
        if (msg == '!devinette' and not self.active_riddle()):
            self.devinette = self.random_riddle(chan)
        if self.active_riddle():
            if (self.devinette.wait_answer(chan)):
                self.devinette = None

    def active_riddle(self):
        return (hasattr(self, 'devinette') and self.devinette is not None)

    def cmd_blague(self, chan):
        self.msg(chan, "Ceci est une blague")

    def cmd_chuck(self, chan):
        self.msg(chan, "Chuck Norris can solve the halting problem. He kicks the Turing machine's ass.")

    def random_riddle(self, chan):
        r = Riddle ("A ?", "B !", chan, lambda msg: self.msg(chan, msg))
        return r
{'fraction_non_alphanumeric': 0.12281415209434729, 'fraction_numerical': 0.0036600244001626678, 'mean_word_length': 2.0521091811414394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2377792', 'n_tokens_mistral': 805, 'n_tokens_neox': 769, 'n_words': 214}