-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
44 lines (36 loc) · 1.16 KB
/
app.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
var fs = require('fs');
var irc = require('irc');
// Open config.json file
var config_output = fs.readFileSync('config.json', 'utf8', function (err) {
if (err) {
console.log('Error opening/reading config.json. Rename config-example.json to config.json to use.');
process.exit(1);
}
});
// Parse the config
config = JSON.parse(config_output);
['server', 'nick'].forEach(function(currentValue) {
if (! config[currentValue]) {
console.log('Missing config values, check your config.json');
process.exit(1);
}
});
var client = new irc.Client(config.server, config.nick, {
debug: false,
channels: config.channels
});
client.addListener('registered', function(message) {
// Stuff to do after connecting here
console.log('Connected to ' + message.server)
});
if (config.plugins) {
config.plugins.forEach(function(currentValue) {
require('./plugins/' + currentValue).run(client);
});
}
client.addListener('message', function(nick, channel, message) {
params = message.split(' ');
if (params[0] == '.commands') {
client.say(channel, 'Loaded commands: ' + config.plugins.join(' '));
}
});