From 00ef7f96079d2e23adecc0e8d434db2a6b79d2c0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 15:51:03 -0400 Subject: [PATCH] test --- sopel_modules/SpiceBot/AI.py | 4 +-- sopel_modules/SpiceBot/setup.py | 4 ++- sopel_modules/SpiceBot_Core_Processing/AI | 25 ------------------- sopel_modules/SpiceBot_Core_Processing/AI.py | 17 +++++++++++++ .../StartupMonologue.py | 11 ++++++++ 5 files changed, 33 insertions(+), 28 deletions(-) delete mode 100644 sopel_modules/SpiceBot_Core_Processing/AI create mode 100644 sopel_modules/SpiceBot_Core_Processing/AI.py diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index 2ac2cc2..daee7c5 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -26,7 +26,7 @@ class SpiceBot_AI(): self.setup_ai() self.braindirs = [] self.dict = { - "patterncount": 0, + "patterncounts": 0, "filecounts": 0, "sessioncache": {}, "files": {} @@ -102,7 +102,7 @@ class SpiceBot_AI(): data = open(aimlfile).read() count = data.count('pattern') count = count / 2 - self.dict["patterncount"] += count + self.dict["patterncounts"] += count tempbrain = tempfile.mkstemp()[1] with open(tempbrain, 'w') as fileo: diff --git a/sopel_modules/SpiceBot/setup.py b/sopel_modules/SpiceBot/setup.py index b27655d..f830ee1 100644 --- a/sopel_modules/SpiceBot/setup.py +++ b/sopel_modules/SpiceBot/setup.py @@ -80,7 +80,8 @@ def setup_startupmonologue(bot): events.startup_add([ events.BOT_STARTUPMONOLOGUE_CONNECTED, events.BOT_STARTUPMONOLOGUE_CHANNELS, - events.BOT_STARTUPMONOLOGUE_COMMANDS + events.BOT_STARTUPMONOLOGUE_COMMANDS, + events.BOT_STARTUPMONOLOGUE_AI, ]) @@ -100,6 +101,7 @@ def setup_ai(bot): logs.log('SpiceBot_AI', "Setting Up Configuration") bot.config.define_section("SpiceBot_AI", SpiceBot_AI_MainSection, validate=False) bot.config.aibrain = os.path.join(bot.config.homedir, bot.config.core.basename + '.aibrain.brn') + events.startup_add([events.BOT_AI]) def setup_osd(bot): diff --git a/sopel_modules/SpiceBot_Core_Processing/AI b/sopel_modules/SpiceBot_Core_Processing/AI deleted file mode 100644 index efa1843..0000000 --- a/sopel_modules/SpiceBot_Core_Processing/AI +++ /dev/null @@ -1,25 +0,0 @@ -# coding=utf8 -from __future__ import unicode_literals, absolute_import, division, print_function -""" -This is the SpiceBot AI system. -""" -import sopel - -import os - -import sopel_modules.SpiceBot as SpiceBot - - -@sopel.module.event(SpiceBot.events.BOT_READY) -@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) - else: - SpiceBot.logs.log('SpiceBot_AI', "Warning: Couldn't load any %s files" % ('aiml')) diff --git a/sopel_modules/SpiceBot_Core_Processing/AI.py b/sopel_modules/SpiceBot_Core_Processing/AI.py new file mode 100644 index 0000000..3f65a2f --- /dev/null +++ b/sopel_modules/SpiceBot_Core_Processing/AI.py @@ -0,0 +1,17 @@ +# coding=utf8 +from __future__ import unicode_literals, absolute_import, division, print_function +""" +This is the SpiceBot AI system. +""" +import sopel + +import sopel_modules.SpiceBot as SpiceBot + + +@sopel.module.event(SpiceBot.events.BOT_READY) +@sopel.module.rule('.*') +def bot_events_complete_ai(bot, trigger): + + SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(SpiceBot.botai.dict['patterncounts']) + " AI pattern Matches.", True) + + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_AI, "SpiceBot_AI") diff --git a/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py b/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py index 9f2945d..7c5215c 100644 --- a/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py +++ b/sopel_modules/SpiceBot_Core_Processing/StartupMonologue.py @@ -43,6 +43,17 @@ def bot_startup_monologue_commands(bot, trigger): SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_COMMANDS, "SpiceBot_StartupMonologue") +@sopel.module.event(SpiceBot.events.BOT_AI) +@sopel.module.rule('.*') +def bot_startup_monologue_ai(bot, trigger): + availablecomsnum = SpiceBot.botai.dict['patterncounts'] + availablecomsfiles = SpiceBot.botai.dict['filecounts'] + displayval = "There are " + str(availablecomsnum) + " AI matches available in " + str(availablecomsfiles) + " files." + SpiceBot.startupmonologue.dict["ai"] = displayval + SpiceBot.logs.log('SpiceBot_StartupMonologue', displayval) + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_STARTUPMONOLOGUE_AI, "SpiceBot_StartupMonologue") + + @sopel.module.event(SpiceBot.events.BOT_LOADED) @sopel.module.rule('.*') def bot_startup_monologue_display(bot, trigger):