Advertisement
Yoloswagger

Regarde il est beau le code :lul

Jun 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.12 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. import http.client
  4. import json
  5. from random import randint
  6. import random
  7. import asyncio
  8. import aiohttp
  9.  
  10. class cyvgel:
  11.     """My custom cog that does stuff!"""
  12.  
  13.     def __init__(self, bot):
  14.         self.bot = bot
  15.  
  16. #GelCommand
  17.     @commands.command(pass_context=True)
  18.     async def gel(self, ctx, tags):
  19.         cname = "no"
  20.         await gelbooru(self, ctx, tags=tags, cname = cname), asyncio.sleep(10)
  21. #Miyuki
  22.     @commands.command(pass_context=True)
  23.     async def miyuki(self, ctx):
  24.         """Miyuki ? :D"""
  25.         tags = "shiba_miyuki"
  26.         cname = "no"
  27.         await gelbooru(self, ctx, tags=tags, cname = cname), asyncio.sleep(10)
  28.  
  29. #MiyukiAliasSpe
  30.     @commands.command(pass_context=True)
  31.     async def micki(self, ctx):
  32.         """Miyuki ? :D"""
  33.         cname = "yes"
  34.         author = ctx.message.author
  35.         server = ctx.message.server
  36.         authorlist = ["115946460419194889",
  37.                       "386916606078353409",
  38.                       "405012289859878919"]
  39.         mention = "<@405012289859878919>"
  40.         if author.id in authorlist:
  41.             tags = "shiba_miyuki"
  42.             await gelbooru(self, ctx, tags=tags, cname = cname), asyncio.sleep(10)
  43.         else:
  44.             messages = "Cette commande est réservé à cyvax & Miyuki désolé :("
  45.             await self.bot.say(messages)
  46. async def gelbooru(self, ctx, tags : list=[], cname : list=[]):
  47.     try:
  48.         tagUnder = tags.replace("_", " ")
  49.         mesg = "Recherche d'une image avec le tag : {}".format(tagUnder)
  50.         e = discord.Embed(title=mesg, colour=0xe7a854)
  51.         msg = await self.bot.say(embed=e)
  52.         urldest = "/index.php?page=dapi&s=post&q=index"
  53.         domain = "www.gelbooru.com"
  54.         request_type = 'GET'
  55.         destination = '/index.php?page=dapi&s=post&q=index'
  56.         json_ = 1
  57.         limit_ = 1
  58.         fullurl = "http://www.gelbooru.com/index.php?page=dapi&s=post&q=index&tags={}".format(tags)
  59.         async with aiohttp.get(fullurl, headers={'User-Agent': "cyvax"}) as r:
  60.             site = await r.text()
  61.         countStart = site.find("count=\"")
  62.         countEnd = site.find("\"", countStart+7)
  63.         count = min(int(site[countStart+7:countEnd]), 20000)
  64.         pid_ = str(random.randint(0, count))
  65.  
  66.         urldest = destination + "&json=" + str(json_) + "&pid=" + str(pid_) + "&tags=" + tags + "&limit=" + str(limit_)
  67.    
  68.         u = http.client.HTTPSConnection(domain)
  69.         u.request(request_type, urldest)
  70.         response = u.getresponse().read()
  71.         jsondata = json.loads(response)
  72.         u.close()
  73.         if cname == "yes":
  74.             mention = "<@405012289859878919>"  
  75.             for e in jsondata:
  76.                 if e["rating"] == "s":
  77.                     imageRating ="rating : safe"
  78.                     messages = "Salut {} tu a eu chaud :D".format(mention)
  79.                 elif e["rating"] == "q":
  80.                     imageRating = "rating : questionable"
  81.                     messages = "Faudrait peut être penser a te respecter {}".format(mention)
  82.                 elif e["rating"] == "e":
  83.                     imageRating = "rating : explicit"
  84.                     messages = "On se respecte pas {} ? x)".format(mention)
  85.             await self.bot.say(messages)
  86.         else:
  87.             entries = len(jsondata)
  88.             for e in jsondata:
  89.                 if e["rating"] == "s":
  90.                     imageRating ="rating : safe"
  91.                 elif e["rating"] == "q":
  92.                     imageRating = "rating : questionable"
  93.                 elif e["rating"] == "e":
  94.                     imageRating = "rating : explicit"
  95.  
  96.         imagelink = e["file_url"]
  97.         embed=discord.Embed(title=tags, url=imagelink, description=imageRating, color=0xe7a854)
  98.         embed.set_image(url=imagelink)
  99.         await self.bot.edit_message(msg, embed=embed)
  100.     except:
  101.         error = "aucun résultat avec le tag {}".format(tags)
  102.         embed=discord.Embed(title="ERREUR", description=error, color=0xff0000)
  103.         await self.bot.edit_message(msg, embed=embed)
  104.  
  105. def setup(bot):
  106.     bot.add_cog(cyvgel(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement