minecraft: add whitelist command

This commit is contained in:
Ayden Jahola 2025-02-18 13:35:29 +00:00
parent 7d8e76f875
commit 647d57fe82
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742
3 changed files with 56 additions and 1 deletions

View file

@ -16,3 +16,8 @@ TRACKER_API_KEY=YOUR_TRACKER_API_KEY
# Database # Database
MONGODB_URI=YOUR_MONGODB_URI MONGODB_URI=YOUR_MONGODB_URI
# RCON
RCON_HOST=your_rcon_host
RCON_PORT=your_rcon_port
RCON_PASSWORD=your_rcon_password

View file

@ -0,0 +1,49 @@
const { SlashCommandBuilder } = require("discord.js");
const { Rcon } = require("rcon-client");
module.exports = {
data: new SlashCommandBuilder()
.setName("whitelist")
.setDescription("Auto-whitelist a user on the Minecraft server")
.addStringOption((option) =>
option
.setName("username")
.setDescription("The Minecraft username to whitelist")
.setRequired(true)
),
isModOnly: true,
async execute(interaction) {
const username = interaction.options.getString("username");
await interaction.deferReply();
try {
// committee only for now, remove once opened to public
if (
!interaction.member.permissions.has(PermissionFlagsBits.ManageGuild)
) {
await interaction.reply({
content: "You do not have permission to use this command!",
ephemeral: true,
});
return;
}
const rcon = new Rcon({
host: process.env.RCON_HOST,
port: Number(process.env.RCON_PORT),
password: process.env.RCON_PASSWORD,
});
await rcon.connect();
const response = await rcon.send(`whitelist add ${username}`);
await rcon.end();
await interaction.editReply(`RCON Response: ${response}`);
} catch (error) {
console.error("RCON Error:", error);
await interaction.editReply(
"There was an error executing the whitelist command."
);
}
},
};

View file

@ -21,6 +21,7 @@
"nodemailer": "^6.9.14", "nodemailer": "^6.9.14",
"owoify-js": "^2.0.0", "owoify-js": "^2.0.0",
"puppeteer": "^23.4.1", "puppeteer": "^23.4.1",
"rcon-client": "^4.2.5",
"uuid": "^11.0.0" "uuid": "^11.0.0"
} }
} }