diff options
author | lassulus <lassulus@googlemail.com> | 2014-03-17 01:35:06 +0100 |
---|---|---|
committer | lassulus <lassulus@googlemail.com> | 2014-03-17 01:35:06 +0100 |
commit | e653d6c832f8fce5937fb782286fd5856e21b204 (patch) | |
tree | 47d20dfb6e7c60dced14dea81ee22b9758068b70 /news | |
parent | 45dae6eb0ac52a2eee2e24b0bfb553a0d7371a2e (diff) |
newsboss.js: url shortening ftw
Diffstat (limited to 'news')
-rw-r--r-- | news/newsbot.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/news/newsbot.js b/news/newsbot.js index 18a7fb07..499f595a 100644 --- a/news/newsbot.js +++ b/news/newsbot.js @@ -3,12 +3,16 @@ var FeedParser = require('feedparser') var Request = require('request') var Parse = require('shell-quote').parse var FS = require('fs') +var HTTP = require('http') +var FormData = require('form-data') +var URL = require('url') var irc_server = 'ire.retiolum' var master_nick = 'knews' var news_channel = '#news' var feeds_file = 'new_feeds' var feedbot_loop_delay = 60 * 1000 // [ms] +var url_shortener_host = 'go' var slaves = {} @@ -192,7 +196,26 @@ function run_command (methodname, params, callback) { } function getShortLink (link, callback) { - return callback(null, link) + var form = new FormData() + form.append('uri', link) + + var request = HTTP.request({ + method: 'post', + host: url_shortener_host, + path: '/', + headers: form.getHeaders(), + }) + form.pipe(request) + + request.on('response', function (response) { + var data = '' + response.on('data', function (chunk) { + data += chunk + }) + response.on('end', function () { + callback(null, data.replace(/\r\n$/,'') + '#' + URL.parse(link).host) + }) + }) } var methods = {} |