-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathircchannel.js
34 lines (30 loc) · 1.06 KB
/
ircchannel.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
var irc = require('irc');
var util = require('util');
var Bacon = require('baconjs').Bacon;
var EventEmitter = require('events').EventEmitter;
var Irc = function(url) {
var self = this;
this.imageUrlRegExp = /(f|ht)tps?:\/\/.+?(jpg|png)(\s|$)/gi;
this.client = new irc.Client('localhost', 'pixie', {
channels: ['#pixie']
});
var images = Bacon.fromEventTarget(self.client, 'message', function(from, to, message) {
return message;
}).filter(function(message) {
var isImage = self.imageUrlRegExp.test(message);
self.imageUrlRegExp.lastIndex = 0;
return isImage;
}).map(function(message) {
return message.match(self.imageUrlRegExp);
});
images.onValue(function(pics) {
pics.forEach(function(pic) {
console.log('pic: ' + pic)
self.emit('image', {
url: pic.trim()
});
})
});
}
util.inherits(Irc, EventEmitter);
exports.ircspider = Irc;