Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (38 sloc) 1.732 kB
# Description:
# A way to interact with the Google Images API.
# Commands:
# hubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
# hubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
# hubot mustache me <url> - Adds a mustache to the specified URL.
# hubot mustache me <query> - Searches Google Images for the specified query and mustaches it.
module.exports = (robot) ->
robot.respond /(image|img)( me)? (.*)/i, (msg) ->
imageMe msg, msg.match[3], (url) ->
msg.send url
robot.respond /animate( me)? (.*)/i, (msg) ->
imageMe msg, msg.match[2], true, (url) ->
msg.send url
robot.respond /(?:mo?u)?sta(?:s|c)he?(?: me)? (.*)/i, (msg) ->
type = Math.floor(Math.random() * 3)
mustachify = "{type}?src="
imagery = msg.match[1]
if imagery.match /^https?:\/\//i
msg.send "#{mustachify}#{imagery}"
imageMe msg, imagery, false, true, (url) ->
msg.send "#{mustachify}#{url}"
imageMe = (msg, query, animated, faces, cb) ->
cb = animated if typeof animated == 'function'
cb = faces if typeof faces == 'function'
q = v: '1.0', rsz: '8', q: query, safe: 'active'
q.as_filetype = 'gif' if typeof animated is 'boolean' and animated is true
q.imgtype = 'face' if typeof faces is 'boolean' and faces is true
.get() (err, res, body) ->
images = JSON.parse(body)
images = images.responseData.results
if images.length > 0
image = msg.random images
cb "#{image.unescapedUrl}#.png"
Jump to Line
Something went wrong with that request. Please try again.