Skip to content

Instantly share code, notes, and snippets.

@fukayatsu
Created December 2, 2012 10:19
Show Gist options
  • Select an option

  • Save fukayatsu/4188057 to your computer and use it in GitHub Desktop.

Select an option

Save fukayatsu/4188057 to your computer and use it in GitHub Desktop.
hubot command
# Description:
# jotei
#
# Commands:
# hubot jotei img - Searches Google Images for the jotei
# hubot jotei tweet - Recent tweet of the jotei
module.exports = (robot) ->
robot.respond /jotei img/i, (msg) ->
imageMe msg, "yamashitam", (url) ->
msg.send url
robot.respond /jotei status/i, (msg) ->
tweetMe msg, "yamashitam", (text) ->
msg.send text
tweetMe = (msg, name, cb) ->
q = screen_name: name
msg.http("http://api.twitter.com/1/statuses/user_timeline.json")
.query(q)
.get() (err, res, body) ->
statuses = JSON.parse(body)
if statuses.length > 0
status = msg.random statuses
cb status.text
imageMe = (msg, query, animated, cb) ->
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment