mirror of
https://github.com/polyjitter/searchbot-discord.git
synced 2024-08-14 22:46:55 +00:00
Fixed developer cog_check
This commit is contained in:
parent
03f821c920
commit
422796b91f
2 changed files with 39 additions and 4 deletions
|
@ -111,7 +111,8 @@ class Developer(commands.Cog):
|
||||||
3 / 0
|
3 / 0
|
||||||
|
|
||||||
async def cog_check(self, ctx):
|
async def cog_check(self, ctx):
|
||||||
return commands.is_owner()
|
|
||||||
|
return (ctx.author.id == self.bot.appinfo.owner.id)
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Developer(bot))
|
bot.add_cog(Developer(bot))
|
|
@ -9,6 +9,7 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import random
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
class Search(commands.Cog):
|
class Search(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -16,7 +17,7 @@ class Search(commands.Cog):
|
||||||
self.request = bot.request
|
self.request = bot.request
|
||||||
self.instances = bot.instances
|
self.instances = bot.instances
|
||||||
|
|
||||||
async def _search_logic(self, query: str, is_nsfw: bool = False, type: str = None):
|
async def _search_logic(self, query: str, is_nsfw: bool = False, category: str = None):
|
||||||
"""Provides search logic for all search commands."""
|
"""Provides search logic for all search commands."""
|
||||||
|
|
||||||
# WARNING - This list includes slurs.
|
# WARNING - This list includes slurs.
|
||||||
|
@ -58,8 +59,8 @@ class Search(commands.Cog):
|
||||||
call = f'{instance}/search?q={query}&format=json&language=en-US'
|
call = f'{instance}/search?q={query}&format=json&language=en-US'
|
||||||
|
|
||||||
# If a type is provided, add that type to the call URL
|
# If a type is provided, add that type to the call URL
|
||||||
if type:
|
if category:
|
||||||
call += f'&type={type}'
|
call += f'&category={category}'
|
||||||
|
|
||||||
if is_nsfw:
|
if is_nsfw:
|
||||||
call += f'&safesearch=0'
|
call += f'&safesearch=0'
|
||||||
|
@ -143,5 +144,38 @@ class Search(commands.Cog):
|
||||||
# Sends result
|
# Sends result
|
||||||
await ctx.send(msg)
|
await ctx.send(msg)
|
||||||
|
|
||||||
|
def _create_cat_func(name: str, desc: str):
|
||||||
|
'''Creates functions for our categories.'''
|
||||||
|
|
||||||
|
async def cat_generic(self, ctx, *, query: str):
|
||||||
|
f'''{desc}'''
|
||||||
|
async with ctx.typing():
|
||||||
|
msg = await self._search_logic(
|
||||||
|
query, ctx.channel.is_nsfw(), name)
|
||||||
|
await ctx.send(msg)
|
||||||
|
|
||||||
|
return cat_generic
|
||||||
|
|
||||||
|
_categories = {
|
||||||
|
'it': 'Search computer-related resources.',
|
||||||
|
'images': 'Search for images.',
|
||||||
|
'video': 'Search for videos.',
|
||||||
|
'music': 'Search for music.',
|
||||||
|
'files': 'Search for files.',
|
||||||
|
'maps': 'Search for map results.',
|
||||||
|
'news': 'Search for new articles.',
|
||||||
|
'science': 'Search for scientific knowledge.',
|
||||||
|
'social+media': 'Search for social media results.',
|
||||||
|
}
|
||||||
|
|
||||||
|
for c, d in _categories.items():
|
||||||
|
print(c)
|
||||||
|
print(d)
|
||||||
|
c_good = c.replace('+', '')
|
||||||
|
c_funcname = c.replace('+', '_')
|
||||||
|
made_func = _create_cat_func(c, d)
|
||||||
|
setattr(Search, c_funcname, made_func)
|
||||||
|
commands.command(name=c_good)(made_func)
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Search(bot))
|
bot.add_cog(Search(bot))
|
Loading…
Add table
Add a link
Reference in a new issue