summaryrefslogtreecommitdiff
path: root/pyaiml_test.py
blob: 3b23cd50de3724cd3d85480373a0b1d9c22f23fc (plain)
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
import aiml

k=aiml.Kernel()
k.bootstrap(learnFiles="std-startup.xml", commands="load aiml b")
while True: print k.respond(raw_input("> "))

"""
from twisted.python import log
from kippo.core import honeypot

learnFiles="std-startup.xml"


class HalCommand(honeypot.HoneyPotCommand):
    k = None
	@staticmethod
	def init():
		HalCommand.k = aiml.Kernel()
		HalCommand.k.bootstrap(learnFiles=learnFiles, commands="load aiml b")
    
    def start(self):
        from random import randint
        token = "token_%s" % (0,10000)
        self.write("HAL: Am I playing a man or a machine?... This is a character that thinks rather than acts\n")
        self.write("You: ")
        self.callbacks = [ lambda line: self.respond(line, token) ]

    def respond(self,line,token)
        resp = "HAL: %s" % HalCommand.k.respond(line, sessionID=token)
        self.write(resp)
        self.callbacks.append(lambda line: self.respond(line, token))

    def lineReceived(self,line):
        self.callbacks.pop(0)(line)

HalCommand.init()
"""