Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 32 lines (28 sloc) 1.15 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# Description:
# Capture a webpage as an image using the bluga.net Easythumb API. API user and key needed from http://webthumb.bluga.net/api
#
# Dependencies:
# "hashlib": "1.0.1"
#
# Configuration:
# HUBOT_WEBTHUMB_USER
# HUBOT_WEBTHUMB_API_KEY
#
# Commands:
# hubot webshot me <url> - Captures the given url as an image.
#
# Author:
# carsonmcdonald

hashlib=require('hashlib')

module.exports = (robot) ->
  robot.respond /webshot( me)? (.*)/i, (msg) ->
    if process.env.HUBOT_WEBTHUMB_USER and process.env.HUBOT_WEBTHUMB_API_KEY
      url = msg.match[2]
      console.log(url)
      msg.send 'http://webthumb.bluga.net/easythumb.php?user=' + process.env.HUBOT_WEBTHUMB_USER + '&url=' + encodeURIComponent(url) + '&size=large&hash=' + webthumbhash(process.env.HUBOT_WEBTHUMB_API_KEY, url) + '&cache=14#.jpeg'

webthumbhash = (apikey, url) =>
  now = new Date
  now = new Date(now.getTime() - (now.getTimezoneOffset() * 1000))
  month = (now.getUTCMonth() < 9 ? '0' : '') + (now.getUTCMonth()+1)
  day = (now.getUTCDate() < 10 ? '0' : '') + now.getUTCDate()
  hashlib.md5(now.getUTCFullYear().toString() + month + day + url + apikey)
Something went wrong with that request. Please try again.