-
Notifications
You must be signed in to change notification settings - Fork 5
/
xdcctest.js
54 lines (43 loc) · 1.38 KB
/
xdcctest.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
47
48
49
50
51
52
53
54
var irc = require('xdcc').irc;
var ProgressBar = require('progress');
var progress;
var connectIRC = function (bot, pack) {
var user = 'desu' + Math.random().toString(36).substr(7, 3);
var start = 0;
console.log('Connecting...');
var client = new irc.Client('irc.rizon.net', user, {
channels: ['#nibl'],
userName: user,
realName: user
});
client.on('join', function(channel, nick, message) {
if (nick !== user) return;
console.log('Joined', channel);
client.getXdcc(bot, 'xdcc send #' + pack, '.');
});
client.on('xdcc-connect', function(meta) {
console.log('Connected: ' + meta.ip + ':' + meta.port);
progress = new ProgressBar('Downloading... [:bar] :percent, :etas remaining', {
incomplete: ' ',
total: meta.length,
width: 20
});
});
var last = 0;
client.on('xdcc-data', function(received) {
progress.tick(received - last);
last = received;
});
client.on('xdcc-end', function(received) {
console.log('Download completed');
});
client.on('notice', function(from, to, message) {
if (to == user && from == bot) {
console.log("[notice]", message);
}
});
client.on('error', function(message) {
console.error(message);
});
};
module.exports.connectIRC = connectIRC;