Change discord version to 1.6.0, Google search (fixes #18)

This commit is contained in:
Stijn De Clercq 2021-01-24 13:08:58 +01:00
parent 3a6e57db73
commit 83f28d9e21
4 changed files with 43 additions and 9 deletions

View file

@ -13,14 +13,39 @@ class Google(commands.Cog):
def cog_check(self, ctx):
return not self.client.locked
@commands.command(name="Google", aliases=["Gtfm", "Search"])
@commands.command(name="Google", aliases=["Gtfm", "Search"], usage="[Query]", case_insensitive=True)
@help.Category(Category.Other)
async def google(self, ctx, *query):
if not query:
return await ctx.reply("Je hebt geen query opgegeven.", mention_author=True)
results, status = google_search(" ".join(query))
if results is None:
return await ctx.send("Er ging iets fout (Response {})".format(status))
elements = list(filter(lambda x: x is not None, results))
if len(elements) > 10:
elements = elements[:10]
embed = discord.Embed(colour=discord.Colour.blue())
embed.set_author(name="Google Search")
# Empty list of results
if len(elements) == 0:
embed.description = "Geen resultaten gevonden."
return await ctx.reply(embed=embed, mention_author=False)
links = []
for index, (link, title) in enumerate(elements):
links.append("{}: [{}]({})".format(index + 1, title, link))
embed.description = "\n".join(links)
await ctx.reply(embed=embed, mention_author=False)
def setup(client):
client.add_cog(Google(client))