Merge pull request #94 from bwreilly/master

Added GIF search plugin
This commit is contained in:
Ryan Hitchman 2014-01-02 20:07:44 -08:00
commit a45b3146ec
1 changed files with 21 additions and 0 deletions

21
plugins/gif.py Normal file
View File

@ -0,0 +1,21 @@
import random
from util import hook, http
@hook.api_key('giphy')
@hook.command('gif')
@hook.command
def giphy(inp, api_key=None):
'''.gif/.giphy <query> -- returns first giphy search result'''
url = 'http://api.giphy.com/v1/gifs/search'
try:
response = http.get_json(url, q=inp, limit=10, api_key=api_key)
except http.HTTPError as e:
return e.msg
results = response.get('data')
if results:
return random.choice(results).get('bitly_gif_url')
else:
return 'no results found'