add subdirectories for dictcom

This commit is contained in:
deathbybandaid 2019-06-21 08:19:19 -04:00
parent 60383c11c8
commit 871fd454e2
3 changed files with 21 additions and 4 deletions

View File

@ -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:

View File

@ -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()