Skip to content
This repository has been archived by the owner. It is now read-only.
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (41 sloc) 1.18 KB
# Description:
# Allow Hubot to show what's lurking behind a CloudApp link
# Dependencies:
# None
# Configuration:
# None
# Commands:
#* - Detects the drop's type and displays it or prints its content if it's an image or text file respectively
# Author:
# lmarburger
module.exports = (robot) ->
robot.hear /(https?:\/\/\/image\/[A-Za-z0-9]+)(\/[^\/]+)?/i, (msg) ->
return if msg.match[2] # Ignore already embedded images.
link = msg.match[1]
.headers(Accept: "application/json")
.get() (err, res, body) ->
unless res.statusCode is 200
msg.send "No drop at #{link}! It may have been deleted."
drop = JSON.parse body
switch drop.item_type
when 'image'
msg.send drop.content_url
when 'text'
send_drop_content msg, drop.content_url
send_drop_content = (msg, url) ->
.get() (err, res, body) ->
if res.statusCode is 302
# Follow the breadcrumbs of redirects.
send_drop_content msg, res.headers.location
body += "\n" unless ~body.indexOf("\n")
msg.send body
You can’t perform that action at this time.