made polished, user friendly so it shouldn't be hard to use anymore #1
25
manager.js
25
manager.js
@ -9,8 +9,20 @@ String.prototype.capitalize = function() {
|
||||
return this[0].toUpperCase() + this.substring(1);
|
||||
};
|
||||
|
||||
//constantn'ts this is up here for scope reasons don't @ me
|
||||
var StatusCycleCount = 0;
|
||||
var OnlineServers = [];
|
||||
|
||||
//constants
|
||||
var MAX_IDLE_MINUTES = 60;
|
||||
var CMD_PREFIX = '%';
|
||||
const DEFAULT_STATUS = `${CMD_PREFIX}help`
|
||||
const STATUS_CYCLE = [
|
||||
"Servers running: " + OnlineServers.join(", "),
|
||||
|
||||
"%start <server> to start a server!",
|
||||
"servername.mc.jpdld.com!"
|
||||
];
|
||||
|
||||
|
||||
class MinecraftServer extends EventEmitter {
|
||||
constructor (cwd, jar) {
|
||||
@ -139,12 +151,14 @@ function commandHandler(input, priviledged) {
|
||||
if (!server) return `Unknown server ${serverName}`
|
||||
if (server.process) return `${serverName.capitalize()} server is already running.`;
|
||||
server.start();
|
||||
OnlineServers.push(serverName.capitalize());
|
||||
return `Starting ${serverName} server.`;
|
||||
} else if (cmd == "stop") {
|
||||
if (!priviledged) return unauthorized;
|
||||
if (!server) return `Unknown server ${serverName}`
|
||||
if (!server.process) return `${serverName.capitalize()} server is not running.`;
|
||||
server.stop();
|
||||
OnlineServers.splice(serverName.capitalize());
|
||||
return `Stopping ${serverName} server.`;
|
||||
} else if (cmd == "input") {
|
||||
if (!priviledged) return unauthorized;
|
||||
@ -191,10 +205,15 @@ if (process.env.DISCORD_TOKEN) {
|
||||
var dClient = new Discord.Client();
|
||||
dClient.login(process.env.DISCORD_TOKEN);
|
||||
dClient.on("error", error => console.error(colors.red("Discord client error: " + error.message)));
|
||||
function setStatus() {
|
||||
dClient.user.setActivity(`${CMD_PREFIX}help`);
|
||||
function setStatus(status) {
|
||||
dClient.user.setActivity(status);
|
||||
}
|
||||
setInterval(setStatus, 1000*60*30);
|
||||
//setInterval(setStatus, 1000*60*30);
|
||||
setInterval(() => {
|
||||
StatusCycleCount++;
|
||||
if (StatusCycleCount >= STATUS_CYCLE.length) count = 0;
|
||||
setStatus(`${DEFAULT_STATUS} | ${STATUS_CYCLE[StatusCycleCount]}`);
|
||||
}, 3500);
|
||||
dClient.on("ready", () => {
|
||||
console.log("Discord client is ready.".green);
|
||||
setStatus();
|
||||
|
Reference in New Issue
Block a user
bruh
Object.keys(servers).filter(name => servers[name].process)
and this won't work here anyway (it will always be blank)