diff --git a/.env.example b/.env.example index 5459a00..bd02565 100644 --- a/.env.example +++ b/.env.example @@ -15,4 +15,9 @@ TRACKER_API_URL=YOUR_TRACKER_API_URL TRACKER_API_KEY=YOUR_TRACKER_API_KEY # Database -MONGODB_URI=YOUR_MONGODB_URI \ No newline at end of file +MONGODB_URI=YOUR_MONGODB_URI + +# RCON +RCON_HOST=your_rcon_host +RCON_PORT=your_rcon_port +RCON_PASSWORD=your_rcon_password \ No newline at end of file diff --git a/commands/minecraft/whitelist.js b/commands/minecraft/whitelist.js new file mode 100644 index 0000000..cfbaabe --- /dev/null +++ b/commands/minecraft/whitelist.js @@ -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." + ); + } + }, +}; diff --git a/package.json b/package.json index e0078ad..5629523 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "nodemailer": "^6.9.14", "owoify-js": "^2.0.0", "puppeteer": "^23.4.1", + "rcon-client": "^4.2.5", "uuid": "^11.0.0" } }