This repository has been archived by the owner on Feb 13, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (67 loc) · 3.53 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//export default
class Dashboard {
constructor (client, config, oAuth) {
this.constructor.validate(client, config);
this.client = client;
this.config = {
//Required Config Items:
clientSecret: /*oAuth.secret ||*/ config.clientSecret,
redirectURI: config.redirectURI,
//Not required config items
port: config.port || 8080,
maintenanceNotification: config.maintenanceNotification || false,
baseGame: config.baseGame || "!help | v0.0.6.3",
baseBotStatus: config.baseBotStatus || "online",
maintenanceGame: config.maintenanceGame || "Bot is in maintenance",
maintenanceStatus: config.maintenanceStatus || "dnd",
};
}
run () {
const client = this.client;
const config = this.config;
return new Promise(function(resolve, reject) {
try {
require('./modules/app').run(client, config); //Runs webserver
require("./modules/events")(client); //Runs live bot stats using events
// if (config.enableLogs) {
// require("./modules/resourceCheck")(config.logFolderPath); //Runs resource logging for stats in dashbaord
// }
resolve();
} catch (error) {
reject(error);
}
});
}
SQLiteProvider (db) {
if (!db) throw new Error("Database file not specified for dashboard");
if (!db.name) throw new Error("Are you sure you are using \"better-sqlite3\" and/or specifed the database file?");
//...
//Will handle rest of databse stuff
}
static validate (client, config) {
//Check client
if (!client) throw new Error("Client must be specified");
//Check config type
if (typeof config !== "object") throw new Error("The config must be an object");
//Check for and type of required config items
if (!config.clientSecret) throw new Error("The config item 'clientSecret' must be specified");
if (typeof config.clientSecret !== "string") throw new Error("The config item 'clientSecret' must be a string");
//Check datatypes for rest of config items
if (config.port && typeof config.port !== "number") throw new TypeError("The config item 'port' must be a number");
if (config.maintenanceNotification && typeof config.maintenanceNotification !== "boolean") throw new TypeError("The config item 'maintenanceNotification' must be a boolean");
if (config.baseGame && typeof config.baseGame !== "string") throw new TypeError("The config item 'baseGame' must be a string");
if (config.baseBotStatus && typeof config.baseBotStatus !== "string") throw new TypeError("The config item 'baseBotStatus' must be a string");
if (config.maintenanceGame && typeof config.maintenanceGame !== "string") throw new TypeError("The config item 'maintenanceGame' must be a string");
if (config.maintenanceStatus && typeof config.maintenanceStatus !== "string") throw new TypeError("The config item 'maintenanceStatus' must be a string");
if (config.redirectURI && typeof config.redirectURI !== "string") throw new TypeError("The config item 'redirectURI' must be a string");
}
}
function CreateRedirectURI (port = 8080, hostName = "localhost") {
const uri = `http://${hostName}:${port}/auth/discord/callback`;
return uri;
}
/*module.exports = {
Dashboard,
CreateRedirectURI
};*/
module.exports = Dashboard