Last active
April 28, 2020 13:01
-
-
Save shahriyardx/49b90d2474a5105809355de57b5aacb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@commands.command() | |
@commands.cooldown(1,30, commands.BucketType.user) | |
async def pixabay(self, ctx,cou:int,*,query): | |
sg = self.client.get_guild(700374484955299900) | |
nextbtn = discord.utils.get(sg.emojis, name="ignext") | |
prevbtn = discord.utils.get(sg.emojis, name="igprev") | |
skipf = discord.utils.get(sg.emojis, name="igskipf") | |
skipb = discord.utils.get(sg.emojis, name="igskipb") | |
beg = discord.utils.get(sg.emojis, name="igbeg") | |
end = discord.utils.get(sg.emojis, name="igend") | |
next = True | |
query = query.replace(" ", "+") | |
if cou < 3: | |
cou = 3 | |
if cou > 200: | |
cou = 200 | |
if ctx.channel.nsfw: | |
ss = "&safesearch=false" | |
se = "Disabled" | |
else: | |
ss = "&safesearch=true" | |
se = "Enabled" | |
try: | |
async with aiohttp.ClientSession() as s: | |
async with s.get(f"https://pixabay.com/api/?key=16244254-43c141e7eae6cdcf242bb7&q={query}&image_type=photo&pretty=true&per_page={cou}{ss}") as r: | |
data = await r.json() | |
except: | |
await ctx.send("Something went wrong!") | |
next = False | |
count = 0 | |
fnd = 0 | |
while next: | |
if len(data["hits"]) >0: | |
try: | |
r = data["hits"][count] | |
fnd = len(data["hits"]) | |
#await ctx.send(r["largeImageURL"]) | |
embed = discord.Embed(color=ctx.author.color, timestamp=ctx.message.created_at) | |
embed.set_image(url=r["largeImageURL"]) | |
embed.add_field(name="Tags", value=r["tags"]) | |
embed.set_footer(text=f"Page {count+1}/{fnd} - Safesearch : {se}") | |
except: | |
await ctx.send("No more images found!") | |
break | |
else: | |
await ctx.send("Nothing match your query!") | |
break | |
if count <=0: | |
try: | |
await msg.edit(embed=embed) | |
except: | |
msg = await ctx.send(embed=embed) | |
else: | |
await msg.edit(embed=embed) | |
if count >0: | |
await msg.add_reaction(beg) | |
await asyncio.sleep(0.1) | |
if count >4: | |
await msg.add_reaction(skipb) | |
await asyncio.sleep(0.1) | |
await msg.add_reaction(prevbtn) | |
await asyncio.sleep(0.1) | |
if count < fnd -1: | |
await msg.add_reaction(nextbtn) | |
await asyncio.sleep(0.1) | |
if fnd > 5 and count < fnd -1: | |
await msg.add_reaction(skipf) | |
await asyncio.sleep(0.1) | |
if count < fnd -1: | |
await msg.add_reaction(end) | |
await asyncio.sleep(0.1) | |
def check(r,u): | |
return (u.id == ctx.author.id) and (r.message.id == msg.id) | |
try: | |
r, u = await self.client.wait_for("reaction_add", timeout=60, check=check) | |
if r.emoji == nextbtn: | |
count += 1 | |
elif r.emoji == prevbtn: | |
count -= 1 | |
elif r.emoji == end: | |
count = fnd-1 | |
elif r.emoji == beg: | |
count = 0 | |
elif r.emoji == skipf: | |
if count +5 > fnd-1: | |
count = fnd -1 | |
else: | |
count += 5 | |
elif r.emoji == skipb: | |
if count -5 <0: | |
count = 0 | |
else: | |
count -= 5 | |
try: | |
await msg.clear_reactions() | |
except: | |
pass | |
except: | |
try: | |
await msg.clear_reactions() | |
except: | |
pass | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment