Skip to content

Commit

Permalink
added some changes, added brain creation and recovery, session soupou…
Browse files Browse the repository at this point in the history
…rt, and some tweaks
  • Loading branch information
compermisos committed Jul 3, 2015
1 parent 72ea6ab commit ab74c75
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions bot-aiml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python2
# encoding=utf8
import os
import os.path
import sys
reload(sys)
sys.setdefaultencoding('utf8')
Expand All @@ -9,12 +10,25 @@
import time
from datetime import datetime
import pyAIML
import atexit


TOKEN = os.environ['TELEGRAM_TOKEN']
AIMLName = "comperBot"
BootName = "belinda"
BRAINNAME = "brain.sav"

k = pyAIML.Kernel()
k.learn(os.path.join(os.path.dirname(__file__), 'AIML/comperBot/') + "*.aiml")
k.setBotPredicate("bot_name", "Belinda")
if os.path.isfile(BRAINNAME):
k.loadBrain(BRAINNAME)
k.setTextEncoding("UTF-8")
k.learn(os.path.join(os.path.dirname(__file__), 'AIML/', AIMLName + "/") + "*.aiml")
k.loadSubs(os.path.join(os.path.dirname(__file__), 'AIML/', AIMLName + "/") + AIMLName+ ".ini")
k.setBotPredicate("bot_name", BootName)



atexit.register(lambda : k.saveBrain(BRAINNAME))

def listener(*messages):
f = open('chat.log', 'a')
Expand All @@ -27,7 +41,7 @@ def listener(*messages):
chatid = m.chat.id
if m.content_type == 'text':
text = m.text
response = k.respond(text)
response = k.respond(text, chatid)
tb.send_message(chatid, "Escribiste: " + text)
tb.send_message(chatid, response)
f.write(str(datetime.now()) + "\t Chat: " + str(chatid) + "\t Msg: " + text + "\t Respuesta: " + response + "\n")
Expand Down

0 comments on commit ab74c75

Please sign in to comment.