From 89f06a88efe80a5cefc56d74aeeb972a7187b19b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 07:55:30 -0400 Subject: [PATCH 1/8] debug gif begins --- sopel_modules/SpiceBot/Gif.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index db12f03..5df37dc 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -7,6 +7,7 @@ from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute from .Config import config as botconfig from .Read import read as botread from .Commands import commands as botcommands +from .Logs import logs from sopel_modules.spicemanip import spicemanip @@ -91,6 +92,7 @@ class BotGif(): # Replace spaces in search query searchdict["searchquery"] = urllib.request.pathname2url(searchdict["query"]) + logs.log('SpiceBot_Gif', searchdict["searchquery"], True) # set api usage if not isinstance(searchdict['gifsearch'], list): From 0f9e46c47a4f17e3345bbad312d653389da0d48b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 08:11:09 -0400 Subject: [PATCH 2/8] test --- sopel_modules/SpiceBot/Gif.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 5df37dc..9a90f6a 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -92,7 +92,6 @@ class BotGif(): # Replace spaces in search query searchdict["searchquery"] = urllib.request.pathname2url(searchdict["query"]) - logs.log('SpiceBot_Gif', searchdict["searchquery"], True) # set api usage if not isinstance(searchdict['gifsearch'], list): @@ -131,6 +130,8 @@ class BotGif(): verifygoodlinks.append(gifresult) self.valid_api[currentapi]["cache"][str(searchdict["searchquery"])] = verifygoodlinks + logs.log('SpiceBot_Gif', str(searchfor), True) + if searchfor: self.valid_api[currentapi]["cache"][str(searchdict["searchquery"]).lower()] = [] # assemble url From 3acbf7c6fcb5ddfed40614f6ebbda9c969997e8d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 08:13:10 -0400 Subject: [PATCH 3/8] test --- sopel_modules/SpiceBot/Gif.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 9a90f6a..e02afb8 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -130,12 +130,11 @@ class BotGif(): verifygoodlinks.append(gifresult) self.valid_api[currentapi]["cache"][str(searchdict["searchquery"])] = verifygoodlinks - logs.log('SpiceBot_Gif', str(searchfor), True) - if searchfor: self.valid_api[currentapi]["cache"][str(searchdict["searchquery"]).lower()] = [] # assemble url url = self.gif_url_assemble(currentapi, str(searchdict["searchquery"]), str(searchdict["searchlimit"]), searchdict['nsfw']) + logs.log('SpiceBot_Gif', str(url), True) # fetch results self.fetch_gif_results(currentapi, str(searchdict["searchquery"]), url) From 7809a7f4482440e5767a28e3d49de08205324fc3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 08:17:20 -0400 Subject: [PATCH 4/8] test --- sopel_modules/SpiceBot/Gif.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index e02afb8..1cbcd82 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -58,6 +58,7 @@ class BotGif(): self.valid_api[gif_api]["comtype"] = "gif_prefix" self.valid_api[gif_api]["validcoms"] = [self.valid_api[gif_api]["filename"]] + logs.log('SpiceBot_Gif', str(self.valid_api[gif_api]), True) botcommands.register(self.valid_api[gif_api]) def setup_gif(self): @@ -134,7 +135,6 @@ class BotGif(): self.valid_api[currentapi]["cache"][str(searchdict["searchquery"]).lower()] = [] # assemble url url = self.gif_url_assemble(currentapi, str(searchdict["searchquery"]), str(searchdict["searchlimit"]), searchdict['nsfw']) - logs.log('SpiceBot_Gif', str(url), True) # fetch results self.fetch_gif_results(currentapi, str(searchdict["searchquery"]), url) From 26200d81ced3801de5d4c2e0efa849ddb87c1159 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 08:20:09 -0400 Subject: [PATCH 5/8] test --- sopel_modules/SpiceBot/Gif.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 1cbcd82..8c62d4e 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -38,6 +38,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") + logs.log('SpiceBot_Gif', str(valid_gif_api_dict), True) """ 15:02 <+Exirel> `channel_section = getattr(bot.config, 'channel', None)` @@ -58,7 +59,6 @@ class BotGif(): self.valid_api[gif_api]["comtype"] = "gif_prefix" self.valid_api[gif_api]["validcoms"] = [self.valid_api[gif_api]["filename"]] - logs.log('SpiceBot_Gif', str(self.valid_api[gif_api]), True) botcommands.register(self.valid_api[gif_api]) def setup_gif(self): From 847e6df5e861d1fb6d95a8c120e19f1d8498674b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 08:30:44 -0400 Subject: [PATCH 6/8] test --- sopel_modules/SpiceBot/Gif.py | 2 +- sopel_modules/SpiceBot/Read.py | 57 ++++++++++++++++++++++++++++++ sopel_modules/SpiceBot/Sherlock.py | 2 +- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 8c62d4e..1900288 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -37,7 +37,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") logs.log('SpiceBot_Gif', str(valid_gif_api_dict), True) """ diff --git a/sopel_modules/SpiceBot/Read.py b/sopel_modules/SpiceBot/Read.py index e717f53..8014766 100644 --- a/sopel_modules/SpiceBot/Read.py +++ b/sopel_modules/SpiceBot/Read.py @@ -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 diff --git a/sopel_modules/SpiceBot/Sherlock.py b/sopel_modules/SpiceBot/Sherlock.py index f525b13..3c89bff 100644 --- a/sopel_modules/SpiceBot/Sherlock.py +++ b/sopel_modules/SpiceBot/Sherlock.py @@ -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] From 6e81d969882f9d97f40027e73fdae9a7d88e0a64 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 08:34:00 -0400 Subject: [PATCH 7/8] gif and sherlock should now work --- sopel_modules/SpiceBot/Gif.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index 1900288..2a725b9 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -7,7 +7,6 @@ from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute from .Config import config as botconfig from .Read import read as botread from .Commands import commands as botcommands -from .Logs import logs from sopel_modules.spicemanip import spicemanip @@ -38,7 +37,6 @@ class BotGif(): self.dir_to_scan = botread.get_config_dirs("SpiceBot_Gif") valid_gif_api_dict = botread.json_to_dict_simple(self.dir_to_scan, "Gif API", "SpiceBot_Gif") - logs.log('SpiceBot_Gif', str(valid_gif_api_dict), True) """ 15:02 <+Exirel> `channel_section = getattr(bot.config, 'channel', None)` From 1366ff6d7f17ab25e7f9321fcde03b071f8784ca Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 20 Sep 2019 08:35:17 -0400 Subject: [PATCH 8/8] update text --- sopel_modules/SpiceBot_Core_Tools/Sherlock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_Core_Tools/Sherlock.py b/sopel_modules/SpiceBot_Core_Tools/Sherlock.py index 74a7791..40c94f4 100644 --- a/sopel_modules/SpiceBot_Core_Tools/Sherlock.py +++ b/sopel_modules/SpiceBot_Core_Tools/Sherlock.py @@ -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 = [], []