-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·128 lines (112 loc) · 3.95 KB
/
Copy pathmain.js
File metadata and controls
executable file
·128 lines (112 loc) · 3.95 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const irc = require('irc-upd');
const fs = require('fs');
const macroPath = '/simojs-data/macros.js'
const features = require('./features/index.js').enabledFeatures;
var commands = features.commands;
var inits = features.inits;
var regexes = features.regexes;
var settings = fs.readFileSync('/simojs-data/settings.json');
settings = JSON.parse(settings);
const TimerPoller = require('./lib/timerpoller').TimerPoller;
const MultiCommand = require('./lib/multicommand').MultiCommand;
const UrlTitle = require('./lib/urltitle').UrlTitle;
var config = {
server: settings.general.server,
channels: settings.general.channels,
botnick: settings.general.botnick,
username: settings.general.username,
password: settings.general.password,
port: settings.general.port,
websocketport: settings.general.websocketport,
wpuser: settings.wordpress.username,
wppass: settings.wordpress.password,
mailFileUrl: settings.email.fileUrl,
mailFilePath: settings.email.filePath,
};
var client = new irc.Client(config.server, config.botnick, {
debug: true,
showErrors: true,
channels: config.channels,
port: config.port,
autoConnect: true,
password: config.password,
userName: config.username,
millisecondsOfSilenceBeforePingSent: 30 * 1000,
millisecondsBeforePingTimeout: 120 * 1000
});
client.addListener('raw', function(message) {
console.log(message);
});
client.addListener('error', function(message) {
console.log('error: ', message);
});
console.log("Starting feature initialization")
for (var init in inits) {
inits[init](config, client);
console.log(init + " initialized");
}
console.log("All features initialized");
var multicommand = new MultiCommand(commands, 100);
var urltitle = new UrlTitle();
client.addListener('message', function(from, to, message) {
var msg = message.toLowerCase();
//In case of a query, send the msg to the querier instead of ourselves
if (to.indexOf("#") === -1) {
to = from;
}
// Enough of this shit
if (from == config.botnick) {
return;
}
try {
Object.keys(regexes).forEach(function(key) {
for (var i = 0; i < regexes[key].length; i++) {
regexes[key][i](client, to, from, message);
}
});
} catch (err) {
console.log(err);
}
try {
if (msg.indexOf('!') !== 0) {
urltitle.getTitle(message, function(title) {
if (!title) {
return;
}
client.say(to, title);
});
} else {
// expand user hypermacros (!*name) if present
if (~message.indexOf('!*')) {
const macroFile = fs.readFileSync(macroPath);
macros = JSON.parse(macroFile);
message = macrofy(message, 0);
function macrofy(msg, depth) {
if (depth > 100) return "stack level too deep, giving up"
if (!~msg.indexOf('!*')) return msg
return macrofy(msg.split(' ').map(word => {
const cmd = word.slice(1)
return cmd.indexOf('*') === 0 ?
macros.hasOwnProperty(cmd) ?
macros[cmd].split(' ').map(macro =>
macros.hasOwnProperty(macro) ? '!' + macro : macro
).join(' ') :
`{Unknown hypermacro: ${cmd}}` :
word
})
.join(' '), depth + 1)
}
}
multicommand.exec(to, from, message, function(result) {
if (!result)
return;
client.say(to, result.substring(0, 400));
});
}
} catch (err) {
console.log(err);
}
});
client.connect(function() {
new TimerPoller(client, 30);
});