From 0362e13d7c0ce6f8d6ccaab56b3cd9cf1b7721d1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 18 Jul 2019 08:30:21 -0400 Subject: [PATCH 1/8] update prerun for action_commands --- sopel_modules/SpiceBot/Prerun.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index cc952e2..2e8ca5a 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -53,7 +53,7 @@ def prerun(t_command_type='module', t_command_subtype=None): # Primary command used for trigger, and a list of all words trigger_args, trigger_command, trigger_prefix = make_trigger_args(trigger.args[1], trigger_command_type) - if trigger_prefix in [botconfig.SpiceBot_Commands.query_prefix]: + if trigger_prefix and trigger_prefix in [botconfig.SpiceBot_Commands.query_prefix]: return trigger_command_type = botcommands.find_command_type(trigger_command) @@ -68,6 +68,7 @@ def prerun(t_command_type='module', t_command_subtype=None): argsdict_default = {} argsdict_default["type"] = trigger_command_type argsdict_default["com"] = trigger_command + argsdict_default["trigger_prefix"] = trigger_prefix # messagelog ID argsdict_default["log_id"] = botmessagelog.messagelog_assign() @@ -144,7 +145,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None): # Primary command used for trigger, and a list of all words trigger_args, trigger_command, trigger_prefix = make_trigger_args(trigger.args[1], trigger_command_type) - if trigger_prefix != botconfig.SpiceBot_Commands.query_prefix: + if trigger_prefix and trigger_prefix not in [botconfig.SpiceBot_Commands.query_prefix]: return # Argsdict Defaults @@ -209,11 +210,15 @@ def verify_channel(trigger): def make_trigger_args(triggerargs_one, trigger_command_type='module'): trigger_args = spicemanip(triggerargs_one, 'create') if trigger_command_type in ['nickname']: - trigger_prefix = spicemanip(trigger_args, 2).lower()[0] + trigger_prefix = None if trigger_prefix.isupper() or trigger_prefix.islower(): trigger_prefix = None trigger_command = spicemanip(trigger_args, 2).lower() trigger_args = spicemanip(trigger_args, '3+', 'list') + elif trigger_command_type in ['action']: + trigger_prefix = None + trigger_command = spicemanip(trigger_args, 1).lower() + trigger_args = spicemanip(trigger_args, '2+', 'list') else: trigger_prefix = spicemanip(trigger_args, 1).lower()[0] trigger_command = spicemanip(trigger_args, 1).lower()[1:] From cecd23556b17a2f71325b61eb2fb8f19dd7e44aa Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 18 Jul 2019 08:32:25 -0400 Subject: [PATCH 2/8] more tweaks --- sopel_modules/SpiceBot/Prerun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 2e8ca5a..ab7b6c9 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -44,7 +44,7 @@ def prerun(t_command_type='module', t_command_subtype=None): check_nick = spicemanip(trigger.args[1], 1).lower() if check_nick != str(bot.nick).lower(): return - else: + elif t_command_type == "module": if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)): return @@ -133,7 +133,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None): check_nick = spicemanip(trigger.args[1], 1).lower() if check_nick != str(bot.nick).lower(): return - else: + elif t_command_type == "module": if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)): return From 16aa203676e37cba5b42d12121e5ad81009eaf9e Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 19 Jul 2019 14:50:05 -0400 Subject: [PATCH 3/8] test new commands finding --- sopel_modules/SpiceBot/Commands.py | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index 6f124e2..fa4e89a 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -12,6 +12,7 @@ from sopel.config.types import StaticSection, ValidatedAttribute import os import threading import copy +import imp from sopel_modules.spicemanip import spicemanip import sopel_modules @@ -368,5 +369,65 @@ class BotCommands(): self.register(validcomdict) + def list_plugin_filenames(self, directory): + return_list = [] + base = os.path.abspath(directory) + for filename in os.listdir(base): + abspath = os.path.join(base, filename) + + if os.path.isdir(abspath): + returndict = {"type": "folder"} + if os.path.isfile(os.path.join(abspath, '__init__.py')): + returndict["name"] = filename + returndict["abspath"] = abspath + module_files = [] + for subfilename in os.listdir(abspath): + name, ext = os.path.splitext(subfilename) + if ext == '.py' and name != '__init__': + subabspath = os.path.join(abspath, subfilename) + if os.path.isfile(os.path.join(subabspath, name + '.json')): + dictfile = os.path.join(subabspath, name + '.json') + else: + dictfile = False + module_files.append({"name": name, "abspath": subabspath, "dictfile": dictfile}) + returndict["module_files"] = module_files + return_list.append(returndict) + else: + returndict = {"type": "file"} + name, ext = os.path.splitext(filename) + if ext == '.py' and name != '__init__': + returndict["name"] = name + returndict["abspath"] = abspath + if os.path.isfile(os.path.join(abspath, name + '.json')): + dictfile = os.path.join(abspath, name + '.json') + else: + dictfile = False + returndict["dictfile"] = dictfile + return_list.append(returndict) + return return_list + + def list_plugin_dir(self): + plugin_dir = imp.find_module('modules', [imp.find_module('sopel')[1]])[1] + return self.list_plugin_filenames(plugin_dir) + + def list_sopel_modules_dir(self): + try: + import sopel_modules + except ImportError: + return [] + sopel_modules_list = [] + for plugin_dir in set(sopel_modules.__path__): + small_list = self.list_plugin_filenames(plugin_dir) + sopel_modules_list.extend(small_list) + return sopel_modules_list + + def get_plugin_list(self): + full_list = [] + for x in ["plugin", "sopel_modules"]: + return_list = eval("self.list_" + str(x) + "_dir()") + full_list.extend(return_list) + return full_list + + commands = BotCommands() From 4e48b3f4e25b1d97761d73758d62ca08efd6e991 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 19 Jul 2019 15:14:38 -0400 Subject: [PATCH 4/8] test --- sopel_modules/SpiceBot/Commands.py | 33 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index fa4e89a..140fd7d 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -369,7 +369,7 @@ class BotCommands(): self.register(validcomdict) - def list_plugin_filenames(self, directory): + def list_plugin_filenames(self, directory, plugin_type='file'): return_list = [] base = os.path.abspath(directory) for filename in os.listdir(base): @@ -378,8 +378,12 @@ class BotCommands(): if os.path.isdir(abspath): returndict = {"type": "folder"} if os.path.isfile(os.path.join(abspath, '__init__.py')): - returndict["name"] = filename + returndict["name"] = os.path.basename(filename) returndict["abspath"] = abspath + if plugin_type == 'file': + returndict["handler"] = sopel.plugins.handlers.PyFilePlugin(abspath) + else: + returndict["handler"] = sopel.plugins.handlers.PyModulePlugin(os.path.basename(filename), plugin_type) module_files = [] for subfilename in os.listdir(abspath): name, ext = os.path.splitext(subfilename) @@ -398,6 +402,10 @@ class BotCommands(): if ext == '.py' and name != '__init__': returndict["name"] = name returndict["abspath"] = abspath + if plugin_type == 'file': + returndict["handler"] = sopel.plugins.handlers.PyFilePlugin(abspath) + else: + returndict["handler"] = sopel.plugins.handlers.PyModulePlugin(name, plugin_type) if os.path.isfile(os.path.join(abspath, name + '.json')): dictfile = os.path.join(abspath, name + '.json') else: @@ -408,7 +416,7 @@ class BotCommands(): def list_plugin_dir(self): plugin_dir = imp.find_module('modules', [imp.find_module('sopel')[1]])[1] - return self.list_plugin_filenames(plugin_dir) + return self.list_plugin_filenames(plugin_dir, 'sopel.modules') def list_sopel_modules_dir(self): try: @@ -417,17 +425,30 @@ class BotCommands(): return [] sopel_modules_list = [] for plugin_dir in set(sopel_modules.__path__): - small_list = self.list_plugin_filenames(plugin_dir) + small_list = self.list_plugin_filenames(plugin_dir, 'sopel_modules') sopel_modules_list.extend(small_list) return sopel_modules_list + def list_homedir_dir(self): + plugin_dir = os.path.join(botconfig.config.homedir, 'modules') + return self.list_plugin_filenames(plugin_dir) + + def list_extra_dir(self): + sopel_modules_list = [] + if botconfig.config.core.extra: + plugin_dirs = list(botconfig.config.core.extra) + for plugin_dir in plugin_dirs: + if os.path.isdir(plugin_dir): + small_list = self.list_plugin_filenames(plugin_dir) + sopel_modules_list.extend(small_list) + return sopel_modules_list + def get_plugin_list(self): full_list = [] - for x in ["plugin", "sopel_modules"]: + for x in ["plugin", "sopel_modules", "homedir", "extra"]: return_list = eval("self.list_" + str(x) + "_dir()") full_list.extend(return_list) return full_list - commands = BotCommands() From 079dc460fa8782e9c4b1f1d0a462636e41baf9b1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 19 Jul 2019 15:14:43 -0400 Subject: [PATCH 5/8] meh --- sopel_modules/SpiceBot/DictComs.py | 5 +++++ sopel_modules/SpiceBot/Prerun.py | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index 6573562..266456c 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -295,5 +295,10 @@ class BotDictCommands(): def setup_dictcoms(self): botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False) + def process(bot, trigger, botcom): + + # use the default key, unless otherwise specified + botcom.dict["responsekey"] = "?default" + dictcoms = BotDictCommands() diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index ab7b6c9..8fba087 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -102,7 +102,12 @@ def prerun(t_command_type='module', t_command_subtype=None): botcom.dict["runcount"] = runcount botcom.dict["args"], botcom.dict["hyphen_arg"] = trigger_hyphen_args(botcom.dict["args"]) + + # special handling + botcom.dict["responsekey"] = "?default" + args_pass = trigger_hyphen_arg_handler(bot, trigger, botcom) + if args_pass: if trigger_runstatus(bot, trigger, botcom): function(bot, trigger, botcom, *args, **kwargs) @@ -267,7 +272,7 @@ def trigger_argsdict_single(argsdict_default, trigger_args_part): def trigger_runstatus_query(bot, trigger, botcom): # Bots can't run commands - if Identifier(trigger.nick) == bot.nick: + if trigger.nick == bot.nick: return False # Allow permissions for enabling and disabling commands via hyphenargs @@ -334,7 +339,8 @@ def trigger_runstatus(bot, trigger, botcom): if not trigger.is_privmsg: if str(trigger.sender).lower() in [x.lower() for x in botcom.dict["dict"]["hardcoded_channel_block"]]: - botmessagelog.messagelog_error(botcom.dict["log_id"], "The " + str(botcom.dict["comtext"]) + " command cannot be used in " + str(trigger.sender) + " because it is hardcoded not to.") + message = "The " + str(botcom.dict["comtext"]) + " command cannot be used in " + str(trigger.sender) + " because it is hardcoded not to." + return trigger_cant_run(bot, trigger, botcom, message) if botcom.dict["runcount"] > 1: # check channel multirun blocks @@ -407,11 +413,13 @@ def trigger_hyphen_args(trigger_args_part): 'foldername', 'folderpath', "author", 'contribs', 'contrib', "contributors", - 'alias', 'aliases' + 'alias', 'aliases', + 'random' ] numdict = { "last": -1 } + hyphen_args = [] trigger_args_unhyphend = [] for worditem in trigger_args_part: From af6bfa92544878c912b231da63db97577ca44d95 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 30 Jul 2019 15:04:06 -0400 Subject: [PATCH 6/8] just a comment for later --- sopel_modules/SpiceBot/Gif.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index d6f6d8b..db12f03 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -38,6 +38,12 @@ class BotGif(): valid_gif_api_dict = botread.json_to_dict(self.dir_to_scan, "Gif API", "SpiceBot_Gif") + """ + 15:02 <+Exirel> `channel_section = getattr(bot.config, 'channel', None)` + 15:02 I'm listening though + 15:02 <+Exirel> `value_of_the_option_specchan = channel_section.specchan` + """ + for gif_api in list(valid_gif_api_dict.keys()): botconfig.define_section(gif_api, GifAPISection, validate=False) From fd2492b8593a3d2126c1cc5b4c6939b495d4b6e2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 17 Sep 2019 12:12:26 -0400 Subject: [PATCH 7/8] None can't be upper or lower --- sopel_modules/SpiceBot/Prerun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Prerun.py b/sopel_modules/SpiceBot/Prerun.py index 8fba087..51521e4 100644 --- a/sopel_modules/SpiceBot/Prerun.py +++ b/sopel_modules/SpiceBot/Prerun.py @@ -216,8 +216,8 @@ def make_trigger_args(triggerargs_one, trigger_command_type='module'): trigger_args = spicemanip(triggerargs_one, 'create') if trigger_command_type in ['nickname']: trigger_prefix = None - if trigger_prefix.isupper() or trigger_prefix.islower(): - trigger_prefix = None + # if trigger_prefix.isupper() or trigger_prefix.islower(): + # trigger_prefix = None trigger_command = spicemanip(trigger_args, 2).lower() trigger_args = spicemanip(trigger_args, '3+', 'list') elif trigger_command_type in ['action']: From 76afbc89eab970ff62666626220f6591e77dae64 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 17 Sep 2019 13:00:48 -0400 Subject: [PATCH 8/8] remove --- sopel_modules/SpiceBot_Core_Commands/AI.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Commands/AI.py b/sopel_modules/SpiceBot_Core_Commands/AI.py index 4a01b13..a3a14f3 100644 --- a/sopel_modules/SpiceBot_Core_Commands/AI.py +++ b/sopel_modules/SpiceBot_Core_Commands/AI.py @@ -106,11 +106,11 @@ def bot_command_rule_ai(bot, trigger): if trigger_command not in commands_list: if not SpiceBot.letters_in_string(trigger_command): return - invalid_display = ["I don't seem to have a command for " + str(trigger_command) + "!"] + # invalid_display = ["I don't seem to have a command for " + str(trigger_command) + "!"] # TODO # invalid_display.append("If you have a suggestion for this command, you can run .feature ." + str(trigger_command)) # invalid_display.append("ADD DESCRIPTION HERE!") - bot.osd(invalid_display, trigger.nick, 'notice') + # bot.osd(invalid_display, trigger.nick, 'notice') return elif command_type == 'nickname':