Skip to content

Instantly share code, notes, and snippets.

@yukihr
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukihr/9020805 to your computer and use it in GitHub Desktop.
Save yukihr/9020805 to your computer and use it in GitHub Desktop.
進捗どうですか? on Hubot
# put in scripts/shinchoku.coffee
# add "tumblr": "~0.4.0" on package.json -> "dependencies"
tumblr = require 'tumblr'
util = require 'util'
auth =
# Set these on environment variables
consumer_key: process.env['TUMBLR_CONSUMER_KEY']
consumer_secret: process.env['TUBMLR_CONSUMER_SECRET']
token: process.env['TUMBLR_TOKEN']
token_secret: process.env['TUBMLR_TOKEN_SECRET']
blog = new tumblr.Blog('shinchokudodesuka.tumblr.com', auth)
module.exports = (robot) ->
robot.respond /shinchoku$/i, (msg) ->
blog.info (err, res) ->
if err
msg.send util.inspect(err)
else
total_posts = res.blog.posts
post = Math.floor(Math.random() * total_posts + 1)
blog.posts
limit: 1
offset: post
, (err, res) ->
if err
msg.send util.inspect(err) if err
else
post = res.posts[0]
switch post.type
when 'photo'
msg.send post.photos[0].original_size.url
else msg.send "Don't know how to handle type:#{post.type}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment