Last active
December 20, 2015 13:39
-
-
Save toots/6140577 to your computer and use it in GitHub Desktop.
Audiosocket hubot script for giphy
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
# Description: | |
# A way to search images on giphy.com | |
# | |
# Configuration: | |
# HUBOT_GIPHY_API_KEY | |
# | |
# Commands: | |
# hubot gif (foo room) <query> - Returns an animated gif matching the requested search term. | |
# Sends result to rooms["foo"] if specified | |
giphy = | |
api_key: process.env.HUBOT_GIPHY_API_KEY | |
base_url: 'http://api.giphy.com/v1' | |
rooms = | |
foo: 123455, | |
bar: 678901, | |
module.exports = (robot) -> | |
robot.respond /gif(?: ([^\s]*) room)? (.*)/i, (msg) -> | |
room = msg.match[1] | |
search = msg.match[2] | |
giphyMe msg, search, (url) -> | |
if room? | |
robot.messageRoom rooms[room], url | |
else | |
msg.send url | |
giphyMe = (msg, query, cb) -> | |
endpoint = '/gifs/random' | |
url = "#{giphy.base_url}#{endpoint}" | |
msg.http(url) | |
.query | |
q: query | |
api_key: giphy.api_key | |
.get() (err, res, body) -> | |
try | |
response = JSON.parse(body) | |
cb response.data.image_original_url | |
catch e | |
cb 'Error' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment