Merge pull request #16 from Rom194/patch-5

Update search.py
This commit is contained in:
Maël 2018-12-20 18:12:27 -04:00 committed by GitHub
commit b7c54c7e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,8 +4,6 @@ import asyncio
import urllib.request import urllib.request
import wikipedia import wikipedia
wikipedia.set_lang("fr")
class Search: class Search:
"""Commandes de WWW.""" """Commandes de WWW."""
@ -26,7 +24,7 @@ class Search:
@_search.command(pass_context=True, name="docubuntu") @_search.command(pass_context=True, name="docubuntu")
async def search_docubuntu(self, ctx, args): async def search_docubuntu(self, ctx, args):
attends = await ctx.send("_Je te cherche ça {} !_".format( attends = await ctx.send("_Je te cherche ça {} !_".format(
ctx.message.author.mention)) ctx.author.mention))
html = urllib.request.urlopen("https://doc.ubuntu-fr.org/" + html = urllib.request.urlopen("https://doc.ubuntu-fr.org/" +
args).read() args).read()
if "avez suivi un lien" in str(html): if "avez suivi un lien" in str(html):
@ -52,7 +50,7 @@ class Search:
@_search.command(pass_context=True, name="docarch") @_search.command(pass_context=True, name="docarch")
async def search_docarch(self, ctx, args): async def search_docarch(self, ctx, args):
attends = await ctx.send("_Je te cherche ça {} !_".format( attends = await ctx.send("_Je te cherche ça {} !_".format(
ctx.message.author.mention)) ctx.author.mention))
html = urllib.request.urlopen("https://wiki.archlinux.org/index.php/" + html = urllib.request.urlopen("https://wiki.archlinux.org/index.php/" +
args).read() args).read()
if "There is currently no text in this page" in str(html): if "There is currently no text in this page" in str(html):
@ -75,11 +73,24 @@ class Search:
await ctx.send(embed=embed) await ctx.send(embed=embed)
@_search.command(pass_context=True, name="wikipedia") @_search.command(pass_context=True, name="wikipedia")
async def search_wikipedia(self, ctx: commands.Context, args): async def search_wikipedia(self, ctx: commands.Context, *, args):
"""Fait une recherche sur wikipd""" """Fait une recherche sur wikipd"""
params = args.split(" ")
lang = [x for x in params if x.startswith("lang=")]
if lang:
lang = lang[0]
params.remove(lang)
lang = lang.replace("lang=", "")
wikipedia.set_lang(lang)
else:
wikipedia.set_lang("fr")
params = ' '.join(params)
wait = await ctx.send("_Je cherche..._") wait = await ctx.send("_Je cherche..._")
results = wikipedia.search(args) results = wikipedia.search(params)
nbmr = 0 nbmr = 0
mmssgg = "" mmssgg = ""
@ -87,7 +98,7 @@ class Search:
nbmr = nbmr + 1 nbmr = nbmr + 1
mmssgg = mmssgg + "**{}**: {} \n".format(str(nbmr), value) mmssgg = mmssgg + "**{}**: {} \n".format(str(nbmr), value)
em = discord.Embed(title='Résultats de : ' + args, em = discord.Embed(title='Résultats de : ' + params,
description = mmssgg, description = mmssgg,
colour=0x4ECDC4) colour=0x4ECDC4)
em.set_thumbnail(url="https://upload.wikimedia.org/wikipedia/commons/" em.set_thumbnail(url="https://upload.wikimedia.org/wikipedia/commons/"
@ -124,7 +135,7 @@ class Search:
try: try:
await msg.delete() await msg.delete()
await ctx.trigger_typing() await ctx.trigger_typing()
wait = await ctx.send(ctx.message.author.mention + wait = await ctx.send(ctx.author.mention +
" ah ok sympa cette recherche, je l'effectue de suite !") " ah ok sympa cette recherche, je l'effectue de suite !")
wp = wikipedia.page(args_) wp = wikipedia.page(args_)
wp_contenu = wp.summary[:200] + "..." wp_contenu = wp.summary[:200] + "..."