mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 19:28:54 -05:00
commit
1d2c3b80c7
@ -3,6 +3,7 @@ from discord.ext import commands
|
|||||||
from random import randint
|
from random import randint
|
||||||
from imgurpython import ImgurClient
|
from imgurpython import ImgurClient
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import random
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
"""Image related commands."""
|
"""Image related commands."""
|
||||||
@ -65,5 +66,29 @@ class Image:
|
|||||||
else:
|
else:
|
||||||
await self.bot.say("gif [text]")
|
await self.bot.say("gif [text]")
|
||||||
|
|
||||||
|
@commands.command(no_pm=True)
|
||||||
|
async def gifr(self, *text):
|
||||||
|
""" gifr [keyword] - retrieves a random gif from a giphy search """
|
||||||
|
random.seed()
|
||||||
|
if len(text) > 0:
|
||||||
|
if len(text[0]) > 1 and len(text[0]) < 20:
|
||||||
|
try:
|
||||||
|
msg = "+".join(text)
|
||||||
|
search = "http://api.giphy.com/v1/gifs/search?q=" + msg + "&api_key=dc6zaTOxFJmzC"
|
||||||
|
async with aiohttp.get(search) as r:
|
||||||
|
result = await r.json()
|
||||||
|
if result["data"] != []:
|
||||||
|
maxarray = len(result)
|
||||||
|
url = result["data"][random.randint(0,maxarray)]["url"]
|
||||||
|
await self.bot.say(url)
|
||||||
|
else:
|
||||||
|
await self.bot.say("Your search terms gave no results.")
|
||||||
|
except:
|
||||||
|
await self.bot.say("Error.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("Invalid search.")
|
||||||
|
else:
|
||||||
|
await self.bot.say("gif [text]")
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Image(bot))
|
bot.add_cog(Image(bot))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user