def chanmsg(self, conn, user, channel, message): ch = self.channels[conn.factory.network, conn.irclower(channel)] if message.strip().lower() == "!next": ch.nobodygotit() elif message.strip().lower() == "!stop": ch.on = False ch.timer.stop() elif message.strip().lower() == "!start": ch.on = True ch.doquestion() elif message.strip().lower() == "!hint": stars = [i for i, c in enumerate(ch.hint) if c == "*"] n = min(3, len(stars)-3) if n >= 1: for i in random.sample(stars, n): ch.hint = ch.hint[:i] + ch.answer[i] + ch.hint[i+1:] ch.post("Hint!!!!! \x037" + ch.hint) elif ch.on: inp = ' '.join(message.strip().lower().split()) ans = ' '.join(ch.answer.strip().lower().split()) if inp == ans: ch.post("%s got the answer! %s" % (irc.usersplit(user).group("nick"), ch.explanation)) ch.doquestion() elif dameraulevenshtein.dameraulevenshtein(inp, ans) / len(ans) <= .2: ch.post(message + "? \x033That's close!") print "levenshtein" elif metaphone.dm(inp) == metaphone.dm(ans): ch.post(message + "? \x033That's close!") print "metaphone"
def privmsg(self, user, message): nick, ident, host = irc.usersplit(user).groups() if (ident, host) not in self.queries: self.queries[ident, host] = Query(self.factory, nick) self.queries[ident, host].window.addline("<%s> %s" % (nick, message))