minecraft now spawnable as child process

This commit is contained in:
Expand-sys 2021-10-06 15:50:56 +11:00
parent 682b741691
commit af03536410
5 changed files with 99 additions and 9 deletions

View file

@ -2,6 +2,7 @@ const fs = require("fs");
const got = require("got");
const { Rcon } = require("rcon-client");
const { spawn } = require("child_process");
module.exports = {
name: "mc",
@ -13,7 +14,7 @@ module.exports = {
return message.reply("OI you need to specify the command you want");
} else {
const rcon = new Rcon({
host: "twix.aosync.me",
host: "mc.expand.gay",
port: 25575,
password: "6pnyf2DsCfHV67d3",
});

View file

@ -0,0 +1,47 @@
const fs = require("fs");
const got = require("got");
const { spawn } = require("child_process");
let minecraftin;
module.exports = {
name: "start",
description: "start mc server",
guildOnly: true,
permissions: "KICK_MEMBERS",
async execute(message, args) {
let channel = message.guild.channels.cache.get(process.env.CONSOLECHAN);
spawnMC(channel);
},
};
function spawnMC(channel) {
let options = {
shell: true,
cwd: "~/minecraft/",
};
const minecraft = spawn(
"java",
["-Xmx4096M", "-Xms1024M", "-jar", "server.jar", "nogui"],
options
);
minecraftin = minecraft;
minecraft.stdout.on("data", (data) => {
try {
channel.send(`${data}`);
} catch (err) {
console.log(err);
}
});
minecraft.stderr.on("data", (data) => {
try {
channel.send(`${data}`);
} catch (err) {
console.log(err);
}
});
minecraft.on("close", (code) => {
console.log(`child process exited with code ${code}`);
});
}

View file

@ -0,0 +1,30 @@
const fs = require("fs");
const got = require("got");
const { Rcon } = require("rcon-client");
const { spawn } = require("child_process");
let minecraftin;
module.exports = {
name: "stop",
description: "stop mc server",
guildOnly: true,
permissions: "KICK_MEMBERS",
async execute(message, args) {
const rcon = new Rcon({
host: "mc.expand.gay",
port: 25575,
password: "6pnyf2DsCfHV67d3",
});
await rcon.connect();
let res = await rcon.send(`/stop`);
message.reply(`Server stopped Safely`);
},
};
function spawnMC(channel) {
let options = {
detached: true,
shell: true,
cwd: "/home/harrison/Desktop/minecraft/",
};
}

View file

@ -1,12 +1,24 @@
const fs = require("fs");
const fetch = require("node-fetch");
const { Client, MessageAttachment, Collection } = require("discord.js");
const {
Client,
MessageAttachment,
Intents,
Collection,
} = require("discord.js");
const dotenv = require("dotenv");
dotenv.config();
const prefix = process.env.PREFIX;
const client = new Client();
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_PRESENCES,
],
});
client.commands = new Collection();
client.cooldowns = new Collection();

12
package-lock.json generated
View file

@ -2327,9 +2327,9 @@
}
},
"node_modules/tar": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==",
"version": "6.1.11",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz",
"integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==",
"dependencies": {
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
@ -4347,9 +4347,9 @@
}
},
"tar": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==",
"version": "6.1.11",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz",
"integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==",
"requires": {
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",