Created
July 14, 2011 20:36
-
-
Save Motoma/1083376 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def learn(self, user, msg): | |
global factoids, substitutions | |
msg = msg.strip() | |
if msg[0] == '[' and ']' in msg[6:]: | |
epos = msg.find(']') | |
token = msg[1:epos] | |
body = msg[epos + 1:] | |
if not factoids.has_key(token): | |
factoids[token] = [] | |
factoids[token].append(body.strip()) | |
save_database() | |
if msg[0] == '<' and '>' in msg[3:]: | |
epos = msg.find('>') | |
token = msg[1:epos] | |
body = msg[epos + 1:] | |
if not substitutions.has_key(token): | |
substitutions[token] = [] | |
substitutions[token].append(body.strip()) | |
save_database() | |
def react(self, user, channel, msg): | |
global factoids, substitutions | |
msg = msg.lower() | |
facts = [] | |
for x in factoids: | |
l = x.lower() | |
if ' %s ' % (l,) in msg or msg[:len(l)] == l or msg[-len(l):] == l or msg[-len(l) - 1:-1] == l: | |
fact = substitute(choice(factoids[x])) | |
facts.append((x, fact)) | |
if len(facts) > 0: | |
fact = choice(facts) | |
self.send_msg(channel, '%s %s' % fact) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment