mirror of
https://github.com/Expand-sys/ccashbot
synced 2025-12-16 23:52:14 +11:00
minecraft now spawnable as child process
This commit is contained in:
parent
682b741691
commit
af03536410
5 changed files with 99 additions and 9 deletions
|
|
@ -2,6 +2,7 @@ const fs = require("fs");
|
||||||
const got = require("got");
|
const got = require("got");
|
||||||
|
|
||||||
const { Rcon } = require("rcon-client");
|
const { Rcon } = require("rcon-client");
|
||||||
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "mc",
|
name: "mc",
|
||||||
|
|
@ -13,7 +14,7 @@ module.exports = {
|
||||||
return message.reply("OI you need to specify the command you want");
|
return message.reply("OI you need to specify the command you want");
|
||||||
} else {
|
} else {
|
||||||
const rcon = new Rcon({
|
const rcon = new Rcon({
|
||||||
host: "twix.aosync.me",
|
host: "mc.expand.gay",
|
||||||
port: 25575,
|
port: 25575,
|
||||||
password: "6pnyf2DsCfHV67d3",
|
password: "6pnyf2DsCfHV67d3",
|
||||||
});
|
});
|
||||||
|
|
|
||||||
47
commands/moderation/start.js
Normal file
47
commands/moderation/start.js
Normal 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}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
30
commands/moderation/stop.js
Normal file
30
commands/moderation/stop.js
Normal 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/",
|
||||||
|
};
|
||||||
|
}
|
||||||
16
index.js
16
index.js
|
|
@ -1,12 +1,24 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
const { Client, MessageAttachment, Collection } = require("discord.js");
|
const {
|
||||||
|
Client,
|
||||||
|
MessageAttachment,
|
||||||
|
Intents,
|
||||||
|
Collection,
|
||||||
|
} = require("discord.js");
|
||||||
const dotenv = require("dotenv");
|
const dotenv = require("dotenv");
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
const prefix = process.env.PREFIX;
|
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.commands = new Collection();
|
||||||
client.cooldowns = new Collection();
|
client.cooldowns = new Collection();
|
||||||
|
|
||||||
|
|
|
||||||
12
package-lock.json
generated
12
package-lock.json
generated
|
|
@ -2327,9 +2327,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/tar": {
|
"node_modules/tar": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz",
|
||||||
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==",
|
"integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chownr": "^2.0.0",
|
"chownr": "^2.0.0",
|
||||||
"fs-minipass": "^2.0.0",
|
"fs-minipass": "^2.0.0",
|
||||||
|
|
@ -4347,9 +4347,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tar": {
|
"tar": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz",
|
||||||
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==",
|
"integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"chownr": "^2.0.0",
|
"chownr": "^2.0.0",
|
||||||
"fs-minipass": "^2.0.0",
|
"fs-minipass": "^2.0.0",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue