This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
forked from martynsmith/node-irc
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
executable file
·46 lines (38 loc) · 1.17 KB
/
test.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
#!/usr/bin/env node
var irc = require('./lib/irc.js');
var util = require('util');
var color = require('ansi-color').set;
var ircServer = process.argv[2] || process.env.IRCSERVER || 'localhost';
console.log('Starting IRC connection to', ircServer, 'with REPL');
var c = new irc.Client(
ircServer,
'nodebot',
{
channels: ['#test'],
debug: true
}
);
var messages = [];
c.addListener('raw', function(message) { messages.push(message); });
c.addListener('unhandled', function(message) {
console.log(color('unhandled: ', 'red'), message);
});
c.addListener('error', function(message) { console.log(color('error: ', 'red'), message); });
function printRecent(number) {
number = number || 1;
var toPrint = messages.slice(messages.length-number, messages.length);
toPrint.forEach(function(message) {
console.log(message);
});
}
var repl = require('repl').start('> ');
repl.context.repl = repl;
repl.context.util = util;
repl.context.irc = irc;
repl.context.c = c;
repl.context.printRecent = printRecent;
repl.context.recent = printRecent;
repl.addListener('exit', function() {
console.log("\nClosing session");
c.disconnect('Closing session');
});