Created
August 6, 2015 21:43
-
-
Save Lordnibbler/2abb750d5006220cde6d to your computer and use it in GitHub Desktop.
Hubot Giphy Coffeescript
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
# Commands: | |
# giphy <term> - Returns a randomly selected gif from a search of the giphy api for <term> | |
giphy = | |
api_key: process.env.HUBOT_GIPHY_API_KEY | |
api_url: 'http://api.giphy.com/v1' | |
search: (msg, q, callback) -> | |
endpoint = '/gifs/search' | |
url = "#{giphy.api_url}#{endpoint}" | |
msg.http(url) | |
.query | |
api_key: giphy.api_key | |
q: q | |
.get() (err, res, body) -> | |
res = JSON.parse(body) | |
data = res?.data || [] | |
if data.length | |
img_obj = msg.random data | |
msg.send(img_obj.images.original.url) | |
else | |
msg.send "No results found for #{q}" | |
module.exports = (robot) -> | |
robot.respond /giphy (.*)/i, (msg) -> | |
giphy.search msg, msg.match[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment