From 823937ca8c1b7294d4b462000e343957b9a095df Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 9 Oct 2019 12:58:27 -0400 Subject: [PATCH 1/3] add threads --- sopel_modules/SpiceBot_Core_Processing/Channels.py | 5 +++++ sopel_modules/SpiceBot_Core_Processing/Events.py | 5 +++++ sopel_modules/SpiceBot_Core_Processing/Logs.py | 14 +++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Processing/Channels.py b/sopel_modules/SpiceBot_Core_Processing/Channels.py index c8f4dd6..23c08d3 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Channels.py +++ b/sopel_modules/SpiceBot_Core_Processing/Channels.py @@ -6,6 +6,7 @@ This is the SpiceBot Channels system. import sopel import time +from threading import Thread from sopel_modules.spicemanip import spicemanip @@ -68,6 +69,10 @@ def watch_chanlist_complete(bot, trigger): @sopel.module.event(SpiceBot.events.BOT_CHANNELS) @sopel.module.rule('.*') def trigger_channel_list_recurring(bot, trigger): + Thread(target=channels_thread, args=(bot,)).start() + + +def channels_thread(bot): while True: time.sleep(1800) SpiceBot.channels.bot_part_empty(bot) diff --git a/sopel_modules/SpiceBot_Core_Processing/Events.py b/sopel_modules/SpiceBot_Core_Processing/Events.py index be9abfc..166f172 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Events.py +++ b/sopel_modules/SpiceBot_Core_Processing/Events.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot Events system. """ import sopel +from threading import Thread import sopel_modules.SpiceBot as SpiceBot @@ -27,6 +28,10 @@ def bot_events_connected(bot, trigger): SpiceBot.events.trigger(bot, SpiceBot.events.BOT_WELCOME, "Welcome to the SpiceBot Events System") """For items tossed in a queue, this will trigger them accordingly""" + Thread(target=events_thread, args=(bot,)).start() + + +def events_thread(bot): while True: if len(SpiceBot.events.dict["trigger_queue"]): pretriggerdict = SpiceBot.events.dict["trigger_queue"][0] diff --git a/sopel_modules/SpiceBot_Core_Processing/Logs.py b/sopel_modules/SpiceBot_Core_Processing/Logs.py index 5ad773f..2a3cc0d 100644 --- a/sopel_modules/SpiceBot_Core_Processing/Logs.py +++ b/sopel_modules/SpiceBot_Core_Processing/Logs.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi This is the SpiceBot Logs system. """ import sopel +from threading import Thread import sopel_modules.SpiceBot as SpiceBot @@ -18,10 +19,13 @@ def join_log_channel(bot, trigger): bot.write(('JOIN', bot.nick, channel)) if channel not in list(bot.channels.keys()) and bot.config.SpiceBot_Channels.operadmin: bot.write(('SAJOIN', bot.nick, channel)) - - while True: - if len(SpiceBot.logs.dict["queue"]): - bot.osd(str(SpiceBot.logs.dict["queue"][0]), channel) - del SpiceBot.logs.dict["queue"][0] + Thread(target=logs_thread, args=(bot, channel,)).start() else: SpiceBot.logs.dict["queue"] = [] + + +def logs_thread(bot, channel): + while True: + if len(SpiceBot.logs.dict["queue"]): + bot.osd(str(SpiceBot.logs.dict["queue"][0]), channel) + del SpiceBot.logs.dict["queue"][0] From dee307199b7aac0c14f4a5b3b8fda24613b2f3c3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 25 Oct 2019 09:55:14 -0400 Subject: [PATCH 2/3] TODO reddit --- sopel_modules/SpiceBot_Core_Tools/Reddit.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sopel_modules/SpiceBot_Core_Tools/Reddit.py b/sopel_modules/SpiceBot_Core_Tools/Reddit.py index 9e91aec..af34fff 100644 --- a/sopel_modules/SpiceBot_Core_Tools/Reddit.py +++ b/sopel_modules/SpiceBot_Core_Tools/Reddit.py @@ -7,6 +7,9 @@ import sopel.module import sopel_modules.SpiceBot as SpiceBot +# @rule(r"^(r|u)\/([^\s/]+)") TODO + + @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @sopel.module.rule(r"""(?:)u/ ( From 0f6c881ecd7f764a59cf4f947106f43b16f24088 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Tue, 29 Oct 2019 09:29:11 -0400 Subject: [PATCH 3/3] fix --- sopel_modules/SpiceBot/Gif.py | 61 ++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/sopel_modules/SpiceBot/Gif.py b/sopel_modules/SpiceBot/Gif.py index ea9ff51..b432901 100644 --- a/sopel_modules/SpiceBot/Gif.py +++ b/sopel_modules/SpiceBot/Gif.py @@ -178,35 +178,38 @@ class BotGif(): page = e page = None if page and not str(page.status_code).startswith(tuple(["4", "5"])): - data = json.loads(urllib.request.urlopen(url).read().decode('utf-8')) - results = data[self.valid_api[currentapi]['results']] - resultsarray = [] - for result in results: - appendresult = False - cururl = result[self.valid_api[currentapi]['cururl']] - slashsplit = str(cururl).split("/") - fileextension = slashsplit[-1] - if not fileextension or fileextension == '': - appendresult = True - elif str(fileextension).endswith(".gif"): - appendresult = True - elif "." not in str(fileextension): - appendresult = True - if appendresult: - resultsarray.append(cururl) - # make sure there are results - if len(resultsarray): - # Create Temp dict for every result - tempresultnum = 0 - for tempresult in resultsarray: - if tempresult not in self.badlinks: - tempresultnum += 1 - tempdict = { - "returnnum": tempresultnum, - "returnurl": tempresult, - "gifapi": currentapi, - } - self.valid_api[currentapi]["cache"][str(searchquery).lower()].append(tempdict) + try: + data = json.loads(urllib.request.urlopen(url).read().decode('utf-8')) + results = data[self.valid_api[currentapi]['results']] + resultsarray = [] + for result in results: + appendresult = False + cururl = result[self.valid_api[currentapi]['cururl']] + slashsplit = str(cururl).split("/") + fileextension = slashsplit[-1] + if not fileextension or fileextension == '': + appendresult = True + elif str(fileextension).endswith(".gif"): + appendresult = True + elif "." not in str(fileextension): + appendresult = True + if appendresult: + resultsarray.append(cururl) + # make sure there are results + if len(resultsarray): + # Create Temp dict for every result + tempresultnum = 0 + for tempresult in resultsarray: + if tempresult not in self.badlinks: + tempresultnum += 1 + tempdict = { + "returnnum": tempresultnum, + "returnurl": tempresult, + "gifapi": currentapi, + } + self.valid_api[currentapi]["cache"][str(searchquery).lower()].append(tempdict) + except urllib.error.HTTPError: + return def gif_url_assemble(self, currentapi, searchquery, searchlimit, searchnsfw): # url base