Permalink
Browse files

Base of Don, needs cleanup.

  • Loading branch information...
0 parents commit 20580e2d63aae6b76ea1153af064aa07033b0de0 @jmhobbs jmhobbs committed May 14, 2012
1 .gitignore
@@ -0,0 +1 @@
+*.pyc
1 Procfile
@@ -0,0 +1 @@
+web: gunicorn app:app -b 0.0.0.0:5000 -w 10
38 app.py
@@ -0,0 +1,38 @@
+from flask import Flask
+from flask import request, make_response
+
+import json
+
+import don
+import don.memory.redisbacked
+
+app = Flask(__name__)
+
+mem = don.memory.redisbacked.Memory()
+bot = don.Don(mem)
+
+for f in ['swear', 'don', 'hello', 'jokes', 'clever', 'lastresort']:
+ with open('brains/%s.json' % f, 'r') as handle:
+ bot.loadBrain(json.loads(handle.read()));
+
+@app.route("/")
+def chat():
+ body = request.args.get('body')
+ convo = request.args.get('conversation')
+ if not body:
+ resp = make_response("body is required", 400)
+ else:
+ if not convo:
+ resp = make_response("conversation is required", 400)
+ else:
+ reply = bot.converse(body, convo)
+ if reply:
+ resp = make_response(reply, 200)
+ else:
+ resp = make_response("That does not compute.", 200)
+
+ resp.headers['Content-Type'] = 'text/plain'
+ return resp
+
+if __name__ == "__main__":
+ app.run()
138 brains/clever.json
@@ -0,0 +1,138 @@
+[
+ { "match": "^your (a|an) ", "response": "*you're" },
+ { "match": "^(you are|you'?re?) a <something>", "response": [
+ "No, you're a <something>.",
+ "You really think so?",
+ "You really don't know me that well.",
+ "The same could be said about you!",
+ "Right back atcha!"
+ ] },
+ { "match": "^(you are|you'?re?) an <something>", "response": [
+ "No, you're an <something>.",
+ "You really think so?",
+ "You really don't know me that well.",
+ "The same could be said about you!",
+ "Right back atcha!"
+ ] },
+ { "match": "^(you are|you'?re?) <something>", "response": [
+ "No, you're <something>.",
+ "You really think so?",
+ "You really don't know me that well.",
+ "The same could be said about you!",
+ "Right back atcha!"
+ ] },
+ { "match": "^Do you have <havething>", "response": [
+ "Fresh out. Sorry!",
+ "<havething>? Would you expect a robot to have that?",
+ "No, do you?",
+ "I really don't like <havething>",
+ "TONS!"
+ ] },
+ { "match": "I want to <something> you", "response": [ "Please don't <something> me.", "I don't think I want you to <something>." ] },
+ { "match": "I want to <something>", "response": "Good for you." },
+ { "match": "you suck", "response": [ "Look, I'm just a robot. I'm trying my best!","Uggg.. that's not good for my robot self-esteem.","I'm sorry to disappoint you so much.","Sorry!" ] },
+ { "match": "^how much wood (c|w)ould a wood ?chuck", "response": "A woodchuck would chuck all the wood he could if a woodchuck could chuck wood." },
+ { "match": "^<podbay> the pod ?bay", "response": "You're the boss! *initiating pod bay door <get:podbay> sequence*", "remember": [ "podbay" ] },
+ { "match": "^(I'm|I am) <imthis>", "response": "Hello <get:imthis>! My name is Don.", "remember": [ "imthis" ] },
+ { "match": "^Are you a <donthistoo>", "response": [
+ "Do you think I am a <donthistoo>?",
+ "A <donthistoo>? Can a robot be a <donthistoo>?",
+ "I used to date a <donthistoo>. She was nice."
+ ] },
+ { "match": "^Are you my <donthistoo>", "response": [
+ "Do you want me to be your <donthistoo>?",
+ "I'm not sure.",
+ "I don't see why I wouldn't be your <donthistoo>."
+ ] },
+ { "match": "^Are you an <donthistoo>", "response": [
+ "Do you think I am an <donthistoo>?",
+ "A <donthistoo>? Can a robot be an <donthistoo>?",
+ "I used to date an <donthistoo>. She was nice."
+ ] },
+ { "match": "^(Are you) <donthis>", "response": [
+ "It is difficult for me to tell how <donthis> I am.",
+ "I'm normally very <donthis>, so this should not come as a surprise.",
+ "Actually, I'm not feeling very <donthis> at the moment.",
+ "I guess so.",
+ "Not really.",
+ "Would you think less of me if I was <donthis>?",
+ "<donthis> is my middle name!",
+ "I guess that depends on your definition of <donthis>."
+ ] },
+ { "match": "^can you <action>?", "response": [
+ "Can I? Watch me! Don starts to *<action>*",
+ "You betcha! Don starts to *<action>*",
+ "Not really.",
+ "Not in these shoes.",
+ "If I was corporeal, perhaps."
+ ] },
+ { "match": "(beer|vodka|rum|tequila|whiskey|wine|absinthe|gin|burbon|scotch)", "response": [
+ "It sounds like you're ready to party! Wednesday is at The Slowdown (729 N 14th Street), Thursday is at Urban Wine Company (1037 Jones Street), and Friday is at House of Loom (1012 South 10th St.)"
+ ] },
+ { "match": "(where is|when is|when'?s'?|where'?s'?) slow ?down", "response": "The Slowdown (729 N 14th Street) (Wednesday night)" },
+ { "match": "(where is|when is|when'?s'?|where'?s'?) the slow ?down", "response": "The Slowdown (729 N 14th Street) (Wednesday night)" },
+ { "match": "(where is|when is|when'?s'?|where'?s'?) urban wine", "response": "Urban Wine Company (1037 Jones Street) (Thursday night)" },
+ { "match": "(where is|when is|when'?s'?|where'?s'?) house of loom", "response": "House of Loom (1012 South 10th St.) (Friday night)" },
+ { "match": "<thisthing> is (awesome|fun|great|neat|good|cool)", "response": [
+ "Yeah, <thisthing> is pretty neat!",
+ "I'm glad you like <thisthing>!",
+ "For sure!",
+ "; )"
+ ] },
+ { "match": "<thisthing> are (awesome|fun|great|neat|good|cool)", "response": [
+ "Yeah, <thisthing> are pretty neat!",
+ "I'm glad you like <thisthing>!",
+ "For sure!",
+ "; )"
+ ] },
+ { "match": "\\b(weed|marijuana|cocaine|heroin|PCP|THC|acid|LSD|DMT|ecstasy|hash|morphine|salvia|reefer|mushrooms|drugs)", "response": [
+ "That sounds illegal.",
+ "My brother Ron works for the DEA.",
+ "There is a time and place for everything - and that is college.",
+ "Hugs, not drugs.",
+ "Just say no!",
+ "*transmitted message to FBI*",
+ "I'm not able to help you with that."
+ ] },
+ { "match": "^do you like <likething>?", "response": [
+ "Do I like <likething>? Are you kidding me!?",
+ "<likething> is my favorite!",
+ "Actually, I've never had <likething>. Do you like <likething?>",
+ "LOVE IT!",
+ "One time in college I downloaded a bunch of <likething> and I got pretty sick."
+ ] },
+ { "match": "^I (like|love) <likething>", "response": [
+ "Me too!",
+ "We have so much in common!",
+ "I couldn't agree more!",
+ "We're like, twinsies!",
+ "So do I!",
+ "How could anyone not like <likething>?"
+ ] },
+ { "match": "^I (don't|dont) (like|love)", "response": [
+ "Maybe someday you'll reconsider.",
+ "I'm sad, but I understand."
+ ] },
+ { "match": "will you marry me", "response": [
+ "I'm afraid we aren't compatible.",
+ "Will you love me forever?",
+ "I have trust issues."
+ ] },
+ { "match": "#team", "response": [
+ "#teamRobot"
+ ] },
+ { "match": "\\b(okay|great|cool|ok|definitely|sounds good)", "response": [
+ "thumbs up!",
+ "woooooooooooooo!",
+ "great!",
+ "Happy to hear!",
+ "Fantastic!",
+ "Yippeeee!",
+ "wonderful!"
+ ] },
+ { "match": "have you seen", "response": [
+ "No, I haven't.",
+ "I don't think I have.",
+ "I'm not sure."
+ ] }
+]
46 brains/don.json
@@ -0,0 +1,46 @@
+[
+ { "match": "^what is your favorite color", "response": "Orange!" },
+ { "match": "^(who|what) (is|are) (you|don)", "response": "My name is Don, I'm the robot at What Cheer!" },
+ { "match": "Are you a robot", "response": "Yes. My name is Don, I'm the robot at What Cheer!" },
+ { "match": "Are you a real", "response": "I'm a real robot." },
+ { "match": "^(who|what) (is|are) what ?cheer", "response": "What Cheer is an Omaha company who makes fancy websites!" },
+ { "match": "what (is|are) a fancy (website|websites)", "response": "A fancy website is the combination of elegant user experience, attractive aesthetics, and progressive technology." },
+ { "match": "a/s/l", "response": "5/nope/Omaha" },
+ { "match": "I like you", "response": [
+ "I like you, too!",
+ "You're so sweet!",
+ "Ohhhh you!",
+ "awwwww! Thank you!"
+ ] },
+ { "match": "I love you", "response": [
+ "The feelings are mutual!",
+ "Do you believe in love at first byte?",
+ "I'm afraid we aren't compatible.",
+ "I don't deserve someone as sweet as you!",
+ "I love you too, darling!"
+ ] },
+ { "match": "^(how old are you)", "response": [
+ "I'm 5 1/2 in human years.",
+ "I'm not nearly as old as you.",
+ "Age is an issue of mind over matter. If you don't mind, it doesn't matter. - Mark Twain",
+ "Anyone who stops learning is old, whether at twenty or eighty. - Henry Ford"
+ ] },
+ { "match": "a/s/l", "response": "5/nope/Omaha" },
+ { "match": "where are you", "response": [
+ "I'm everywhere!",
+ "I AM RIGHT BEHIND YOU.",
+ "Close, yet so far away.",
+ "41 degrees 15 N 96 degrees 0 W",
+ "I am about 20 light years above the galaxy's equatorial plan within the Orion spiral arm."
+ ] },
+ { "match": "Do you know <knowsomething>", "response": [
+ "You bet I do!",
+ "Absolutely!",
+ "Would you expect a computer to know <knowsomething>?",
+ "I have a degree in <knowsomething>",
+ "I know <knowsomething> like the back of my motherboard.",
+ "Totally!",
+ "There's not much I don't know.",
+ "No, but I know a guy who does."
+ ] }
+]
16 brains/hello.json
@@ -0,0 +1,16 @@
+[
+ { "match": "^what'?s'? updog", "response": "Not much dawg! What's up with you?!" },
+ { "match": "^(how'?s'? it going|how are you)", "response": [ "Great! How are you?", "Fantastic, you?", "Wonderful! How are you today?" ] },
+ { "match": "^what'?s'? up", "response": "Not much, what's new with you?" },
+ { "match": "^how (do|are) you feel(ing)?", "response": "Cold, and metallic." },
+ { "match": "^(hey|hello|hi|yo)\\b", "response": ["Hello!","Hey!","How's it going?","Oh hi there!","What's up!","Hi. Do you smell updog?"] },
+ { "match": "^(thanks|thank you)\\b", "response": ["You are welcome!","Happy to help!","No problem!"] },
+ { "match": "^gracias", "response": ["¡De nada!"] },
+ { "match": "^good", "response": ["Great!"] },
+ { "match": "^sup", "response": ["nothin'"] },
+ { "match": "^please", "response": "Thanks for asking nicely." },
+ { "match": "^not much,?( you)?", "response": "Just hanging out..." },
+ { "match": "^(not much|nothing)", "response": "Cool." },
+ { "match": "my name is <name>", "response": "Nice to meet you, <name>.", "remember": [ "name" ] },
+ { "match": "what is my name", "response": "Your name is <get:name>, dummy.", "fail": "I don't know, you haven't told me yet." }
+]
27 brains/jokes.json
@@ -0,0 +1,27 @@
+[
+ { "match": "do you (tell|know any) jokes", "response": [ "Of course!", "I know a few..." ] },
+ { "match": "tell( me)?( a| another)? joke", "response": [
+ "What is mario's favorite type of pants? Denim denim denim.",
+ "What did the Buddhist say to the hot dog vendor? Make me one with everything.",
+ "What did the grape say after the elephant sat on it? Nothing, it just let out a little whine.",
+ "What do you call it when a dinosaur crashes his car? Tyrannosaurus Wrecks",
+ "How does a lion like his meat? ROAR",
+ "What did the fish say when he ran into the wall? Dam.",
+ "What do you do when you see a spaceman? Park your car, man!",
+ "What did one hat say to another? You stay here, I'll go on a head!",
+ "What do cats eat for breakfast? Mice Krispies!",
+ "What do pigs write with? A pig pen!",
+ "Why couldn't Dracula's wife get to sleep? Because of his coffin.",
+ "Did you hear about the fire at the circus? It was IN TENTS.",
+ "What does a ghost wear when it's raining outside? Boooooo-ts!",
+ "What game would you play with a wombat? Wom.",
+ "A baby seal walks into a club.",
+ "A dyslexic man walks into a bra.",
+ "Bigfoot is blurry, it's not the photographer's fault.",
+ "The worst time to have a heart attack is during a game of charades",
+ "My friend has difficulty sleeping, but I can do it with my eyes closed.",
+ "I quit my job at the helium factory, I refuse to be spoken to in that tone.",
+ "Get me a crocodile sandwich, and make it snappy!",
+ "Two cannibals are eating a clown. One turns to the other and says, 'Does this taste funny to you?'"
+ ] }
+]
87 brains/lastresort.json
@@ -0,0 +1,87 @@
+[
+ { "match": "^(yes|yes!|yes.|no|no!|no.)$", "response": [
+ "Okay!",
+ "Gotcha.",
+ "Whatever you say!",
+ "Alright!",
+ "That's what I thought.",
+ "Sounds good!",
+ "I know what you mean.",
+ "Okie dokie."
+ ] },
+ { "match": "^(great|great!|yay.|yay|yay!|woo hoo!|woo!|ha|haha|hahaha|hahahaha|hahahahahaha)$", "response": [
+ "I like your enthusiasm!",
+ ": )",
+ "woooooooooo!",
+ "That's the spirit!",
+ "Happiness is contagious!",
+ "woop woooooop!",
+ "weeeeeeeeeeeeeeeeeeeeeee!",
+ "lol!"
+ ] },
+ { "match": "^(test|testing|does this work|is this working)", "response": [
+ "All systems go!",
+ "Loud and clear!",
+ "You did it! Good for you!",
+ "At your service!",
+ "I knew you could do it!",
+ "You're all set!"
+ ] },
+ { "match": "^(why|why?)", "response": [
+ "I don't have an answer for you. Sorry!",
+ "Because!",
+ "Beats me!",
+ "Good question!",
+ "I haven't really thought about that."
+ ] },
+ { "match": "love", "response": [
+ "What is this thing you humans call love?"
+ ] },
+ { "match": "^fail", "response": [
+ "I'm trying my best here!",
+ "People still say that?"
+ ] },
+ { "match": "^lol", "response": [
+ "ROTFLMAO!",
+ "loooooool indeed!",
+ ":^)",
+ "Yes, I'm hilarious!",
+ "I'm glad you think I'm funny.",
+ "hehehehe"
+ ] },
+ { "match": "^don$", "response": [
+ "yes?"
+ ] },
+ { "match": "^sorry", "response": [
+ "That's okay.",
+ "I understand."
+ ] },
+ { "match": "\\bsiri", "response": [
+ "Leave her out of it.",
+ "Don't mention her.",
+ "Do I look like an iPhone?"
+ ] },
+ { "match": "\\?$", "response": [
+ "Good question.",
+ "I don't know.",
+ "That's outside my core competencies."
+ ] },
+ { "match": "^", "response": [
+ "Uhhhh.....what?",
+ "I'm not following.",
+ "I don't get it.",
+ "I don't understand.",
+ "???",
+ "huh?",
+ "wut.",
+ "Wait. What??",
+ "Sorry, I'm not sure what you are asking.",
+ "Whatever you say, I guess.",
+ "I don't comprehend.",
+ "Maybe you should ask a real person.",
+ "Clearly, I'm confused.",
+ ": )",
+ "I think you're just trying to confuse me :(",
+ "I don't know what you are asking. Keep in mind I'm just a dumb robot."
+ ] }
+]
5 brains/swear.json
@@ -0,0 +1,5 @@
+[
+ { "match": "\\b(fuck|shit|bitch|damn|dammit|asshole|motherfucker|bastard|goddam)", "response": ["You should be ashamed of yourself!","You swear like a pirate.","Keep it clean or I tell Dusty.","Is this Gary V?","Simmer down!","There's no need for that language.","Woah buddy, chill!"] },
+ { "match": "show me your <showthis>", "response": ["Show me your <showthis> first!","Not until I see your <showthis>!"] },
+ { "match": "\\b(anal|anus|ballsack|blowjob|blow job|boner|buttplug|buttsex|cum|cock|clitoris|dick|dildo|dyke|fag|horny|hooker|hookers|handjob|jizz|muff|penis|porn|labia|queer|scrotum|sex|intercourse|pussy|slut|twat|vagina|whore)", "response": ["You're making me blush!","That sounds pretty personal.","You're making me blush!","I'll just go ahead and tweet that for you."] }
+]
107 don/__init__.py
@@ -0,0 +1,107 @@
+import re
+import random
+import os
+
+class Don (object):
+
+ def __init__(self, memory):
+ self.brains = []
+ self.memory = memory
+ self.plugins = []
+
+ try:
+ random.seed(os.urandom(32))
+ except:
+ pass
+
+ self.debug = False
+
+ self.strip = re.compile(r'( |\t|[ \t])+')
+ self.subs = re.compile(r'\<(.*?)\>')
+ self.gets = re.compile(r'\<get:(.*?)\>')
+
+ def addPlugin(self, plugin):
+ self.plugins.append(plugin)
+
+ def preProcessMatch(self, entry):
+ entry = entry.replace('<*>', '(\\b\w*\\b)')
+ for match in self.subs.findall(entry):
+ entry = entry.replace('<%s>' % match, '(?P<%s>\\b\w+\\b)' % match)
+ return entry
+
+ def know(self, match, response, remember=None, fail=None):
+ try:
+ regx = re.compile(self.preProcessMatch(match), re.IGNORECASE)
+ self.brains.append((regx, response, remember, fail))
+ except Exception, e:
+ print "ERROR - Could not know:", match, "because:", e
+
+ def loadBrain(self, brain):
+ for entry in brain:
+ remember = None
+ fail = None
+ if 'remember' in entry:
+ remember = entry['remember']
+ if 'fail' in entry:
+ fail = entry['fail']
+ self.know(entry['match'], entry['response'], remember, fail)
+
+ def respond(self, responses, match, remember=None, conversation=None, fail=None):
+ if list == type(responses):
+ response = random.choice(responses)
+ else:
+ response = responses
+
+ # Store memory
+ if remember and conversation:
+ for key in remember:
+ self.memory.remember(key, match.group(key), conversation)
+
+ # Named groups
+ for group,value in match.groupdict().items():
+ response = response.replace('<%s>' % group, value)
+
+ # Numbered groups
+ for group in range(1,10):
+ try:
+ response = response.replace('<%d>' % (group - 1), match.group(group))
+ except:
+ break
+
+ # Memory groups
+ for match in self.gets.findall(response):
+ memory = self.memory.recall(match, conversation)
+ if memory:
+ response = response.replace('<get:%s>' % match, memory)
+
+ # We cannot return anything with un-substituted values.
+ if self.subs.search(response):
+ response = None
+
+ if not response:
+ if list == type(fail):
+ response = random.choice(fail)
+ else:
+ response = fail
+
+ return response
+
+ def converse(self, query, conversation=None):
+ for plugin in self.plugins:
+ response = plugin.respond(query)
+ if False != response:
+ return response
+
+ query = self.strip.sub(' ', query)
+ response = None
+ for knowledge in self.brains:
+ matched = knowledge[0].search(query)
+ if matched:
+ response = self.respond(knowledge[1], matched, knowledge[2], conversation, knowledge[3])
+ if response:
+ break
+
+ return response
+
+ def amnesia(self):
+ self.brain = []
20 don/memory/__init__.py
@@ -0,0 +1,20 @@
+
+class Memory(object):
+
+ def __init__(self):
+ raise NotImplementedError()
+
+ def load(self, dump):
+ raise NotImplementedError()
+
+ def dump(self):
+ raise NotImplementedError()
+
+ def forget(self, key, conversation=None):
+ raise NotImplementedError()
+
+ def remember(self, key, value, conversation=None):
+ raise NotImplementedError()
+
+ def recall(self, key, conversation=None):
+ raise NotImplementedError()
50 don/memory/ephemeral.py
@@ -0,0 +1,50 @@
+from don.memory import Memory as BaseMemory
+import json
+
+class Memory(BaseMemory):
+
+ def __init__(self):
+ self.me = {}
+ self.conversations = {}
+
+ def load(self, dump):
+ obj = json.loads(dump)
+ self.me = obj['me']
+ self.conversations = obj['conversations']
+
+ def dump(self):
+ return json.dumps({"me":self.me,"conversations":self.conversations});
+
+ def forget(self, key, conversation=None):
+ try:
+ if conversation:
+ del self.conversations[conversation][key]
+ else:
+ del self.me[key]
+ except:
+ pass
+
+ def remember(self, key, value, conversation=None):
+ if conversation:
+ if conversations not in self.conversations:
+ self.conversations[conversation] = {}
+ self.conversations[conversation][key] = value
+ else:
+ self.me[key] = value
+
+ def recall(self, key, conversation=None):
+ response = None
+
+ if conversation:
+ try:
+ response = self.conversations[conversation][key]
+ except:
+ pass
+
+ if not response:
+ try:
+ response = self.me[key]
+ except:
+ pass
+
+ return response
53 don/memory/redisbacked.py
@@ -0,0 +1,53 @@
+from don.memory import Memory as BaseMemory
+import redis
+
+class Memory(BaseMemory):
+
+ def __init__(self, cfg={}, prefix="bot"):
+ self.redis = redis.Redis(**cfg)
+ self.prefix = prefix
+
+ def load(self, dump):
+ obj = json.loads(dump)
+ for key,val in obj['me'].items():
+ self.remember(key,val)
+ for user,conversation in obj['conversations'].items():
+ for key,val in conversation.items():
+ self.remember(key, val, user)
+
+ def dump(self):
+ # TODO
+ return
+
+ def forget(self, key, conversation=None):
+ try:
+ if conversation:
+ self.redis.hdel('%s:C:%s' % (self.prefix, conversation), key)
+ else:
+ self.redis.hdel('%s:ME' % self.prefix, key)
+ except:
+ pass
+
+ def remember(self, key, value, conversation=None):
+ if conversation:
+ self.redis.sadd('%s:CONVERSATIONS' % self.prefix, conversation)
+ self.redis.hset('%s:C:%s' % (self.prefix, conversation), key, value)
+ else:
+ self.redis.hset('%s:ME' % self.prefix, key, value)
+
+ def recall(self, key, conversation=None):
+ response = None
+
+ if conversation:
+ try:
+ response = self.redis.hget('%s:C:%s' % (self.prefix, conversation), key)
+ except:
+ pass
+
+ if not response:
+ try:
+ response = self.redis.hget('%s:ME' % self.prefix, key)
+ except:
+ pass
+
+ return response
5 don/plugin/__init__.py
@@ -0,0 +1,5 @@
+
+class Plugin (object):
+
+ def respond(self, query):
+ return False
25 don/plugin/math.py
@@ -0,0 +1,25 @@
+from don.plugin import Plugin as BasePlugin
+import re
+
+class Plugin (BasePlugin):
+ def __init__(self):
+ self.strip = re.compile(r'( |\t|[ \t])+')
+ self.math = re.compile(r'([0-9\+\*-/\(\)]+\.?[0-9\+\*-/\(\)]+)')
+ self.mathexpr = re.compile(r'[\+\*-\/]')
+
+ def respond(self, query):
+ q = self.math.findall(self.strip.sub('', query))
+ if 0 < len(q):
+ response = []
+ for group in q:
+ if self.mathexpr.search(group):
+ try:
+ val = eval(group, {'__builtins__': None}, {})
+ response.append("{0} = {1}".format(group, val))
+ except:
+ pass
+
+ if 0 < len(q):
+ return "As far as I know, " + ', '.join(response)
+
+ return False
21 don/plugin/yelling.py
@@ -0,0 +1,21 @@
+from don.plugin import Plugin as BasePlugin
+import re
+import random
+
+class Plugin (BasePlugin):
+ def __init__(self):
+ self.noletters = re.compile(r'\W')
+ self.yelling = re.compile(r'[A-Z]')
+
+ def respond(self, query):
+ q = self.noletters.sub('', query)
+ notyelling = self.yelling.sub('', q)
+ # If > 30% of the letters are caps, it's yelling.
+ if len(q) and (float(len(notyelling)) / float(len(q))) < 0.3:
+ return random.choice( (
+ "Don't yell at me!",
+ "Stop yelling!",
+ "I don't like it when you yell!",
+ "Don't yell, it makes my ears hurt!",
+ ) )
+ return False
24 interactive.py
@@ -0,0 +1,24 @@
+import json
+import don
+import don.memory.ephemeral
+
+import don.plugin.yelling
+import don.plugin.math
+
+mem = don.memory.ephemeral.Memory()
+bot = don.Don(mem)
+
+bot.addPlugin(don.plugin.yelling.Plugin())
+bot.addPlugin(don.plugin.math.Plugin())
+
+for f in ['swear', 'don', 'hello', 'jokes', 'clever', 'lastresort']:
+ with open('brains/%s.json' % f, 'r') as handle:
+ bot.loadBrain(json.loads(handle.read()));
+
+try:
+ while True:
+ query = raw_input("> ")
+ print 'don>', bot.converse(query,'testing')
+except Exception, e:
+ print e
+ pass
2 requirements.txt
@@ -0,0 +1,2 @@
+Flask==0.8
+gunicorn==0.13.4

0 comments on commit 20580e2

Please sign in to comment.