Initial commit

ok, ok, it a late initial one

include a wolfram search, some simple talking.
Add a quickly, poorly written network server.
This commit is contained in:
Mathieu Maret 2015-12-29 17:59:27 +01:00
commit 11986cc5aa
5 changed files with 135 additions and 0 deletions

49
brain/hello.rive Normal file
View File

@ -0,0 +1,49 @@
! version = 2.0
+ (bonjour|salut|coucou|plop) [*]
- bonjour
- salut
- coucou
- plop
+ my name is *
- <set name=<formal>>I will remember to call you <get name>.
+ (what is|do you know) my name
* <get name> != undefined => Yes, your name is <get name>!
- I don't know your name.
+ (hello|hi) [*]
* <get name> != undefined => hi <get name>!
* <get name> != undefined => hello <get name>!
- hi ! what is your name ?
- hello ! what is your name ?
+ *
% * what is your name ?
@ my name is <star>
+ 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 *
* <get name> != undefined => goodbye <get name>!<set name=undefined>
- goodbye
+ bye *
@goodbye
+ say [that] *
- Umm... "<person>"

27
brain/sub.rive Normal file
View File

@ -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

21
brain/wolfram.rive Normal file
View File

@ -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 *
- <call>wolfram_alpha <star> </call>

15
main.py Executable file
View File

@ -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))

23
netbot.py Normal file
View File

@ -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()