2021-01-23 23:40:49 +01:00
|
|
|
import discord
|
|
|
|
from discord.ext import commands
|
|
|
|
from decorators import help
|
|
|
|
from enums.help_categories import Category
|
2021-09-03 17:57:45 +02:00
|
|
|
from functions.scrapers.google import google_search, create_google_embed
|
2021-08-30 23:21:34 +02:00
|
|
|
|
|
|
|
|
2021-01-23 23:40:49 +01:00
|
|
|
class Google(commands.Cog):
|
|
|
|
def __init__(self, client):
|
|
|
|
self.client = client
|
|
|
|
|
|
|
|
# Don't allow any commands to work when locked
|
|
|
|
def cog_check(self, ctx):
|
|
|
|
return not self.client.locked
|
|
|
|
|
2021-01-24 13:08:58 +01:00
|
|
|
@commands.command(name="Google", aliases=["Gtfm", "Search"], usage="[Query]", case_insensitive=True)
|
2021-01-23 23:40:49 +01:00
|
|
|
@help.Category(Category.Other)
|
|
|
|
async def google(self, ctx, *query):
|
2021-01-24 13:08:58 +01:00
|
|
|
if not query:
|
|
|
|
return await ctx.reply("Je hebt geen query opgegeven.", mention_author=True)
|
|
|
|
|
2021-08-31 00:13:27 +02:00
|
|
|
result = google_search(" ".join(query))
|
2021-01-23 23:40:49 +01:00
|
|
|
|
2021-08-31 00:13:27 +02:00
|
|
|
if not result.results:
|
|
|
|
return await ctx.send("Er ging iets fout (Response {})".format(result.status_code))
|
2021-01-23 23:40:49 +01:00
|
|
|
|
2021-09-03 17:57:45 +02:00
|
|
|
embed = create_google_embed(result)
|
2021-01-24 13:08:58 +01:00
|
|
|
await ctx.reply(embed=embed, mention_author=False)
|
|
|
|
|
2021-01-23 23:40:49 +01:00
|
|
|
|
|
|
|
def setup(client):
|
|
|
|
client.add_cog(Google(client))
|