-
Notifications
You must be signed in to change notification settings - Fork 1
/
bokkabot.py
executable file
·50 lines (43 loc) · 1.23 KB
/
bokkabot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)