KiTTY, un bot Discord qui est un petit chat :) Il est basé sur une ancienne version du bot Red, sous Python 3.6 et qui a des fonctionnalités bien sympatiques !
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

66 lines
2.5KB

  1. import discord
  2. from discord.ext import commands
  3. from __main__ import send_cmd_help
  4. import wikipedia
  5. import urllib.request, json
  6. class Wikipedia:
  7. """Wikipedia search for the Red-DiscordBot"""
  8. def __init__(self, bot):
  9. self.bot = bot
  10. @commands.command(pass_context=True, no_pm=True)
  11. async def wikipedia(self, ctx, *text):
  12. """Wikipedia search. (Only french results)"""
  13. if text == ():
  14. await send_cmd_help(ctx)
  15. return
  16. else:
  17. s = "_";
  18. search = ""
  19. search = s.join(text)
  20. user = ctx.message.author
  21. wikiLang = 'fr'# Define the Wikipedia language / Most of these are supported » https://nl.wikipedia.org/wiki/ISO_3166-1
  22. ws = None
  23. wikipedia.set_lang(wikiLang)# Set the Wikipedia language.
  24. try:
  25. ws = wikipedia.page(search)
  26. wikiUrl = (ws.url.encode('ascii', 'xmlcharrefreplace'))
  27. await self.bot.say(wikiUrl.decode("utf8"))
  28. except:
  29. await self.bot.say( "Sorry {}, I've found any results :cat:".format(user))
  30. @commands.command(pass_context=True)
  31. async def docubuntu(self, ctx, args):
  32. """Ubuntu Doc search, only french"""
  33. attends = await self.bot.say("I'm searching this for you, {} :cat: !".format(ctx.message.author.mention))
  34. html = urllib.request.urlopen("https://doc.ubuntu-fr.org/" + args).read()
  35. if "avez suivi un lien" in str(html):
  36. await self.bot.say("This page doesn't exist !")
  37. else:
  38. await self.bot.say("https://doc.ubuntu-fr.org/" + args)
  39. @commands.command(pass_context=True)
  40. async def searchaur(self, ctx, args):
  41. """Search into the AUR database."""
  42. attends = await self.bot.say("I'm searching this for you, {} :cat: !".format(ctx.message.author.mention))
  43. erreur = 0
  44. try:
  45. html = urllib.request.urlopen("https://aur.archlinux.org/packages/" + args).read()
  46. except:
  47. erreur = 1
  48. if erreur == 1:
  49. await self.bot.say("I've made a little search on this : https://aur.archlinux.org/packages/?K=" + args)
  50. else:
  51. await self.bot.say("https://aur.archlinux.org/packages/{0} ! \n Use ``pacaur -S {0}`` to install it :cat: !".format(args))
  52. class ModuleNotFound(Exception):
  53. def __init__(self, m):
  54. self.message = m
  55. def __str__(self):
  56. return self.message
  57. def setup(bot):
  58. bot.add_cog(Wikipedia(bot))