-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.js
57 lines (45 loc) · 1.71 KB
/
main.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
var fs = require('fs');
var config = require('./botconfig/default');
if (fs.existsSync('./botconfig/local.js')) {
var localConfig = require('./botconfig/local');
for (i in localConfig) {
config[i] = localConfig[i];
}
}
////////////////////////////////////////////////////////////////////
////////////////////////////// LISTENERS ///////////////////////////
////////////////////////////////////////////////////////////////////
var logSave = function(hash) {
hash.time = new Date;
config.logs.save(hash, {w: 0});
}
config.client.addListener('message', function (nick, to, text, message) {
logSave({type: 'message', nick: nick, text: text});
// Send Push notification to iPhone and HipChat:
if (text.toLowerCase().indexOf('mongo') !== -1) {
if (config.hipchat) {
config.hipchat.postMessage({room: 'reaaad', from: 'irclogs', message: nick+': '+text, color: 'gray'});
}
if (config.pushover) {
config.pushover.send("irclogs", text);
}
}
});
config.client.addListener('join', function (channel, nick, message) {
logSave({type: 'join', nick: nick});
});
config.client.addListener('part', function (channel, nick, reason, message) {
logSave({type: 'part', nick: nick, reason: reason});
});
config.client.addListener('quit', function (nick, reason, channels, message) {
logSave({type: 'quit', nick: nick, reason: reason});
});
////////////////////////////////////////////////////////////////////
/////////////////////////// ERROR HANDLING /////////////////////////
////////////////////////////////////////////////////////////////////
config.client.addListener('error', function(message) {
console.error('error: ', message);
});
config.client.addListener('raw', function(message) {
console.info('raw: ', message);
});