82 lines
4.1 KiB
JavaScript
82 lines
4.1 KiB
JavaScript
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js')
|
|
require('dotenv').config()
|
|
require('require-all')(__dirname + '/../../utilsAMP')
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder().setName('amp').setDescription('Accède à mon panel de jeu AMP !')
|
|
//.addSubcommand(subcommand => subcommand.setName('api_info').setDescription('Prints info about the API.'))
|
|
.addSubcommand(subcommand => subcommand.setName('login').setDescription("Connectez-vous avant d'effectuer une autre commande !")
|
|
.addStringOption(option => option.setName('username').setDescription("Nom d'Utilisateur").setRequired(true))
|
|
.addStringOption(option => option.setName('password').setDescription('Mot de Passe').setRequired(true))
|
|
.addBooleanOption(option => option.setName('remember').setDescription('Mémoriser les identifiants').setRequired(true))
|
|
.addStringOption(option => option.setName('otp').setDescription('Code de double authentification')))
|
|
.addSubcommandGroup(subcommandgroup => subcommandgroup.setName('instances').setDescription('Intéragir avec les instances AMP.')
|
|
.addSubcommand(subcommand => subcommand.setName('manage').setDescription('Gérer une instance.')
|
|
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))
|
|
.addSubcommand(subcommand => subcommand.setName('list').setDescription('Liste toutes les instances disponibles.'))
|
|
.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
|
|
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))),
|
|
|
|
async execute(interaction) {
|
|
const base_url = process.env.AMP_HOST + '/API'
|
|
|
|
if (interaction.options.getSubcommand() == 'login') {
|
|
await interaction.deferReply({ ephemeral: true })
|
|
|
|
let result = await login(base_url, interaction.options)
|
|
if (result.status === 'success') return await interaction.editReply(`You are successfully logged in as **${result.data.userInfo.Username}** !`)
|
|
else if (result.status === 'fail') return await interaction.editReply(`Sorry, something bad happened ! (${result.data.Message})`)
|
|
else if (result.status === 'error') return await interaction.editReply(`Sorry, there has been an error ! (${result.data.error_code})`)
|
|
}
|
|
else if (interaction.options.getSubcommandGroup() == 'instances') {
|
|
if (interaction.options.getSubcommand() == 'list') {
|
|
await interaction.deferReply()
|
|
|
|
let result = await getInstances(base_url)
|
|
if (result.status === 'success') {
|
|
let fields = []
|
|
result.instances.forEach(instance => {
|
|
fields.push({
|
|
name: instance.FriendlyName,
|
|
value: `**ID:** ${instance.InstanceID}
|
|
**Running:** ${instance.Running}
|
|
**IP:** ${instance.IP}
|
|
**Port:** ${instance.Port}
|
|
**Module:** ${instance.Module}`,
|
|
inline: true
|
|
})
|
|
})
|
|
let embed = new EmbedBuilder()
|
|
.setTitle('Instances')
|
|
.setDescription('Liste de toutes les instances disponibles.')
|
|
.setColor(interaction.guild.members.me.displayColor)
|
|
.setTimestamp()
|
|
.setFields(fields)
|
|
return await interaction.followUp({ embeds: [embed] })
|
|
}
|
|
}
|
|
else if (interaction.options.getSubcommand() == 'manage') {
|
|
await interaction.deferReply()
|
|
|
|
let result = await manageInstance(base_url, interaction.options.getString('name'))
|
|
if (result.status === 'success') return await interaction.followUp(`Ok !`)
|
|
}
|
|
else if (interaction.options.getSubcommand() == 'restart') {
|
|
await interaction.deferReply()
|
|
|
|
let result = await restartInstance(base_url, interaction.options.getString('name'))
|
|
if (result.status === 'success') return await interaction.followUp(`Ok !`)
|
|
}
|
|
/*else if (interaction.options.getSubcommand() == 'api_info') {
|
|
await interaction.deferReply()
|
|
let url = `${base_url}/Core/GetAPISpec`
|
|
let headers = { headers: { SESSIONID: localStorage.getItem("AMP_sessionID") } }
|
|
try {
|
|
let response = await axios.post(url, headers)
|
|
console.log(response.data)
|
|
await interaction.editReply('Ok !')
|
|
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
|
|
}*/
|
|
}
|
|
}
|
|
} |