Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def gelbooru(self, ctx, tags : list=[], cname : list=[], rand : list=[]):
- urldest = "/index.php?page=dapi&s=post&q=index"
- domain = "www.gelbooru.com"
- request_type = 'GET'
- destination = '/index.php?page=dapi&s=post&q=index'
- json_ = 1
- limit_ = 1
- try:
- if rand == "yes":
- mesg = "Recherche d'une image sans tags."
- e = discord.Embed(title=mesg, colour=0xe7a854)
- msg = await self.bot.say(embed=e)
- fullurl = "http://www.gelbooru.com/index.php?page=dapi&s=post&q=index"
- async with aiohttp.get(fullurl, headers={'User-Agent': "cyvax"}) as r:
- site = await r.text()
- countStart = site.find("count=\"")
- countEnd = site.find("\"", countStart+7)
- count = min(int(site[countStart+7:countEnd]), 20000)
- pid_ = str(random.randint(0, count))
- urldest = destination + "&json=" + str(json_) + "&pid=" + str(pid_) + "&limit=" + str(limit_)
- tagUnder = "Aucun"
- elif rand == "no":
- if "_" in tags:
- tagUnder = tags.replace("_", " ")
- else:
- tagUnder = tags
- msg1 = "Recherche d'une image avec le tag : {}".format(tags)
- e = discord.Embed(title=msg1, colour=0xe7a854)
- msg = await self.bot.say(embed=e)
- fullurl = "http://www.gelbooru.com/index.php?page=dapi&s=post&q=index&tags={}".format(tags)
- async with aiohttp.get(fullurl, headers={'User-Agent': "cyvax"}) as r:
- site = await r.text()
- countStart = site.find("count=\"")
- countEnd = site.find("\"", countStart+7)
- count = min(int(site[countStart+7:countEnd]), 20000)
- pid_ = str(random.randint(0, count))
- urldest = destination + "&json=" + str(json_) + "&pid=" + str(pid_) + "&tags=" + tags + "&limit=" + str(limit_)
- u = http.client.HTTPSConnection(domain)
- u.request(request_type, urldest)
- response = u.getresponse().read()
- jsondata = json.loads(response)
- u.close()
- if cname == "yes":
- mention = "<@405012289859878919>"
- for e in jsondata:
- if e["rating"] == "s":
- imageRating ="rating : safe"
- messages = "Salut {} tu a eu chaud :D".format(mention)
- color = "0x00cc99"
- elif e["rating"] == "q":
- imageRating = "rating : questionable"
- messages = "Faudrait peut être penser a te respecter {}".format(mention)
- color = "0xFF9900"
- elif e["rating"] == "e":
- imageRating = "rating : explicit"
- messages = "On se respecte pas {} ? x)".format(mention)
- color = "0xe32636"
- await self.bot.say(messages)
- else:
- entries = len(jsondata)
- for e in jsondata:
- if e["rating"] == "s":
- imageRating ="rating : safe"
- color = "0x00cc99"
- elif e["rating"] == "q":
- imageRating = "rating : questionable"
- color = "0xe7a854"
- elif e["rating"] == "e":
- imageRating = "rating : explicit"
- color = "0xef25f9"
- imagelink = e["file_url"]
- embed=discord.Embed(title=tagUnder, url=imagelink, description=imageRating, color=discord.Colour(value=int(color, 16)))
- embed.set_image(url=imagelink)
- await self.bot.edit_message(msg, embed=embed)
- except ValueError:
- if not tags:
- error = "ERREUR AUCUN RESULTAT. (API ERROR)"
- embed=discord.Embed(title="ERREUR", description=error, color=0xff0000)
- await self.bot.edit_message(msg, embed=embed)
- else:
- error = "aucun résultat avec le tag {}".format(tags)
- embed=discord.Embed(title="ERREUR", description=error, color=0xff0000)
- await self.bot.edit_message(msg, embed=embed)
- except TypeError:
- error = "API ERROR, RÉPONSE VIDE."
- embed=discord.Embed(title="ERREUR", description=error, color=0xff0000)
- await self.bot.edit_message(msg, embed=embed)
Advertisement
Add Comment
Please, Sign In to add comment