From 6b305fdea0866126ee5c14ea70964b1f37a1299b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Sat, 1 Jun 2019 13:55:55 -0400 Subject: [PATCH] test --- sopel_modules/SpiceBot/AI.py | 43 ++++++++++---------- sopel_modules/SpiceBot_Core_Processing/AI.py | 6 +++ 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index e9908a1..06b9465 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -23,6 +23,7 @@ class SpiceBot_AI(): def __init__(self): self.load_commands = [0] + self.braindirs = [] self.dict = { "counts": 0, "failcounts": 0, @@ -57,27 +58,27 @@ class SpiceBot_AI(): def learn(self, braindirs): for braindir in braindirs: - dirnumber = max(self.load_commands) + 1 - # for parsefile in os.listdir(braindir): - # self.check_file_parse(parsefile) - tempbrain = tempfile.mkstemp()[1] - with open(tempbrain, 'w') as fileo: - fileo.write( - "" - " \n" - " \n" - " LOAD AIML {}\n" - " \n" - " \n" - "".format(str(dirnumber), os.path.join(braindir, "*")) - ) - self.aiml_kernel.learn(tempbrain) - for number in self.load_commands: - if number != 0: - self.aiml_kernel.respond("LOAD AIML {}").format(str(dirnumber)) - os.remove(tempbrain) + if braindir not in self.braindirs: + self.braindirs.append(braindir) + dirnumber = max(self.load_commands) + 1 + tempbrain = tempfile.mkstemp()[1] + with open(tempbrain, 'w') as fileo: + fileo.write( + "" + " \n" + " \n" + " LOAD AIML {}\n" + " \n" + " \n" + "".format(str(dirnumber), os.path.join(braindir, "*")) + ) + self.aiml_kernel.learn(tempbrain) + for number in self.load_commands: + if number != 0: + self.aiml_kernel.respond("LOAD AIML {}").format(str(dirnumber)) + os.remove(tempbrain) def on_message(self, bot, trigger, message): nick = Identifier(trigger.nick) diff --git a/sopel_modules/SpiceBot_Core_Processing/AI.py b/sopel_modules/SpiceBot_Core_Processing/AI.py index cb214b8..efa1843 100644 --- a/sopel_modules/SpiceBot_Core_Processing/AI.py +++ b/sopel_modules/SpiceBot_Core_Processing/AI.py @@ -5,6 +5,8 @@ This is the SpiceBot AI system. """ import sopel +import os + import sopel_modules.SpiceBot as SpiceBot @@ -12,6 +14,10 @@ import sopel_modules.SpiceBot as SpiceBot @sopel.module.rule('.*') def bot_events_complete_ai(bot, trigger): + for braindir in SpiceBot.botai.braindirs: + for parsefile in os.listdir(braindir): + SpiceBot.botai.check_file_parse(parsefile) + if SpiceBot.botai.dict["counts"]: SpiceBot.logs.log('SpiceBot_AI', 'Registered %d %s files,' % (SpiceBot.botai.dict["counts"], 'aiml')) SpiceBot.logs.log('SpiceBot_AI', '%d %s files failed to load' % (SpiceBot.botai.dict["failcounts"], 'aiml'), True)