Last active
August 29, 2015 13:56
-
-
Save hara-y-u/9020805 to your computer and use it in GitHub Desktop.
進捗どうですか? on Hubot
This file contains hidden or 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
# 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