commit 11986cc5aa82ae5236fe4493358ea4d766b2f57e Author: Mathieu Maret Date: Tue Dec 29 17:59:27 2015 +0100 Initial commit ok, ok, it a late initial one include a wolfram search, some simple talking. Add a quickly, poorly written network server. diff --git a/brain/hello.rive b/brain/hello.rive new file mode 100644 index 0000000..655c1b2 --- /dev/null +++ b/brain/hello.rive @@ -0,0 +1,49 @@ +! version = 2.0 ++ (bonjour|salut|coucou|plop) [*] +- bonjour +- salut +- coucou +- plop + ++ my name is * +- >I will remember to call you . + ++ (what is|do you know) my name +* != undefined => Yes, your name is ! +- I don't know your name. + ++ (hello|hi) [*] +* != undefined => hi ! +* != undefined => hello ! +- hi ! what is your name ? +- hello ! what is your name ? + ++ * +% * what is your name ? +@ my name is + + ++ how [are] you [*] +- I'm great, how are you? +- I'm good, you? +- Good :) you? +- Great! You? +- I'm fine, thanks for asking! + ++ what is up +- Not much, you? +- nm, you? +- Not a lot, you? + ++ you are a bot +- How did you know I'm a machine? + ++ goodbye * +* != undefined => goodbye ! +- goodbye + ++ bye * +@goodbye + ++ say [that] * +- Umm... "" diff --git a/brain/sub.rive b/brain/sub.rive new file mode 100644 index 0000000..b5c1f56 --- /dev/null +++ b/brain/sub.rive @@ -0,0 +1,27 @@ +! version = 2.0 +// Substitutions +! sub i'm = i am +! sub i'd = i would +! sub i've = i have +! sub i'll = i will +! sub don't = do not +! sub isn't = is not +! sub you'd = you would +! sub you're = you are +! sub you've = you have +! sub you'll = you will +! sub what's = what is +! sub whats = what is +! sub what're = what are +! sub what've = what have +! sub what'll = what will + +//person +! person i am = you are +! person you are = i am +! person i'm = you're +! person you're = I'm +! person my = your +! person your = my +! person you = I +! person i = you diff --git a/brain/wolfram.rive b/brain/wolfram.rive new file mode 100644 index 0000000..2866006 --- /dev/null +++ b/brain/wolfram.rive @@ -0,0 +1,21 @@ +! version = 2.0 +> object wolfram_alpha python + import tungsten + APP_ID = 'TK5JGE-E4W4PA38LH' + + query = ' '.join(args) + client = tungsten.Tungsten(APP_ID) + result = client.query(query) + print(result) + + for pod in result.pods: + print(pod.id) + if pod.id == "Result": + return u'\n'.join(pod.format['plaintext']) + + return u"I do not understand :(" +< object + + ++ tell[-]me * +- wolfram_alpha diff --git a/main.py b/main.py new file mode 100755 index 0000000..2a2ce33 --- /dev/null +++ b/main.py @@ -0,0 +1,15 @@ +#!/usr/bin/python2.7 +#-*- coding: utf-8 -*- + +from rivescript import RiveScript + +rs = RiveScript() +rs.load_directory("./brain") +rs.sort_replies() + +while True: + msg = raw_input('>'); + if msg == '/quit': + quit() + reply = rs.reply("localuser", msg); + print(u'Bot > {0}'.format(reply)) diff --git a/netbot.py b/netbot.py new file mode 100644 index 0000000..85cf47b --- /dev/null +++ b/netbot.py @@ -0,0 +1,23 @@ +#!/usr/bin/python2.7 +#-*- coding: utf-8 -*- + +from rivescript import RiveScript +from twisted.internet import protocol, reactor, endpoints +from twisted.protocols.basic import LineReceiver + +class Echo(LineReceiver): + def lineReceived(self, line): + print("I just receive "+line) + self.sendLine('{0}'.format(rs.reply("localuser",line))) + +class EchoFactory(protocol.Factory): + def buildProtocol(self, addr): + return Echo() + + +rs = RiveScript() +rs.load_directory("./brain") +rs.sort_replies() + +endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory()) +reactor.run()