Skip to content

Commit

Permalink
done with the bokkabot listenet
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Mishra committed Dec 27, 2009
1 parent 3997b10 commit fad7758
Show file tree
Hide file tree
Showing 12 changed files with 1,416 additions and 0 deletions.
Binary file modified bokkabot/aiml/AimlParser.pyc
Binary file not shown.
Binary file modified bokkabot/aiml/DefaultSubs.pyc
Binary file not shown.
Binary file modified bokkabot/aiml/Kernel.pyc
Binary file not shown.
Binary file modified bokkabot/aiml/PatternMgr.pyc
Binary file not shown.
Binary file modified bokkabot/aiml/Utils.pyc
Binary file not shown.
Binary file modified bokkabot/aiml/WordSub.pyc
Binary file not shown.
Binary file modified bokkabot/aiml/__init__.pyc
Binary file not shown.
Binary file added bokkabot/bokkabot.brn
Binary file not shown.
50 changes: 50 additions & 0 deletions bokkabot/bokkabot.py
@@ -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)
24 changes: 24 additions & 0 deletions bokkabot/makemeabrain.py
@@ -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")

0 comments on commit fad7758

Please sign in to comment.