Created
April 7, 2015 15:35
-
-
Save jfromaniello/c2bb59374116ab975836 to your computer and use it in GitHub Desktop.
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: | |
# 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