forked from github/hubot-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chopapp.coffee
42 lines (37 loc) · 1.02 KB
/
chopapp.coffee
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
32
33
34
35
36
37
38
39
40
41
42
# Description:
# Return a link to your chopapp.com code
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot chop [me] [in] <language> <code> - Return a URL of your chopapp snippet (ruby, javascript, php, ...)
#
# Author:
# kristofbc
module.exports = (robot) ->
robot.respond /chop (me )?(in )?(\w+) (.*)$/i, (msg) ->
getUrl(msg)
getUrl = (msg) ->
lang = escape(msg.match[3])
code = escape(msg.match[4])
# Exceptions
if lang is 'javascript' or 'js'
lang = 'java_script' # whut
if lang is 'c++'
lang = 'c'
if lang is 'text'
lang = 'diff'
url = 'Drop+in+a+URL...' # default by chopapp
params = 'code=' + code + '&language=' + lang + '&url=' + url
msg.http('http://chopapp.com/code_snips')
.headers("Accept:": "*/*", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": params.length)
.post(params) (err, res, body) ->
if err
message.send "Does not compute"
else
response = JSON.parse body
msg.send "Here's your code: http://chopapp.com/#" + response.token