All checks were successful
Publish staging Docker image / Push Docker image to Gitea Container Registry (push) Successful in 1m40s
71 lines
3.3 KiB
JavaScript
71 lines
3.3 KiB
JavaScript
const { ButtonBuilder, ButtonStyle, SlashCommandBuilder, ActionRow, ActionRowBuilder} = require('discord.js')
|
|
const config = require('../../config.json')
|
|
|
|
if (!config.proxmoxUser || !config.proxmoxPass || !config.proxmoxHostname) {
|
|
console.error("Proxmox credentials not found in config.json. Exiting.");
|
|
process.exit(1);
|
|
}
|
|
proxmox = require("proxmox")(config.proxmoxUser, config.proxmoxPass, config.proxmoxHostname);
|
|
|
|
module.exports = {
|
|
cooldowns: 60,
|
|
data: new SlashCommandBuilder()
|
|
.setName('start-mc')
|
|
.setDescription('Starts the minecraft server machine.'),
|
|
async execute(interaction) {
|
|
const confirm = new ButtonBuilder()
|
|
.setCustomId('confirm')
|
|
.setLabel('Confirm')
|
|
.setStyle(ButtonStyle.Primary)
|
|
const cancel = new ButtonBuilder()
|
|
.setCustomId('cancel')
|
|
.setLabel('Cancel')
|
|
.setStyle(ButtonStyle.Danger)
|
|
|
|
const row = new ActionRowBuilder()
|
|
.addComponents(cancel, confirm)
|
|
|
|
const response = await interaction.reply({
|
|
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') {
|
|
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 {
|
|
const linkButton = new ButtonBuilder()
|
|
.setStyle(ButtonStyle.Link)
|
|
.setLabel('Web Interface')
|
|
.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. 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') {
|
|
await confirmation.update({ content: 'Minecraft server start cancelled.', components: [] });
|
|
}
|
|
} catch (e) {
|
|
await confirmation.update({ content: 'You took too long to respond.', components: [] });
|
|
}
|
|
}
|
|
}
|