From 1bfc619cc62712dfb11a0298ea61df04a573a3a9 Mon Sep 17 00:00:00 2001 From: Louis Gallet Date: Sun, 3 Mar 2024 21:04:26 +0100 Subject: [PATCH] style: :rotating_light: Fix linter problem --- commands/server/start-mc.js | 92 +++++++++++++++++---------------- commands/server/stop-mc.js | 27 +++++----- commands/utility/check-perms.js | 30 +++++------ commands/utility/test-time.js | 22 ++++---- 4 files changed, 88 insertions(+), 83 deletions(-) diff --git a/commands/server/start-mc.js b/commands/server/start-mc.js index 0280084..368f0ce 100644 --- a/commands/server/start-mc.js +++ b/commands/server/start-mc.js @@ -6,7 +6,7 @@ if (!config.proxmoxUser || !config.proxmoxPass || !config.proxmoxHostname) { process.exit(1); } // eslint-disable-next-line no-undef -proxmox = require('proxmox')(config.proxmoxUser, config.proxmoxPass, config.proxmoxHostname); +const proxmox = require('proxmox')(config.proxmoxUser, config.proxmoxPass, config.proxmoxHostname); module.exports = { cooldowns: 60, @@ -25,46 +25,50 @@ module.exports = { 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) { - 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 " + ``, 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: [] }); - } - } -} \ No newline at end of file + 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) { + 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 row2 = 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 ' + ``, components: [row2] }); + } + }); + } + else if (confirmation.customId === 'cancel') { + await confirmation.update({ content: 'Minecraft server start cancelled.', components: [] }); + } + } + catch (e) { + // eslint-disable-next-line no-undef + await confirmation.update({ content: 'You took too long to respond.', components: [] }); + } + }, +}; \ No newline at end of file diff --git a/commands/server/stop-mc.js b/commands/server/stop-mc.js index fbf1c89..6c5c110 100644 --- a/commands/server/stop-mc.js +++ b/commands/server/stop-mc.js @@ -8,16 +8,17 @@ if (!config.proxmoxUser || !config.proxmoxPass || !config.proxmoxHostname) { const proxmox = require('proxmox')(config.proxmoxUser, config.proxmoxPass, config.proxmoxHostname); module.exports = { - data: new SlashCommandBuilder() - .setName('stop-mc') - .setDescription('Stops the minecraft server machine.'), - async execute(interaction) { - proxmox.qemu.shutdown("pve", "103", function(err, res) { - if (err) { - interaction.reply("Error starting the Minecraft server: " + err); - } else { - interaction.reply("Minecraft server stopped successfully."); - } - }) - } -} \ No newline at end of file + data: new SlashCommandBuilder() + .setName('stop-mc') + .setDescription('Stops the minecraft server machine.'), + async execute(interaction) { + proxmox.qemu.shutdown('pve', '103', function(err) { + if (err) { + interaction.reply('Error starting the Minecraft server: ' + err); + } + else { + interaction.reply('Minecraft server stopped successfully.'); + } + }); + }, +}; \ No newline at end of file diff --git a/commands/utility/check-perms.js b/commands/utility/check-perms.js index 4ff3080..81cf597 100644 --- a/commands/utility/check-perms.js +++ b/commands/utility/check-perms.js @@ -1,17 +1,17 @@ -const { SlashCommandBuilder } = require('discord.js') -const config = require('../../config.json') +const { SlashCommandBuilder } = require('discord.js'); +const config = require('../../config.json'); module.exports = { - data: new SlashCommandBuilder() - .setName('check-perms') - .setDescription('Check if the user has the correct permissions to start the Minecraft server.'), - async execute(interaction) { - for (const role of config.allowedRoles) { - if (interaction.member.roles.cache.has(role)) { - await interaction.reply({ content: 'You have the correct permissions to start the Minecraft server.', ephemeral: true }); - return; - } - } - await interaction.reply({ content: 'You have the correct permissions to start the Minecraft server.', ephemeral: true }); - }, -} \ No newline at end of file + data: new SlashCommandBuilder() + .setName('check-perms') + .setDescription('Check if the user has the correct permissions to start the Minecraft server.'), + async execute(interaction) { + for (const role of config.allowedRoles) { + if (interaction.member.roles.cache.has(role)) { + await interaction.reply({ content: 'You have the correct permissions to start the Minecraft server.', ephemeral: true }); + return; + } + } + await interaction.reply({ content: 'You have the correct permissions to start the Minecraft server.', ephemeral: true }); + }, +}; \ No newline at end of file diff --git a/commands/utility/test-time.js b/commands/utility/test-time.js index deb76f1..338ecf1 100644 --- a/commands/utility/test-time.js +++ b/commands/utility/test-time.js @@ -1,13 +1,13 @@ -const { SlashCommandBuilder } = require('discord.js') +const { SlashCommandBuilder } = require('discord.js'); module.exports = { - data: new SlashCommandBuilder() - .setName('test-time') - .setDescription('Test the time between now and 4am in discord timestamp'), - async execute(interaction) { - const date = new Date(new Date().setDate(new Date().getDate() + 1)) - date.setUTCHours(3, 0, 0, 0) - const test = Math.round(date.getTime() / 1000); - await interaction.reply({ content: `Time between now and 4am: `}, {ephemeral: true}); - }, -} \ No newline at end of file + data: new SlashCommandBuilder() + .setName('test-time') + .setDescription('Test the time between now and 4am in discord timestamp'), + async execute(interaction) { + const date = new Date(new Date().setDate(new Date().getDate() + 1)); + date.setUTCHours(3, 0, 0, 0); + const test = Math.round(date.getTime() / 1000); + await interaction.reply({ content: `Time between now and 4am: ` }, { ephemeral: true }); + }, +}; \ No newline at end of file