Skip to content

Commit 01710ea

Browse files
authored
Add files via upload
1 parent 01044b5 commit 01710ea

File tree

8 files changed

+1492
-1
lines changed

8 files changed

+1492
-1
lines changed

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker: node index.js

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# server-status-bot
1+
# spark-server-status

bot.js

+420
Large diffs are not rendered by default.

config.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"URL_SERVER": "",
3+
"SERVER_NAME": "Spark RP",
4+
"SERVER_LOGO": "",
5+
"EMBED_COLOR": "#00f931",
6+
"PERMISSION": "ADMINISTRATOR",
7+
"BOT_TOKEN": "",
8+
"CHANNEL_ID": "",
9+
"MESSAGE_ID": "",
10+
"SUGGESTION_CHANNEL": "",
11+
"BUG_CHANNEL": "",
12+
"BUG_LOG_CHANNEL": "",
13+
"LOG_CHANNEL": "",
14+
"DEBUG": false,
15+
"WEBSITE_URL": "",
16+
"RESTART_TIMES": "",
17+
"SHOW_PLAYERS": false // True = Show players on message ||| False Doesnt show players on message
18+
}

index.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const setup = require('./setup.js');
2+
const { start } = require('./bot.js');
3+
const chalk = require('chalk');
4+
5+
const printValues = function(values, text) {
6+
console.log(text ? text : 'Current values:');
7+
for (var key in values) {
8+
console.log(` ${key} = \x1b[32m'${values[key]}'\x1b[0m`);
9+
}
10+
}
11+
12+
const startBot = function(values) {
13+
console.log(`${chalk.bgBlue("[INFO]")} ${chalk.blue("Starting bot... this may take a few seconds to start...")}`);
14+
var bot = start(values);
15+
bot.on('restart',() => {
16+
console.log('\nRestarting bot');
17+
bot.destroy();
18+
bot = start(values);
19+
})
20+
var shutdown = function() {
21+
console.log(`${chalk.bgRed(`[STATUS]`)} ${chalk.red('Shutting down')}`);
22+
let destructor = bot.destroy();
23+
if (destructor) {
24+
destructor.then(() => {
25+
process.exit(0);
26+
}).catch(console.error);
27+
} else {
28+
process.exit(0);
29+
}
30+
}
31+
process.on('SIGINT', shutdown);
32+
process.on('SIGTERM', shutdown);
33+
}
34+
35+
if (process.argv.includes('-c') || process.argv.includes('--config')) {
36+
setup.loadValues().then((values) => {
37+
printValues(values);
38+
process.exit(0);
39+
}).catch((error) => {
40+
console.log('Unable to load saved values, reconfiguring all saved values again');
41+
setup.createValues().then((values) => {
42+
setup.saveValues(values).then(() => {
43+
printValues(values, 'New values:');
44+
process.exit(0);
45+
}).catch(console.error);
46+
}).catch(console.error);
47+
})
48+
} else {
49+
console.log(`${chalk.bold.bgYellow(`[LOAD]`)} ${chalk.bold.yellow('Attempting to load enviroment values...')}`);
50+
setup.loadValues().then((values) => {
51+
startBot(values);
52+
}).catch((error) => {
53+
console.error(error);
54+
setup.createValues().then((values) => {
55+
setup.saveValues(values).then(() => {
56+
startBot(values);
57+
}).catch(console.error);
58+
}).catch(console.error);
59+
})
60+
}

0 commit comments

Comments
 (0)