-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutalirc.js
109 lines (85 loc) · 2.12 KB
/
mutalirc.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var nwk = require('./network.js'),
cfg = require('./config.js'),
cmd = require('./commands.js'),
irc = require('./irc.js'),
log = require('./log.js'),
opt,
ignored = {};
cfg.read(init);
function ignoring(nickOrHostmask) {
return typeof ignored[nickOrHostmask] !== 'undefined';
}
function init(options) {
opt = options;
opt.ignore.forEach(function (nickOrHostmask) {
ignored[nickOrHostmask] = true;
});
log.setDir(opt.logDir);
nwk.connect(opt, react);
}
function react(data) {
var parsed = irc.process(data.toString(), opt),
resp = irc.outbound;
switch (parsed.ircCmd) {
case 'ping':
nwk.send(resp.pong(parsed.content));
log.debug({message: 'PONG: ' + parsed.content});
break;
case 'version':
nwk.send(resp.version(parsed.requester, opt.version));
log.debug({
message: 'Providing version information to: ' + parsed.requester
});
break;
case 'privmsg':
void function () {
var context = {
sender: parsed.sender,
hostmask: parsed.hostmask,
message: parsed.message,
dispatcher: 'query',
network: nwk,
options: opt
};
if (ignoring(parsed.sender) || ignoring(parsed.hostmask)) {
log.debug({
message: 'Ignoring query from ' + parsed.hostmask
});
return;
}
log.queryIn({
sender: context.sender,
message: context.message
});
cmd.dispatch(context);
}();
break;
case 'publicmsg':
void function () {
var context = {
sender: parsed.sender,
hostmask: parsed.hostmask,
channel: parsed.channel,
message: parsed.message,
dispatcher: 'public',
network: nwk,
options: opt
};
if (ignoring(parsed.sender) || ignoring(parsed.hostmask)) {
log.debug({
message: 'Ignoring message from ' + parsed.hostmask
});
return;
}
log.publicMsgIn({
message: context.message,
channel: context.channel,
sender: context.sender
});
cmd.dispatch(context);
}();
break;
default:
console.log('-- Undefined reaction.');
}
}