From 8e314f2aed8ea6ad5b9d8bafc79eab923ee672a7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 4 Jun 2019 12:40:32 -0400 Subject: [PATCH] onward --- sopel_modules/SpiceBot/Commands.py | 10 ++++++++++ sopel_modules/SpiceBot_AI/AI_aiml.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 75d5e33..df42c1f 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -22,6 +22,8 @@ class BotCommands(): self.lock = threading.Lock() self.dict = { "counts": 0, + 'nickrules': [], + 'nickaiml': [], "commands": { 'module': {}, 'nickname': {}, @@ -30,9 +32,17 @@ class BotCommands(): 'disabled': {} } self.module_files_parse() + self.nickrules() for comtype in ['module', 'nickname', 'rule']: logs.log('SpiceBot_Commands', "Found " + str(len(self.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True) + def nickrules(self): + for command in self.dict['commands']['rule'].keys(): + if command.startswith("$nickname"): + command = command.split("$nickname")[-1] + if command not in self.dict['nickrules']: + self.dict['nickrules'].append(command) + def find_command_type(self, command): for commandstype in self.dict['commands'].keys(): if commandstype not in ['rule']: diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 520682d..8726191 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -6,6 +6,8 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot +import spicemanip + @sopel.module.rule('(.*)') def bot_command_rule(bot, trigger): @@ -27,9 +29,25 @@ def bot_command_rule(bot, trigger): if str(message).lower().startswith(str(bot.nick).lower()): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'nickname') + if str(trigger_command).startswith("?"): + return + fulltrigger = spicemanip.main(trigger_args, 0) + if fulltrigger in SpiceBot.commands.dict['nickrules']: + return if trigger_command in SpiceBot.commands.dict['commands']["nickname"].keys(): return + else: + trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') returnmessage = SpiceBot.botai.on_message(bot, trigger, message) if returnmessage: bot.osd(str(returnmessage)) + else: + closestmatches = SpiceBot.similar_list(bot, trigger_command, SpiceBot.commands.dict['commands']["nickname"].keys(), 3, 'reverse') + if len(closestmatches): + closestmatches = spicemanip.main(closestmatches, "andlist") + bot.osd("I don't know what you are asking me to do! Did you mean: " + str(closestmatches) + "?") + return + else: + bot.osd("I don't know what you are asking me to do!") + return