-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbot-dpaste.js
46 lines (37 loc) · 1013 Bytes
/
dbot-dpaste.js
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
43
44
45
46
var deferred = require('deferred')
, http = require('follow-redirects').http
, qs = require('qs');
module.exports = {
description: 'Saves the given content and gives you an URL',
regex: /^dpaste (.+)$/,
callback: function(matches) {
var d = deferred()
, data = qs.stringify({
paste: matches[1]
})
, params = {
host: 'dpaste.cc',
port: 80,
method: 'POST',
path: '/paste/new',
headers: {
'User-Agent': 'curl',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
}
}
, req = http.request(params, function (res) {
res.setEncoding('utf8');
var buffer = '';
res.on('data', function (chunk) {
buffer += chunk;
});
res.on('end', function () {
d.resolve(buffer);
});
});
req.write(data);
req.end();
return d.promise;
}
};