Merge pull request #144 from SpiceBot/development

Development
This commit is contained in:
Deathbybandaid 2019-10-29 11:36:15 -04:00 committed by GitHub
commit 41e230fd58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 34 deletions

View File

@ -178,35 +178,38 @@ class BotGif():
page = e page = e
page = None page = None
if page and not str(page.status_code).startswith(tuple(["4", "5"])): if page and not str(page.status_code).startswith(tuple(["4", "5"])):
data = json.loads(urllib.request.urlopen(url).read().decode('utf-8')) try:
results = data[self.valid_api[currentapi]['results']] data = json.loads(urllib.request.urlopen(url).read().decode('utf-8'))
resultsarray = [] results = data[self.valid_api[currentapi]['results']]
for result in results: resultsarray = []
appendresult = False for result in results:
cururl = result[self.valid_api[currentapi]['cururl']] appendresult = False
slashsplit = str(cururl).split("/") cururl = result[self.valid_api[currentapi]['cururl']]
fileextension = slashsplit[-1] slashsplit = str(cururl).split("/")
if not fileextension or fileextension == '': fileextension = slashsplit[-1]
appendresult = True if not fileextension or fileextension == '':
elif str(fileextension).endswith(".gif"): appendresult = True
appendresult = True elif str(fileextension).endswith(".gif"):
elif "." not in str(fileextension): appendresult = True
appendresult = True elif "." not in str(fileextension):
if appendresult: appendresult = True
resultsarray.append(cururl) if appendresult:
# make sure there are results resultsarray.append(cururl)
if len(resultsarray): # make sure there are results
# Create Temp dict for every result if len(resultsarray):
tempresultnum = 0 # Create Temp dict for every result
for tempresult in resultsarray: tempresultnum = 0
if tempresult not in self.badlinks: for tempresult in resultsarray:
tempresultnum += 1 if tempresult not in self.badlinks:
tempdict = { tempresultnum += 1
"returnnum": tempresultnum, tempdict = {
"returnurl": tempresult, "returnnum": tempresultnum,
"gifapi": currentapi, "returnurl": tempresult,
} "gifapi": currentapi,
self.valid_api[currentapi]["cache"][str(searchquery).lower()].append(tempdict) }
self.valid_api[currentapi]["cache"][str(searchquery).lower()].append(tempdict)
except urllib.error.HTTPError:
return
def gif_url_assemble(self, currentapi, searchquery, searchlimit, searchnsfw): def gif_url_assemble(self, currentapi, searchquery, searchlimit, searchnsfw):
# url base # url base

View File

@ -6,6 +6,7 @@ This is the SpiceBot Channels system.
import sopel import sopel
import time import time
from threading import Thread
from sopel_modules.spicemanip import spicemanip 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.event(SpiceBot.events.BOT_CHANNELS)
@sopel.module.rule('.*') @sopel.module.rule('.*')
def trigger_channel_list_recurring(bot, trigger): def trigger_channel_list_recurring(bot, trigger):
Thread(target=channels_thread, args=(bot,)).start()
def channels_thread(bot):
while True: while True:
time.sleep(1800) time.sleep(1800)
SpiceBot.channels.bot_part_empty(bot) SpiceBot.channels.bot_part_empty(bot)

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
This is the SpiceBot Events system. This is the SpiceBot Events system.
""" """
import sopel import sopel
from threading import Thread
import sopel_modules.SpiceBot as SpiceBot 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") 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""" """For items tossed in a queue, this will trigger them accordingly"""
Thread(target=events_thread, args=(bot,)).start()
def events_thread(bot):
while True: while True:
if len(SpiceBot.events.dict["trigger_queue"]): if len(SpiceBot.events.dict["trigger_queue"]):
pretriggerdict = SpiceBot.events.dict["trigger_queue"][0] pretriggerdict = SpiceBot.events.dict["trigger_queue"][0]

View File

@ -4,6 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
This is the SpiceBot Logs system. This is the SpiceBot Logs system.
""" """
import sopel import sopel
from threading import Thread
import sopel_modules.SpiceBot as SpiceBot import sopel_modules.SpiceBot as SpiceBot
@ -18,10 +19,13 @@ def join_log_channel(bot, trigger):
bot.write(('JOIN', bot.nick, channel)) bot.write(('JOIN', bot.nick, channel))
if channel not in list(bot.channels.keys()) and bot.config.SpiceBot_Channels.operadmin: if channel not in list(bot.channels.keys()) and bot.config.SpiceBot_Channels.operadmin:
bot.write(('SAJOIN', bot.nick, channel)) bot.write(('SAJOIN', bot.nick, channel))
Thread(target=logs_thread, args=(bot, channel,)).start()
while True:
if len(SpiceBot.logs.dict["queue"]):
bot.osd(str(SpiceBot.logs.dict["queue"][0]), channel)
del SpiceBot.logs.dict["queue"][0]
else: else:
SpiceBot.logs.dict["queue"] = [] 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]

View File

@ -7,6 +7,9 @@ import sopel.module
import sopel_modules.SpiceBot as SpiceBot import sopel_modules.SpiceBot as SpiceBot
# @rule(r"^(r|u)\/([^\s/]+)") TODO
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED]) @SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED])
@sopel.module.rule(r"""(?:)u/ @sopel.module.rule(r"""(?:)u/
( (