refactor: 🚨 Add linter and fix files

This commit is contained in:
2024-02-27 11:41:52 +01:00
parent 7f71d5a96a
commit 9ff0bf142f
13 changed files with 238 additions and 210 deletions

View File

@ -1,58 +1,64 @@
const { ButtonBuilder, ButtonStyle, SlashCommandBuilder, ActionRow, ActionRowBuilder} = require('discord.js')
const config = require('../../config.json')
const { ButtonBuilder, ButtonStyle, SlashCommandBuilder, 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);
console.error('Proxmox credentials not found in config.json. Exiting.');
process.exit(1);
}
proxmox = require("proxmox")(config.proxmoxUser, config.proxmoxPass, config.proxmoxHostname);
// eslint-disable-next-line no-undef
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)
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 row = new ActionRowBuilder()
.addComponents(cancel, confirm);
const response = await interaction.reply({
content: 'Are you sure you want to start the Minecraft server?',
components: [row]
})
const response = await interaction.reply({
content: 'Are you sure you want to start the Minecraft server?',
components: [row],
});
const collectorFilter = i => i.user.id === interaction.user.id;
try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 30_000 });
if (confirmation.customId === 'confirm') {
proxmox.qemu.start("pve", "102", 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.", 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: [] });
}
const collectorFilter = i => i.user.id === interaction.user.id;
try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 30_000 });
if (confirmation.customId === 'confirm') {
// eslint-disable-next-line no-undef
proxmox.qemu.start('pve', '102', 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 linkRow = new ActionRowBuilder()
.addComponents(linkButton);
confirmation.update({ content: 'Minecraft server started successfully. Please wait a few minutes for it to boot.', components: [linkRow] });
}
});
}
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: [] });
}
}
}
},
};

View File

@ -1,23 +1,24 @@
const { SlashCommandBuilder } = require('discord.js')
const config = require('../../config.json')
const { SlashCommandBuilder } = 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);
console.error('Proxmox credentials not found in config.json. Exiting.');
process.exit(1);
}
proxmox = require("proxmox")(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", "102", function(err, res) {
if (err) {
interaction.reply("Error starting the Minecraft server: " + err);
} else {
interaction.reply("Minecraft server stopped successfully.");
}
})
}
}
data: new SlashCommandBuilder()
.setName('stop-mc')
.setDescription('Stops the minecraft server machine.'),
async execute(interaction) {
proxmox.qemu.shutdown('pve', '102', function(err) {
if (err) {
interaction.reply('Error starting the Minecraft server: ' + err);
}
else {
interaction.reply('Minecraft server stopped successfully.');
}
});
},
};

View File

@ -1,10 +1,10 @@
const { SlashCommandBuilder } = require('discord.js')
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong'),
async execute(interaction) {
await interaction.reply('Pong')
},
}
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong'),
async execute(interaction) {
await interaction.reply('Pong');
},
};

View File

@ -1,32 +1,33 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
category: 'utility',
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reloads a command.')
.addStringOption(option =>
option.setName('command')
.setDescription('The command to reload.')
.setRequired(true)),
async execute(interaction) {
const commandName = interaction.options.getString('command', true).toLowerCase();
const command = interaction.client.commands.get(commandName);
category: 'utility',
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reloads a command.')
.addStringOption(option =>
option.setName('command')
.setDescription('The command to reload.')
.setRequired(true)),
async execute(interaction) {
const commandName = interaction.options.getString('command', true).toLowerCase();
const command = interaction.client.commands.get(commandName);
if (!command) {
return interaction.reply(`There is no command with name \`${commandName}\`!`);
}
if (!command) {
return interaction.reply(`There is no command with name \`${commandName}\`!`);
}
delete require.cache[require.resolve(`../${command.category}/${command.data.name}.js`)];
delete require.cache[require.resolve(`../${command.category}/${command.data.name}.js`)];
try {
await interaction.client.commands.delete(command.data.name);
const newCommand = require(`../${command.category}/${command.data.name}.js`);
await interaction.client.commands.set(newCommand.data.name, newCommand);
await interaction.reply(`Command \`${newCommand.data.name}\` was reloaded!`);
} catch (error) {
console.error(error);
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
}
},
try {
await interaction.client.commands.delete(command.data.name);
const newCommand = require(`../${command.category}/${command.data.name}.js`);
await interaction.client.commands.set(newCommand.data.name, newCommand);
await interaction.reply(`Command \`${newCommand.data.name}\` was reloaded!`);
}
catch (error) {
console.error(error);
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
}
},
};

View File

@ -1,11 +1,11 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('server')
.setDescription('Provides information about the server.'),
async execute(interaction) {
// interaction.guild is the object representing the Guild in which the command was run
await interaction.reply(`This server is ${interaction.guild.name} and has ${interaction.guild.memberCount} members.`);
},
data: new SlashCommandBuilder()
.setName('server')
.setDescription('Provides information about the server.'),
async execute(interaction) {
// interaction.guild is the object representing the Guild in which the command was run
await interaction.reply(`This server is ${interaction.guild.name} and has ${interaction.guild.memberCount} members.`);
},
};

View File

@ -1,12 +1,12 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};