Let's let Giphy handle the randomness. Works much better

This commit is contained in:
scummboy 2016-02-16 14:35:36 +00:00
parent 4a274d178a
commit ffddc09f9e

View File

@ -81,12 +81,11 @@ class Image:
if len(text[0]) > 1 and len(text[0]) < 20: if len(text[0]) > 1 and len(text[0]) < 20:
try: try:
msg = "+".join(text) msg = "+".join(text)
search = "http://api.giphy.com/v1/gifs/search?q=" + msg + "&api_key=dc6zaTOxFJmzC" search = "http://api.giphy.com/v1/gifs/random?&api_key=dc6zaTOxFJmzC&tag=" + msg
async with aiohttp.get(search) as r: async with aiohttp.get(search) as r:
result = await r.json() result = await r.json()
if result["data"] != []: if result["data"] != []:
maxarray = len(result) url = result["data"]["url"]
url = result["data"][random.randint(0,maxarray)]["url"]
await self.bot.say(url) await self.bot.say(url)
else: else:
await self.bot.say("Your search terms gave no results.") await self.bot.say("Your search terms gave no results.")