Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created April 7, 2015 15:35
Show Gist options
  • Save jfromaniello/c2bb59374116ab975836 to your computer and use it in GitHub Desktop.
Save jfromaniello/c2bb59374116ab975836 to your computer and use it in GitHub Desktop.
# Description:
# Show an image of a sad panda everytime someone use `@channel` to notify every user on a channel.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# @channel
#
# Author:
# Jose F. Romaniello
imageMe = (msg, query, cb) ->
animated = Math.random() < 0.5
cb = animated if typeof animated == 'function'
q = v: '1.0', rsz: '8', q: query, safe: 'active'
q.as_filetype = 'gif' if typeof animated is 'boolean' and animated is true
msg.http('http://ajax.googleapis.com/ajax/services/search/images')
.query(q)
.get() (err, res, body) ->
images = JSON.parse(body)
images = images.responseData.results
if images.length > 0
image = msg.random images
cb "#{image.unescapedUrl}#.png"
module.exports = (robot) ->
robot.hear /\@channel/i, (msg) ->
imageMe msg, 'sad panda', (url) ->
msg.send url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment