Skip to content

Instantly share code, notes, and snippets.

@fukayatsu
Created March 1, 2013 14:50
Show Gist options
  • Select an option

  • Save fukayatsu/5065136 to your computer and use it in GitHub Desktop.

Select an option

Save fukayatsu/5065136 to your computer and use it in GitHub Desktop.
みつをる(縦書ジェネレータ) for hipchat
# Description:
# みつをる(縦書ジェネレータ) - http://mitsuwo.net/
#
# Commands:
# hubot mitsuwo [body],[author]
# hubot mitsuwo 寿司が<br>食べたいのです,名無し
request = require('request') # add `"request": "2.14.x"` to package.json
module.exports = (robot) ->
robot.respond /mits?uw?o ([^,]+),(.+)/i, (msg) ->
body = msg.match[1].replace(/<br>/g, "\r\n")
author = msg.match[2]
params = {card: {author: author, body: body}}
request.post {
headers: {'content-type' : 'application/x-www-form-urlencoded'},
url: 'http://mitsuwo.net/cards',
body: "card[author]=#{author}&card[body]=#{body}"
}, (error, res, body) ->
status = res.statusCode
if status == 302
url = res.headers.location
request.get { url: "#{url}.json", json: true }, (error, res, card) ->
msg.send url
msg.send card.image
else
msg.send "なんかおかしいっぽい(#{status})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment