Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import http.client
- import json
- from random import randint
- import random
- import asyncio
- import aiohttp
- class cyvgel:
- """My custom cog that does stuff!"""
- def __init__(self, bot):
- self.bot = bot
- #GelCommand
- @commands.command(pass_context=True)
- async def gel(self, ctx, tags):
- cname = "no"
- await gelbooru(self, ctx, tags=tags, cname = cname), asyncio.sleep(10)
- #Miyuki
- @commands.command(pass_context=True)
- async def miyuki(self, ctx):
- """Miyuki ? :D"""
- tags = "shiba_miyuki"
- cname = "no"
- await gelbooru(self, ctx, tags=tags, cname = cname), asyncio.sleep(10)
- #MiyukiAliasSpe
- @commands.command(pass_context=True)
- async def micki(self, ctx):
- """Miyuki ? :D"""
- cname = "yes"
- author = ctx.message.author
- server = ctx.message.server
- authorlist = ["115946460419194889",
- "386916606078353409",
- "405012289859878919"]
- mention = "<@405012289859878919>"
- if author.id in authorlist:
- tags = "shiba_miyuki"
- await gelbooru(self, ctx, tags=tags, cname = cname), asyncio.sleep(10)
- else:
- messages = "Cette commande est réservé à cyvax & Miyuki désolé :("
- await self.bot.say(messages)
- async def gelbooru(self, ctx, tags : list=[], cname : list=[]):
- try:
- tagUnder = tags.replace("_", " ")
- mesg = "Recherche d'une image avec le tag : {}".format(tagUnder)
- e = discord.Embed(title=mesg, colour=0xe7a854)
- msg = await self.bot.say(embed=e)
- 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
- 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)
- elif e["rating"] == "q":
- imageRating = "rating : questionable"
- messages = "Faudrait peut être penser a te respecter {}".format(mention)
- elif e["rating"] == "e":
- imageRating = "rating : explicit"
- messages = "On se respecte pas {} ? x)".format(mention)
- await self.bot.say(messages)
- else:
- entries = len(jsondata)
- for e in jsondata:
- if e["rating"] == "s":
- imageRating ="rating : safe"
- elif e["rating"] == "q":
- imageRating = "rating : questionable"
- elif e["rating"] == "e":
- imageRating = "rating : explicit"
- imagelink = e["file_url"]
- embed=discord.Embed(title=tags, url=imagelink, description=imageRating, color=0xe7a854)
- embed.set_image(url=imagelink)
- await self.bot.edit_message(msg, embed=embed)
- except:
- 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)
- def setup(bot):
- bot.add_cog(cyvgel(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement