Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Abhishek Mishra
committed
Dec 27, 2009
1 parent
3997b10
commit fad7758
Showing
12 changed files
with
1,416 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from socket import * | ||
import logging | ||
import time | ||
import os | ||
|
||
import redis | ||
import aiml | ||
|
||
host = "localhost" | ||
port = 31337 | ||
buf = 1024 | ||
addr = (host,port) | ||
|
||
logging.basicConfig() | ||
log = logging.getLogger ("Bokkabot") | ||
log.setLevel(logging.INFO) | ||
|
||
log.info ("Connecting to Redis Server...") | ||
r = redis.Redis() | ||
log.info ("Binding Bokkabot on %s:%s" % addr) | ||
UDPSock = socket(AF_INET,SOCK_DGRAM) | ||
UDPSock.bind(addr) | ||
|
||
log.info ("Bootstrapping Bokka's brain from bokkabot.brn") | ||
k = aiml.Kernel() | ||
if os.path.isfile("bokkabot.brn"): | ||
k.bootstrap(brainFile = "bokkabot.brn") | ||
else: | ||
print "Bokka couldn't find its brain - bokkabot.brn" | ||
print "Please run makemeabrain.py" | ||
|
||
log.info ("Bokka is ready to talk the talk...") | ||
|
||
while True: | ||
data,addr = UDPSock.recvfrom(buf) | ||
if not data: | ||
print "Client has exited!" | ||
break | ||
else: | ||
# data is in format time|nick:msg | ||
log.info ("Received %s" % data) | ||
nick, msg = data.split('|',1)[1].split(':',1) | ||
response = "%s|%s:%s" % ( | ||
time.time(), | ||
'bokka', | ||
' @%s %s' % (nick, k.respond(msg)) | ||
) | ||
r.push ('msgs',response,tail=True) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# BrainMaker for BokkaBot 0.1 ideamonk at gmail.com | ||
|
||
# Based on - http://ravispeaks.wordpress.com/2009/09/16/diy-omegle-chat-bot | ||
# which is based on the PyAIML and liberally uses code from PyOmegle | ||
# PyAMIL:http://pyaiml.sourceforge.net/ | ||
# PyOmegle:http://code.google.com/p/pyomegle/ | ||
|
||
import aiml | ||
import os | ||
|
||
k = aiml.Kernel() | ||
|
||
homedir=os.getcwd() | ||
# You can get the AAA files from | ||
# http://aitools.org/Free_AIML_sets#Annotated_A.L.I.C.E | ||
os.chdir('./aaa') | ||
list=os.listdir('./'); | ||
for item in list: | ||
k.learn(item) | ||
k.setPredicate("name","BokkaBot") | ||
k.setPredicate("master","ideamonk") | ||
os.chdir(homedir) | ||
k.saveBrain("bokkabot.brn") |
Oops, something went wrong.