feat: Introduce role check and timer before server stop
All checks were successful
Publish staging Docker image / Push Docker image to Gitea Container Registry (push) Successful in 1m40s

This commit is contained in:
2024-03-03 15:10:08 +01:00
parent 320cdc2b14
commit a0656c5831
5 changed files with 59 additions and 9 deletions

View File

@ -29,12 +29,25 @@ module.exports = {
content: 'Are you sure you want to start the Minecraft server?',
components: [row]
})
// Before stop variable which return the time between now and 4am in discord timestamp
const date = new Date(new Date().setDate(new Date().getDate() + 1))
date.setUTCHours(3, 0, 0, 0)
const test = Math.round(date.getTime() / 1000);
const collectorFilter = i => i.user.id === interaction.user.id;
let allowed = false;
for (const role of config.allowedRoles) {
if (interaction.member.roles.cache.has(role)) {
allowed = true;
}
}
try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 30_000 });
if (confirmation.customId === 'confirm') {
proxmox.qemu.start("pve", "102", function(err, res) {
if (!allowed) {
await confirmation.update({ content: 'You do not have permission to start the Minecraft server.', components: [] });
return;
}
proxmox.qemu.start("pve", "103", function(err, res) {
if (err) {
confirmation.update("Error starting the Minecraft server: " + err);
} else {
@ -44,7 +57,7 @@ module.exports = {
.setURL('https://mc.louisgallet.fr')
const row = new ActionRowBuilder()
.addComponents(linkButton)
confirmation.update({content: "Minecraft server started successfully. Please wait a few minutes for it to boot.", components: [row]});
confirmation.update({content: "Minecraft server started successfully. Please wait a few minutes for it to boot. Use the command `/stop-mc` to stop it, otherwise, the server will be automatically shut down " + `<t:${test}:R>`, components: [row]});
}
})
} else if (confirmation.customId === 'cancel') {
@ -53,6 +66,5 @@ module.exports = {
} catch (e) {
await confirmation.update({ content: 'You took too long to respond.', components: [] });
}
}
}