Fixed global session, added no prefix in DMs

This commit is contained in:
Adriene Hutchins 2020-02-23 17:47:51 -05:00
parent 8f9a7064f5
commit 83c7aaa76d
7 changed files with 152 additions and 18 deletions

View file

@ -13,7 +13,7 @@ import random
class Developer(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.session = bot.session
self.request = bot.request
self.instances = bot.instances
async def _instance_check(self, instance, info):
@ -43,7 +43,7 @@ class Developer(commands.Cog):
# Check for Google captcha
test_search = f'{instance}/search?q=test&format=json&lang=en-US'
try:
async with self.session.get(test_search) as resp:
async with self.request.get(test_search) as resp:
response = await resp.json()
response['results'][0]['content']
except (aiohttp.ClientError, KeyError, IndexError):
@ -61,7 +61,7 @@ class Developer(commands.Cog):
plausible = []
# Get, parse, and quality check all instances
async with self.session.get('https://searx.space/data/instances.json') as r:
async with self.request.get('https://searx.space/data/instances.json') as r:
# Parsing
searx_json = await r.json()
instances = searx_json['instances']

View file

@ -13,7 +13,7 @@ import random
class Search(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.session = bot.session
self.request = bot.request
self.instances = bot.instances
async def _search_logic(self, query: str, type: str = None):
@ -26,10 +26,12 @@ class Search(commands.Cog):
instance = random.sample(self.instances, k=1)[0]
print(f"Attempting to use {instance}")
appinfo = await self.bot.application_info()
# Error Template
error_msg = ("**An error occured!**\n\n"
f"There was a problem with `{instance}`. Please try again later.\n"
f"_If problems with this instance persist, contact`{self.bot.appinfo.owner}` to have it removed._")
f"_If problems with this instance persist, contact`{appinfo.owner}` to have it removed._")
# Create the URL to make an API call to
call = f'{instance}/search?q={query}&format=json&language=en-US'
@ -40,7 +42,7 @@ class Search(commands.Cog):
# Make said API call
try:
async with self.session.get(call) as resp:
async with self.request.get(call) as resp:
response = await resp.json()
except aiohttp.ClientError:
return error_msg