Pushed kissing gifs but from API to see how fast it is

pull/8/head
sgoudham 4 years ago
parent 58a5270fa5
commit 45122316de

@ -17,6 +17,8 @@
import datetime import datetime
import random import random
import aiohttp
from decouple import config
from discord import Embed, Member from discord import Embed, Member
from discord.ext.commands import cooldown, command, BucketType, bot_has_permissions, Cog from discord.ext.commands import cooldown, command, BucketType, bot_has_permissions, Cog
@ -43,8 +45,6 @@ class Interactive(Cog):
"""Printing out that Cog is ready on startup""" """Printing out that Cog is ready on startup"""
print(f"{self.__class__.__name__} Cog has been loaded\n-----") print(f"{self.__class__.__name__} Cog has been loaded\n-----")
# TODO: MAKE EVERYTHING IN HERE ASYNCHRONOUS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@command(name="kiss") @command(name="kiss")
@bot_has_permissions(embed_links=True) @bot_has_permissions(embed_links=True)
@cooldown(1, 3, BucketType.user) @cooldown(1, 3, BucketType.user)
@ -74,11 +74,20 @@ class Interactive(Cog):
await self.bot.generate_embed(ctx, desc="Σ(‘◉⌓◉’) You can only kiss your partner! Baka!") await self.bot.generate_embed(ctx, desc="Σ(‘◉⌓◉’) You can only kiss your partner! Baka!")
return return
try: # Set details for search
# Open the file containing the kissing gifs apikey = config("TENOR_AUTH") # test value
with open('images/FunCommands/kissing.txt') as file: search_term = "anime-kiss"
# Store content of the file in kissing_array url = f"https://api.tenor.com/v1/random?q={search_term}&key={apikey}&limit=1"
kissing_array = file.readlines()
# get random results using default locale of EN_US
# Searching API for the current airing shows
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
if resp.status == 200:
gifs = await resp.json()
url = gifs["results"][0]["media"][0]["gif"]["url"]
else:
self.bot.generate_embed(ctx, desc="**Something Went Wrong With Tenor!**")
# Get the member and the userAvatar # Get the member and the userAvatar
member, userAvatar = getMember(ctx) member, userAvatar = getMember(ctx)
@ -88,15 +97,12 @@ class Interactive(Cog):
title=title, title=title,
colour=self.bot.random_colour(), colour=self.bot.random_colour(),
timestamp=datetime.datetime.utcnow()) timestamp=datetime.datetime.utcnow())
embed.set_image(url=random.choice(kissing_array)) embed.set_image(url=url)
embed.set_footer(text=f"Requested by {member}", icon_url=userAvatar) embed.set_footer(text=f"Requested by {member}", icon_url=userAvatar)
# Send the embedded message to the user # Send the embedded message to the user
await ctx.send(embed=embed) await ctx.send(embed=embed)
except FileNotFoundError as e:
print(e)
@command(name="cuddle") @command(name="cuddle")
@bot_has_permissions(embed_links=True) @bot_has_permissions(embed_links=True)
@cooldown(1, 3, BucketType.user) @cooldown(1, 3, BucketType.user)

Loading…
Cancel
Save