Permalink
Browse files

Added gif-me, a script to search imgur.com for a nice gif.

  • Loading branch information...
1 parent e5f6439 commit 21b01498db73aa13103f924223609bc59c196849 @brkattk brkattk committed Jan 11, 2013
Showing with 31 additions and 0 deletions.
  1. +31 −0 src/scripts/gif-me.coffee
@@ -0,0 +1,31 @@
+# Description:
+# Searches imgur.com for a gif
+#
+# Dependencies:
+# None
+#
+# Configuration:
+# Store your imgur.com application client id in an environment
+# variable called IMGUR_CLIENT_ID. To get api access, visit
+# http://api.imgur.com and register an application.
+#
+# Commands:
+# hubot <keyword> gif - Returns a link to a gif about <keyword>
+#
+# Author:
+# brickattack
+
+module.exports = (robot) ->
+ robot.respond /(.*) gif/i, (msg) ->
+ search = escape(msg.match[1])
+ client_id = 'Client-ID ' + process.env.IMGUR_CLIENT_ID
+ msg.http('https://api.imgur.com/3/gallery/search')
+ .headers(Authorization: client_id)
+ .query(q: search)
+ .get() (err, res, body) ->
+ images = JSON.parse(body).data
+ if images.length > 0
+ image = msg.random images
+ msg.send image.link
+ else
+ msg.send "NO!"

0 comments on commit 21b0149

Please sign in to comment.