mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
commit
94f595521d
@ -36,7 +36,7 @@ class BotGif():
|
||||
|
||||
self.dir_to_scan = botread.get_config_dirs("SpiceBot_Gif")
|
||||
|
||||
valid_gif_api_dict = botread.json_to_dict(self.dir_to_scan, "Gif API", "SpiceBot_Gif")
|
||||
valid_gif_api_dict = botread.json_to_dict_simple(self.dir_to_scan, "Gif API", "SpiceBot_Gif")
|
||||
|
||||
"""
|
||||
15:02 <+Exirel> `channel_section = getattr(bot.config, 'channel', None)`
|
||||
|
||||
@ -142,6 +142,63 @@ class BotRead():
|
||||
|
||||
return configs_dict
|
||||
|
||||
def json_to_dict_simple(self, directories, configtypename="Config File", log_from='read_directory_json_to_dict', logging=True):
|
||||
|
||||
if not isinstance(directories, list):
|
||||
directories = [directories]
|
||||
|
||||
configs_dict = {}
|
||||
filesprocess, fileopenfail, filecount = [], 0, 0
|
||||
for directory in directories:
|
||||
if os.path.exists(directory) and os.path.isdir(directory):
|
||||
if len(os.listdir(directory)) > 0:
|
||||
for file in os.listdir(directory):
|
||||
filepath = os.path.join(directory, file)
|
||||
if os.path.isfile(filepath) and filepath.endswith('.json'):
|
||||
filesprocess.append(filepath)
|
||||
|
||||
for filepath in filesprocess:
|
||||
|
||||
# Read dictionary from file, if not, enable an empty dict
|
||||
filereadgood = True
|
||||
try:
|
||||
inf = codecs.open(filepath, "r", encoding='utf-8')
|
||||
infread = inf.read()
|
||||
# Close File
|
||||
inf.close()
|
||||
dict_from_file = eval(infread)
|
||||
except Exception as e:
|
||||
filereadgood = False
|
||||
if logging:
|
||||
logs.log(log_from, "Error loading %s: %s (%s)" % (configtypename, e, filepath))
|
||||
dict_from_file = dict()
|
||||
|
||||
# gather file stats
|
||||
slashsplit = str(filepath).split("/")
|
||||
filename = slashsplit[-1]
|
||||
filename_base = os.path.basename(filename).rsplit('.', 1)[0]
|
||||
|
||||
if not filereadgood or not isinstance(dict_from_file, dict):
|
||||
fileopenfail += 1
|
||||
else:
|
||||
filecount += 1
|
||||
dict_from_file["filepath"] = str(filepath)
|
||||
dict_from_file["filename"] = str(filename_base)
|
||||
dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0]
|
||||
dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1]
|
||||
# dict_from_file = self.command_defaults(dict_from_file)
|
||||
configs_dict[filename_base] = dict_from_file
|
||||
|
||||
if filecount:
|
||||
if logging:
|
||||
logs.log(log_from, 'Registered %d %s dict files,' % (filecount, configtypename))
|
||||
logs.log(log_from, '%d %s dict files failed to load' % (fileopenfail, configtypename), True)
|
||||
else:
|
||||
if logging:
|
||||
logs.log(log_from, "Warning: Couldn't load any %s dict files" % (configtypename))
|
||||
|
||||
return configs_dict
|
||||
|
||||
def module_json_to_dict(self, filepath, logging=True):
|
||||
|
||||
# gather file stats
|
||||
|
||||
@ -25,7 +25,7 @@ class Sherlock():
|
||||
|
||||
dir_to_scan = botread.get_config_dirs("SpiceBot_Sherlock")
|
||||
|
||||
valid_usernames_dict = botread.json_to_dict(dir_to_scan, "Sherlock", "SpiceBot_Sherlock")
|
||||
valid_usernames_dict = botread.json_to_dict_simple(dir_to_scan, "Sherlock", "SpiceBot_Sherlock")
|
||||
|
||||
for social_network in list(valid_usernames_dict.keys()):
|
||||
self.dict[social_network] = valid_usernames_dict[social_network]
|
||||
|
||||
@ -25,7 +25,7 @@ def bot_command_sherlock(bot, trigger, botcom):
|
||||
checklist = [checklistname]
|
||||
username = spicemanip(botcom.dict["args"], 1) or trigger.nick
|
||||
|
||||
bot.osd("Checking username " + username + " in " + checklistname + " network.")
|
||||
bot.osd(["Checking username " + username + " in " + checklistname + " network.", "This takes time, please be patient."])
|
||||
|
||||
inlist, notinlist = [], []
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user