This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
app.js
67 lines (51 loc) · 1.65 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
62
63
64
65
66
67
/**
* App
* Cassius - https://github.com/sirDonovan/Cassius
*
* This is the main file that starts Cassius.
*
* @license MIT license
*/
'use strict';
const fs = require('fs');
global.Tools = require('./tools.js');
try {
fs.accessSync('./config.js');
} catch (e) {
if (e.code !== 'ENOENT') throw e;
console.log("Creating a default config.js file");
fs.writeFileSync('./config.js', fs.readFileSync('./config-example.js'));
}
// @ts-ignore
global.Config = require('./config.js');
if (!Config.username) throw new Error("Please specify a username in config.js");
global.Commands = require('./commands.js');
global.Rooms = require('./rooms.js').Rooms;
global.Users = require('./users.js').Users;
global.MessageParser = require('./message-parser.js').MessageParser;
global.Client = require('./client.js');
global.Tournaments = require('./tournaments');
global.Games = require('./games.js');
global.Storage = require('./storage.js');
Storage.importDatabases();
Storage.globalDatabase = Storage.getDatabase('global');
let pluginsList;
let plugins = fs.readdirSync('./plugins');
for (let i = 0, len = plugins.length; i < len; i++) {
let fileName = plugins[i];
if (!fileName.endsWith('.js') || fileName === 'example-commands.js' || fileName === 'example-module.js') continue;
if (!pluginsList) pluginsList = [];
let file = require('./plugins/' + fileName);
if (file.name) {
// @ts-ignore
global[file.name] = file;
if (typeof file.onLoad === 'function') file.onLoad();
}
if (file.commands) Object.assign(Commands, file.commands);
pluginsList.push(file);
}
global.Plugins = pluginsList;
if (require.main === module) {
Games.loadGames();
Client.connect();
}