couteau_suisse/index.js
2025-07-05 14:15:54 +02:00

91 lines
3.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('node:fs');
const deepl = require('deepl-node');
const path = require('node:path');
const deploy = require('./deploy_command.js')
const update = require('./displayer.js');
const clean = require('./cleaner.js');
const { Client, GatewayIntentBits, Collection, Events, Partials } = require('discord.js');
const client = new Client({ intents:
[
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
const args = process.argv;
const token = args[2].toString();
const pterodactyl = args[3].toString();
const palworldToken = args[4].toString();
const deeplToken = args[5] ? args[5].toString() : null;
const headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer "+pterodactyl
};
const numbers=["𝟎","𝟏","𝟐","𝟑","𝟒","𝟓","𝟔","𝟕","𝟖","𝟗","𝟏𝟎","𝟏𝟏","𝟏𝟐","𝟏𝟑","𝟏𝟒","𝟏𝟓","𝟏𝟔","𝟏𝟕","𝟏𝟖","𝟏𝟗","𝟐𝟎","𝟐𝟏","𝟐𝟐","𝟐𝟑","𝟐𝟒","𝟐𝟓","𝟐𝟔","𝟐𝟕","𝟐𝟖","𝟐𝟗","𝟑𝟎","𝟑𝟏","𝟑𝟐"];
const translator = deeplToken ? new deepl.Translator(deeplToken) : null;
client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
client.once('ready', () => {
client.user.setPresence({ activities: [{ name: 'Rygain', type: 'WATCHING' }], status: 'online' });
console.log('Bot started !');
deploy(token);
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
if (interaction.commandName === 'server-stats') {
await command.execute(interaction, palworldToken);
} else if (interaction.commandName === 'trad') {
await command.execute(interaction, translator);
} else if (interaction.commandName === 'start-server' || interaction.commandName === 'reboot-server') {
await command.execute(interaction, headers);
} else {
await command.execute(interaction);
}
} 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 {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.login(token);
setInterval(()=>{update(headers,numbers,client,palworldToken)}, 300000);
setInterval(()=>{clean(client)}, 86400000);