Exemplo n.º 1
0
    def updateStats(self, m):
        msg = StringUtil.removeFormattingAndColors(m.getTrailing()).lower()
        word_count = len(msg.split())
        seen_types = {}
        pure = True

        for word_type, (impure, rx) in WORD_TYPES_RX.items():
            if re.search(rx, msg):
                if impure:
                    pure = False
                seen_types[word_type] = True

        # goat is fickle.
        if random.random() < .0005:
          pure = False

        user_store = KVStore.getUserStore(m)
        user_store.save(LAST_SEEN, time.time())

        chan_store = KVStore.getChanStore(m)
        for store, is_channel in [(chan_store, True), (user_store, False)]:
            if pure:
                self.purity_update(m, store, is_channel)
            else:
                self.purity_fail(m, store, is_channel)
            store.incSave(LINE_COUNT)
            store.incSave(WORD_COUNT, word_count)
            for word_type, seen in seen_types.items():
                store.incSave(word_type, 1)
Exemplo n.º 2
0
    def processChannelMessage(self, m):
        if m.sender in BOT_NAMES:
            return

        commands = {
            "stats": self.gen_stats_reply,
            "purity": self.gen_purity_reply,
            "sexstats": self.gen_sex_reply,
        }

        if m.modCommand in commands:
            reply = "I'm afraid I just don't know."
            parser = CommandParser(m)
            if parser.hasVar("user"):
                user = parser.get("user")
                if KVStore.hasUserStore(user):
                    user_store = KVStore.getUserStore(user)
                    reply = commands[m.modCommand](user, user_store)
            else:
                chan_store = KVStore.getChanStore(m)
                reply = commands[m.modCommand](m.getChanname(), chan_store)
            m.reply("%s: %s" % (m.sender, reply))
        else:
            self.updateStats(m)