Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (40 sloc) 1.475 kb
# Description:
# Pulls a movie gif from the best tumblog
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_TUMBLR_API_KEY - A Tumblr OAuth Consumer Key will work fine
#
# Commands:
# hubot movie me - Displays a moving still from IWDRM
#
# Author:
# iangreenleaf
module.exports = (robot) ->
robot.respond /(movie|iwdrm)( me)?( .*)/i, (msg) ->
tumblr_request = (offset, success) ->
params = { api_key: process.env.HUBOT_TUMBLR_API_KEY, limit: 1, offset: offset }
msg.http('http://api.tumblr.com/v2/blog/iwdrm.tumblr.com/posts/photo')
.query(params)
.get() (err, res, body) ->
if err
robot.logger.error err
else if res.statusCode != 200
robot.logger.error "Received status code #{res.statusCode}."
else
success JSON.parse(body)
clean_quotes = (text) ->
for entity,replacement of { "&#822[01];": '"', "’": "'", "…": "--" }
text = text.replace RegExp(entity, "g"), replacement
text
tumblr_request 0, (data) ->
total_posts = data.response.total_posts
offset = Math.round((total_posts - 1) * Math.random())
tumblr_request offset, (data) ->
post = data.response.posts.pop()
msg.send post.photos.pop().original_size.url
quote = clean_quotes /<i>(.*?)<\/i>/.exec(post.caption)[1]
title = /<a [^>]*imdb.com[^>]*>(.*?)<\/a>/.exec(post.caption)[1]
msg.send "#{quote} #{title}"
Jump to Line
Something went wrong with that request. Please try again.