Remise en forme du code AMP
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { SlashCommandBuilder } = require('discord.js')
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js')
|
||||
require('dotenv').config()
|
||||
require('require-all')(__dirname + '/../../utilsAMP')
|
||||
|
||||
@@ -24,73 +24,59 @@ module.exports = {
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
let result = await login(base_url, interaction.options)
|
||||
//if (result) return await interaction.followUp({ content: `Sorry, something bad happened !` })
|
||||
//else return await interaction.followUp({ content: `You are successfully logged in as **${result}** !` })
|
||||
//await interaction.editReply(`You are successfully logged in as **${response.data.userInfo.Username}** !`)
|
||||
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 (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.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 !") }
|
||||
}*/
|
||||
else if (interaction.options.getSubcommandGroup() == 'instances') {
|
||||
if (interaction.options.getSubcommand() == 'manage') {
|
||||
if (interaction.options.getSubcommand() == 'list') {
|
||||
await interaction.deferReply()
|
||||
let friendlyName = interaction.options.getString('name')
|
||||
let url = `${base_url}/ADSModule/GetInstances`
|
||||
let headers = { SESSIONID: localStorage.getItem("AMP_sessionID") }
|
||||
try {
|
||||
let response = await axios.post(url, headers)
|
||||
response.data.result[0].AvailableInstances.forEach(element => {
|
||||
if (element.FriendlyName == friendlyName) { return instanceID = element.InstanceID }
|
||||
|
||||
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
|
||||
})
|
||||
})
|
||||
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
|
||||
|
||||
if (!instanceID) { await interaction.editReply(`Aucune instance trouv<75>e au nom de ${friendlyName} !`) }
|
||||
|
||||
url = `${base_url}/ADSModule/ManageInstance`
|
||||
headers = { SESSIONID: localStorage.getItem("AMP_sessionID"),
|
||||
InstanceId: instanceID }
|
||||
try {
|
||||
let response = await axios.post(url, headers)
|
||||
console.log(response)
|
||||
await interaction.editReply('Ok !')
|
||||
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
|
||||
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() == 'list') {
|
||||
else if (interaction.options.getSubcommand() == 'manage') {
|
||||
await interaction.deferReply()
|
||||
let url = `${base_url}/ADSModule/GetInstances`
|
||||
let headers = { SESSIONID: localStorage.getItem("AMP_sessionID") }
|
||||
try {
|
||||
let response = await axios.post(url, headers)
|
||||
console.log(response.data.result[0].AvailableInstances)
|
||||
await interaction.editReply('Ok !')
|
||||
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
|
||||
|
||||
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 url = `${base_url}/ADSModule/RestartInstance`
|
||||
let headers = { SESSIONID: localStorage.getItem("AMP_sessionID"),
|
||||
InstanceName: interaction.options.getString('name') }
|
||||
|
||||
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 !") }
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
17
utilsAMP/getInstances.js
Normal file
17
utilsAMP/getInstances.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const axios = require('axios')
|
||||
require('dotenv').config()
|
||||
|
||||
module.exports = getInstances = (async (url) => {
|
||||
return await axios.post(`${url}/ADSModule/GetInstances`, {
|
||||
SESSIONID: process.env.AMP_SESSIONID
|
||||
}).then(response => {
|
||||
console.log(response.data)
|
||||
console.log(response.data.result[0].AvailableInstances)
|
||||
|
||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data, instances: response.data.result[0].AvailableInstances }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
})
|
||||
34
utilsAMP/manageInstance.js
Normal file
34
utilsAMP/manageInstance.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const axios = require('axios')
|
||||
require('dotenv').config()
|
||||
|
||||
module.exports = manageInstance = (async (url, FriendlyName) => {
|
||||
let result = await axios.post(`${url}/ADSModule/GetInstances`, {
|
||||
SESSIONID: process.env.AMP_SESSIONID
|
||||
}).then(response => {
|
||||
console.log(response.data)
|
||||
|
||||
let instance_id = response.data.result[0].AvailableInstances.forEach(element => {
|
||||
if (element.FriendlyName == FriendlyName) return element.InstanceID
|
||||
})
|
||||
|
||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: { instance_id } }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
|
||||
if (result.status === 'success') return await axios.post(`${url}/ADSModule/ManageInstance`, {
|
||||
SESSIONID: process.env.AMP_SESSIONID,
|
||||
InstanceId: result.data.instance_id
|
||||
}).then(response => {
|
||||
console.log(response.data)
|
||||
|
||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
else return result
|
||||
})
|
||||
17
utilsAMP/restartInstance.js
Normal file
17
utilsAMP/restartInstance.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const axios = require('axios')
|
||||
require('dotenv').config()
|
||||
|
||||
module.exports = restartInstance = (async (url, InstanceName) => {
|
||||
return await axios.post(`${url}/ADSModule/RestartInstance`, {
|
||||
SESSIONID: process.env.AMP_SESSIONID,
|
||||
InstanceName
|
||||
}).then(response => {
|
||||
console.log(response.data)
|
||||
|
||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
||||
return { status: 'success', data: response.data }
|
||||
}).catch(error => {
|
||||
console.error(error)
|
||||
return { status: 'error', data: error }
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user