This commit is contained in:
deathbybandaid 2019-05-31 21:00:43 -04:00
parent 0323092df4
commit 1dee4b13d2
3 changed files with 16 additions and 23 deletions

View File

@ -5,6 +5,7 @@ This is the SpiceBot AI system. Based On Chatty cathy
"""
import os
import tempfile
import aiml
@ -16,15 +17,29 @@ class SpiceBot_AI():
}
# Load AIML kernel
self.aiml_kernel = aiml.Kernel()
# self.aiml_kernel._verboseMode = False
# Learn responses
import sopel_modules
for plugin_dir in set(sopel_modules.__path__):
configsdir = os.path.join(plugin_dir, "SpiceBot_Configs")
aimldir = os.path.join(configsdir, "aiml")
aimlstarter = os.path.join(aimldir, "std-startup.xml")
aimlstarter = tempfile.mkstemp()[1]
with open(aimlstarter, 'w') as fileo:
fileo.write(
"<aiml version='1.0.1' encoding='UTF-8'>"
" <!-- std-startup.xml -->\n"
" <category>\n"
" <pattern>LOAD AIML B</pattern>\n"
" <template>\n"
" <learn>{}</learn>\n"
" </template>\n"
" </category>\n"
"</aiml>".format(os.path.join(aimldir, "*"))
)
self.aiml_kernel.learn(aimlstarter)
self.aiml_kernel.respond("LOAD AIML B")
os.remove(aimlstarter)
def on_message(self, message):
aiml_response = self.aiml_kernel.respond(message)

View File

@ -1,22 +0,0 @@
<aiml version="1.0.1" encoding="UTF-8">
<!-- std-startup.xml -->
<!-- Category is an atomic AIML unit -->
<category>
<!-- Pattern to match in user input -->
<!-- If user enters "LOAD AIML B" -->
<pattern>LOAD AIML B</pattern>
<!-- Template is the response to the pattern -->
<!-- This learn an aiml file -->
<template>
<learn>./aiml/*</learn>
<!-- All aiml files are relative to the run dir and must be subdirs,
E.g. ./aiml/alice/one.aiml, ./aiml/custom/mine.aiml -->
</template>
</category>
</aiml>