diff --git a/sopel_modules/SpiceBot/DictComs.py b/sopel_modules/SpiceBot/DictComs.py index ea1a324..83b3b55 100644 --- a/sopel_modules/SpiceBot/DictComs.py +++ b/sopel_modules/SpiceBot/DictComs.py @@ -15,6 +15,7 @@ from .Commands import commands as botcommands import requests from fake_useragent import UserAgent import urllib +import os class SpiceBot_DictComs_MainSection(StaticSection): @@ -33,7 +34,16 @@ class BotDictCommands(): "feeds", "search" ] + self.prefix_com_load() + + def prefix_com_load(self): self.dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs") + for directory in self.dir_to_scan: + for valid_com_type in self.valid_com_types: + poss_path = os.path.join(directory, valid_com_type) + if os.path.exists(poss_path) and os.path.isdir(poss_path): + if len(os.listdir(poss_path)) > 0: + self.dir_to_scan.append(poss_path) self.valid_dictcom_dict = botread.json_to_dict(self.dir_to_scan, "Dictionary Commands", "SpiceBot_DictComs") @@ -75,7 +85,7 @@ class BotDictCommands(): # handle basic required dict handling dict_required = ["?default"] - dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, dict_required) + dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, dict_required) keysprocessed.extend(dict_required) # remove later @@ -87,12 +97,12 @@ class BotDictCommands(): if otherkey not in keysprocessed: otherkeys.append(otherkey) if otherkeys != []: - dict_from_file = self.bot_dict_use_cases(maincom, dict_from_file, otherkeys) + dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, otherkeys) keysprocessed.extend(otherkeys) botcommands.register(dict_from_file) - def bot_dict_use_cases(self, maincom, dict_from_file, process_list): + def prefix_com_load_subtypes(self, maincom, dict_from_file, process_list): for mustbe in process_list: diff --git a/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid.json b/sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/simple/bandaid.json similarity index 100% rename from sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/bandaid.json rename to sopel_modules/SpiceBot_Configs/SpiceBot_DictComs/simple/bandaid.json diff --git a/sopel_modules/SpiceBot_Core_Commands/DictComs.py b/sopel_modules/SpiceBot_Core_Commands/DictComs.py index 0cb2753..fe73704 100644 --- a/sopel_modules/SpiceBot_Core_Commands/DictComs.py +++ b/sopel_modules/SpiceBot_Core_Commands/DictComs.py @@ -4,6 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot DictCom system """ +import copy + # sopel imports import sopel.module @@ -21,4 +23,9 @@ def command_dictcom(bot, trigger): if "aliasfor" in list(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']].keys()): trigger.sb['com'] = SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]["aliasfor"] - bot.say(str(trigger.sb['com'])) + # simplify usage of the bot command going forward + # copy dict to not overwrite + trigger.sb['comdict'] = copy.deepcopy(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]) + + # execute function based on command type + trigger.sb['comtype'] = trigger.sb['comdict']["type"].lower()