-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
162 lines (132 loc) · 5.41 KB
/
main.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* Discord Bot Mainframe
* @author AstroGD - https://www.astrogd.eu
* @since 2018-07-15
*/
const scriptName = 'main.js';
//Required Modules and Files
const Discord = require("discord.js");
const config = require(`${__dirname}/config/config.json`);
const fs = require("fs-extra");
const readline = require("readline");
const package = require(`${__dirname}/package.json`);
//Instances
const client = new Discord.Client();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.setPrompt("> ");
//Required Scripts
const tools = require(`${__dirname}/tools/tools.js`)(Discord, client, fs, __dirname);
//Module Definition
const discord_accept_rules_bot = require(`${__dirname}/modules/discord-accept-rules-bot.js`)(client, fs, tools, __dirname);
//Module Commands
async function command(cmd, args) {
let success = false;
if (await tools.command(cmd, args)) success = true;
if (await discord_accept_rules_bot.command(cmd, args)) success = true;
return success;
}
//Module Initialization
async function initialization() {
await discord_accept_rules_bot.init();
}
//DO NOT CHANGE THE CODE BELOW IF YOU DON'T KNOW WHAT YOU ARE DOING.
//
//
//CHANGING THE CODE COULD LEAD TO SECURITY ISSUES AND MALFUNCTION. DO NOT EVEN CHANGE SOMETHING IF SAID BY SOMEONE ELSE CLAIMING TO KNOW WHAT HE IS DOING!
//ONLY USE THE ORIGINAL DISCORD BOT MAINFRAME VERSION FROM ASTROGDs GITHUB REPOSITORY.
//
//
//IF YOU HAVE ANY QUESTIONS, FEEL FREE TO CONTACT ASTROGD:
// Mail: support@astrogd.eu
// Twitter: @astrogd
// Instagram: @astrogd
// Discord: https://go.astrogd.eu/discord (AstroGD#3416)
//
//
//THE CODE BELOW MAY ONLY BE CHANGED TO UPDATE THE DISCORD BOT MAINFRAME. IF THERE IS AN UPDATE AVAILABLE, YOU WILL GET A MESSAGE IN THE CONSOLE.
//FOR MORE INFOS ON HOW TO UPDATE, CHECK ASTROGDs REPOSITORY
//Initialization
async function init() {
try {
await tools.init();
} catch (e) {
console.log(`An error occurred during the initialization: ${e.stack}`);
process.exit();
return;
}
tools.log(scriptName, "Scripts initialized - Getting version information");
global.VERSIONINFO = await tools.checkVersion();
if (!VERSIONINFO) {
tools.log(scriptName, "Version couldn't be fetched. Make sure you have a connection to the internet and access to software.astrogd.eu", 1);
} else {
if (tools.isVersionLower(VERSIONINFO.version, package.version)) tools.log(scriptName, `Theres a new version available for Discord accept rules bot by AstroGD (${package.version} --> ${VERSIONINFO.version})`, 2);
}
tools.log(scriptName, "Logging in...");
try {
await client.login(config.token);
} catch (e) {
tools.log(scriptName, `Authentication failed: ${e.message}`);
process.exit();
return;
}
}
async function checkVersion() {
VERSIONINFO = await tools.checkVersion();
if (!VERSIONINFO) {
tools.log(scriptName, "Version couldn't be fetched. Make sure you have a connection to the internet and access to software.astrogd.eu", 1);
return false;
}
let newVerAvailable = false;
if (tools.isVersionLower(VERSIONINFO.version, package.version)) {
tools.log(scriptName, `Theres a new version available for Discord accept rules bot by AstroGD (${package.version} --> ${VERSIONINFO.version})`, 2);
newVerAvailable = true;
}
return newVerAvailable;
}
client.on(`ready`, async () => {
tools.log(scriptName, `Setup completed. Connected to ${client.user.tag} (${client.user.id})`);
try {
await initialization();
} catch (e) {
tools.log(scriptName, `Initalization failed: ${e.stack}`, 1);
client.destroy().then(() => {
process.exit();
});
return;
}
tools.log(scriptName, "All modules were successfully initialized");
setInterval(checkVersion, 1*60*60*1000);
rl.prompt(true);
});
rl.on("line", async (input) => {
rl.pause();
let cmd = input.split(" ")[0].toLowerCase();
let args = input.split(" ").slice(1);
tools.logFile(scriptName, `Command recieved: ${input}`);
let success = await command(cmd, args);
switch (cmd) {
case "shutdown":
console.log(`Shutting down...`);
client.destroy();
process.exit();
case "help":
console.log(`===== Discord Bot Mainframe Commands\n\nshutdown: Deactivates all correctly installed Modules and shuts the bot down\ncheckversion: Checks if there is a new version available\nhelp: Displays all commands available from Modules or Mainframe\nreloaddb: Reloads Database. Use only if changes were made manually\nreloadconfig: Reloads Config. Use only if changes were made manually\n\n=====`);
break;
case "checkversion":
if (!await checkVersion()) console.log("Everythings up to date!");
break;
default:
if (!success) {
console.log(`${cmd}: The input "${cmd}" was not being recognized as a command. Please check your spelling or type "help" for a list of possible commands. Also check, if module commands were correctly installed.`);
tools.logFile(scriptName, `Unknown Command`);
}
break;
}
rl.prompt();
});
rl.pause();
console.log(`Starting ${scriptName} V${package.version}...`);
init();