Skip to content

Instantly share code, notes, and snippets.

@tondol
Last active August 29, 2015 14:15
Show Gist options
  • Save tondol/24389071001e3ac365f4 to your computer and use it in GitHub Desktop.
Save tondol/24389071001e3ac365f4 to your computer and use it in GitHub Desktop.
lovelive.coffee
# Description
# A Hubot script for shoda script
#
# Configuration:
# None
#
# Commands:
#
# Author:
# tondol
module.exports = (robot) ->
robot.hear /ラブライブ/i, (msg) ->
imageMe msg, "ラブライブ", true, (url) ->
msg.send 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.imgtype = 'animated' if typeof animated is 'boolean' and animated is true
q.imgtype = 'face' if typeof faces is 'boolean' and faces 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment