couteau_suisse/commands/server/reboot-server.js
2025-07-05 14:44:59 +02:00

86 lines
3.0 KiB
JavaScript

const { SlashCommandBuilder } = require('discord.js');
const axios = require('axios');
module.exports = {
data: new SlashCommandBuilder()
.setName('reboot-server')
.setDescription('Redémarre le serveur Palworld'),
async execute(interaction, headers) {
await interaction.deferReply();
try {
// Vérifier l'état actuel du serveur
const statusResponse = await axios.get('https://panel.louismazin.ovh/api/client/servers/ae4a628f/resources', {
headers: headers
});
const currentState = statusResponse.data.attributes.current_state;
if (currentState !== 'running') {
await interaction.editReply('⚠️ Le serveur n\'est pas en cours d\'exécution. Utilisez `/start-server` pour le démarrer.');
return;
}
// Étape 1: Sauvegarder le serveur
await interaction.editReply('💾 Sauvegarde du serveur en cours...');
await axios.post('https://panel.louismazin.ovh/api/client/servers/ae4a628f/command', {
command: 'save'
}, {
headers: headers
});
await axios.post('https://panel.louismazin.ovh/api/client/servers/ae4a628f/command', {
command: "broadcast 'Redemarrage journalier du serveur (Ca prends 20 secondes)'"
}, {
headers: headers
});
// Attendre un peu pour la sauvegarde
await new Promise(resolve => setTimeout(resolve, 2000));
// Étape 2: Arrêter le serveur
await interaction.editReply('⏹️ Arrêt du serveur...');
await axios.post('https://panel.louismazin.ovh/api/client/servers/ae4a628f/command', {
command: 'shutdown 1'
}, {
headers: headers
});
// Étape 3: Attendre 10 secondes
await interaction.editReply('⏳ Attente de 10 secondes...');
await new Promise(resolve => setTimeout(resolve, 10000));
// Étape 4: Redémarrer le serveur
await interaction.editReply('🚀 Redémarrage du serveur...');
await axios.post('https://panel.louismazin.ovh/api/client/servers/ae4a628f/power', {
signal: 'start'
}, {
headers: headers
});
var run = false;
while (!run) {
setTimeout(async () => {
try {
const checkResponse = await axios.get('https://panel.louismazin.ovh/api/client/servers/ae4a628f/resources', {
headers: headers
});
const newState = checkResponse.data.attributes.current_state;
if (newState === 'running') {
run = true;
await interaction.editReply('✅ Le serveur Palworld a été redémarré avec succès !');
}
} catch (error) {
console.error('Erreur lors de la vérification de l\'état du serveur:', error);
}
}, 5000); // Vérifier après 5 secondes
}
} catch (error) {
console.error('Erreur lors du redémarrage du serveur:', error);
await interaction.editReply('❌ Erreur lors du redémarrage du serveur. Veuillez réessayer plus tard.');
}
},
};