-
Notifications
You must be signed in to change notification settings - Fork 0
/
lugbot.js
32 lines (29 loc) · 950 Bytes
/
lugbot.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
var cheerio = require('cheerio');
var irc = require('irc');
var Pinboard = require('node-pinboard');
var request = require('request');
var twitter = require('twitter-text');
var CHAN = '#utdlug' + (process.argv[3] ? 'testing' : '');
var bot = new irc.Client('irc.oftc.net', 'utdlug', {channels: [CHAN]});
var pinboard = new Pinboard(process.argv[2]);
bot.addListener('message', function(from, to, msg) {
twitter.extractUrls(msg).map(function(url) {
try {
if (url.substring(0, 4) != 'http') {
url = 'http://' + url;
};
request(url, function(err, res, body) {
pinboard.add({
url: url,
description: cheerio.load(body || '')('title').text() || url,
tags: ['by:' + from].concat(twitter.extractHashtags(msg)).join(','),
replace: 'no',
}, function(res) {
console.log(res);
})
});
} catch(e) {
console.log(e);
};
});
});