-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (49 loc) · 1.38 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* App
* Cassius - https://github.com/sirDonovan/Cassius
*
* This is the main file that starts Cassius.
*
* @license MIT license
*/
'use strict';
const fs = require('fs');
const path = require('path');
global.Tools = require('./tools.js');
try {
require.resolve('./config.js');
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') throw e;
console.log("Creating a default config file");
fs.writeFileSync(path.resolve(__dirname, 'config.js'),
fs.readFileSync(path.resolve(__dirname, 'config-example.js'))
);
} finally {
global.Config = require('./config.js');
}
if (!Config.username) throw new Error("Please specify a username in config.js");
let commands = require('./commands.js');
let plugins;
try {
plugins = fs.readdirSync('./plugins');
} catch (e) {}
if (plugins) {
for (let i = 0, len = plugins.length; i < len; i++) {
let file = plugins[i];
if (!file.endsWith('.js')) continue;
file = require('./plugins/' + file);
if (file.name) {
global[file.name] = file;
if (typeof global[file.name].onLoad === 'function') global[file.name].onLoad();
}
if (file.commands) Object.assign(commands, file.commands);
}
}
global.Commands = commands;
global.CommandParser = require('./command-parser.js');
global.Rooms = require('./rooms.js');
global.Users = require('./users.js');
global.Client = require('./client.js');
if (require.main === module) {
Client.connect();
}