feature/eslint #2

Merged
lgallet merged 2 commits from feature/eslint into main 2024-02-27 10:43:22 +00:00
13 changed files with 238 additions and 210 deletions
Showing only changes of commit 9ff0bf142f - Show all commits

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

6
.idea/jsLinters/eslint.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EslintConfiguration">
<option name="fix-on-save" value="true" />
</component>
</project>

View File

@ -1,11 +1,12 @@
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.");
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,
@ -16,43 +17,48 @@ module.exports = {
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Primary)
.setStyle(ButtonStyle.Primary);
const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Danger)
.setStyle(ButtonStyle.Danger);
const row = new ActionRowBuilder()
.addComponents(cancel, confirm)
.addComponents(cancel, confirm);
const response = await interaction.reply({
content: 'Are you sure you want to start the Minecraft server?',
components: [row]
})
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) {
// eslint-disable-next-line no-undef
proxmox.qemu.start('pve', '102', function(err) {
if (err) {
confirmation.update("Error starting the Minecraft server: " + err);
} else {
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]});
.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') {
});
}
else if (confirmation.customId === 'cancel') {
await confirmation.update({ content: 'Minecraft server start cancelled.', components: [] });
}
} catch (e) {
}
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.");
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) {
proxmox.qemu.shutdown('pve', '102', function(err) {
if (err) {
interaction.reply("Error starting the Minecraft server: " + err);
} else {
interaction.reply("Minecraft server stopped successfully.");
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')
await interaction.reply('Pong');
},
}
};

View File

@ -24,7 +24,8 @@ module.exports = {
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) {
}
catch (error) {
console.error(error);
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
}

View File

@ -18,7 +18,8 @@ for (const folder of commandFolders) {
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
}
else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
@ -39,7 +40,8 @@ const rest = new REST().setToken(token);
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
}
catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}

View File

@ -14,11 +14,13 @@ module.exports = {
try {
await command.execute(interaction);
} catch (error) {
}
catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
}
else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}

View File

@ -18,7 +18,8 @@ for (const folder of commandFolders) {
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
}
else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
@ -62,11 +63,13 @@ client.on(Events.InteractionCreate, async interaction => {
try {
await command.execute(interaction);
} catch (error) {
}
catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
}
else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}

View File

@ -6,7 +6,8 @@
"scripts": {
"dev": "node deploy-commands.js && nodemon index.js",
"start": "node deploy-commands.js && node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint . --fix"
},
"keywords": [],
"author": "",