Tentative de récup d'info de jeu depuis instance
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
const { SlashCommandBuilder, EmbedBuilder, inlineCode } = require('discord.js')
|
const { SlashCommandBuilder, EmbedBuilder, inlineCode } = require('discord.js')
|
||||||
let dotenv = require('dotenv')
|
const dotenv = require('dotenv')
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
const appDir = require('path').dirname(require.main.filename)
|
const appDir = require('path').dirname(require.main.filename)
|
||||||
@@ -20,11 +20,55 @@ module.exports = {
|
|||||||
.addSubcommand(subcommand => subcommand.setName('list').setDescription('Liste toutes les instances disponibles.'))
|
.addSubcommand(subcommand => subcommand.setName('list').setDescription('Liste toutes les instances disponibles.'))
|
||||||
|
|
||||||
.addSubcommand(subcommand => subcommand.setName('manage').setDescription('Gérer une instance.')
|
.addSubcommand(subcommand => subcommand.setName('manage').setDescription('Gérer une instance.')
|
||||||
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))
|
.addStringOption(option => option.setName('instance').setDescription("Nom de l'instance").setRequired(true).setAutocomplete(true)))
|
||||||
|
|
||||||
.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
|
/*.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
|
||||||
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))),
|
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))*/),
|
||||||
|
|
||||||
|
async autocompleteRun(interaction) {
|
||||||
|
let query = interaction.options.getString('instance', true)
|
||||||
|
|
||||||
|
// Check if the SessionID is still valid
|
||||||
|
let sessionID = dotenv.config().parsed.AMP_SESSIONID
|
||||||
|
let session = await API.CheckSession(sessionID)
|
||||||
|
if (session.status === 'fail') {
|
||||||
|
if (process.env.AMP_REMEMBER_TOKEN) {
|
||||||
|
// Refresh the SessionID if the RememberMeToken is available
|
||||||
|
let details = {
|
||||||
|
username: process.env.AMP_USERNAME,
|
||||||
|
password: '',
|
||||||
|
token: process.env.AMP_REMEMBER_TOKEN,
|
||||||
|
rememberMe: true
|
||||||
|
}
|
||||||
|
let result = await API.Core.Login(details)
|
||||||
|
console.log(result)
|
||||||
|
if (result.status === 'success') sessionID = result.data.sessionID
|
||||||
|
else if (result.status === 'fail') return interaction.respond([])
|
||||||
|
else if (result.status === 'error') return interaction.respond([])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// If no RememberMeToken is available, ask to login
|
||||||
|
return await interaction.followUp(`Tu dois te connecter avant d'effectuer une autre commande !`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (session.status === 'error') return interaction.respond([])
|
||||||
|
|
||||||
|
let choices = []
|
||||||
|
let result = await API.ADSModule.GetInstances(sessionID)
|
||||||
|
if (result.status === 'success') {
|
||||||
|
let hosts = result.data.result
|
||||||
|
hosts.forEach(host => {
|
||||||
|
let instances = host.AvailableInstances
|
||||||
|
instances.forEach(instance => {
|
||||||
|
if (instance.FriendlyName.includes(query)) choices.push({ name: `${host.FriendlyName} - ${instance.FriendlyName}`, value: instance.InstanceID })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (result.status === 'fail') return interaction.respond([])
|
||||||
|
else if (result.status === 'error') return interaction.respond([])
|
||||||
|
|
||||||
|
return interaction.respond(choices)
|
||||||
|
},
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
// Let the user login
|
// Let the user login
|
||||||
if (interaction.options.getSubcommand() == 'login') {
|
if (interaction.options.getSubcommand() == 'login') {
|
||||||
@@ -47,8 +91,8 @@ module.exports = {
|
|||||||
|
|
||||||
// Check if the SessionID is still valid
|
// Check if the SessionID is still valid
|
||||||
let sessionID = dotenv.config().parsed.AMP_SESSIONID
|
let sessionID = dotenv.config().parsed.AMP_SESSIONID
|
||||||
|
|
||||||
let session = await API.CheckSession(sessionID)
|
let session = await API.CheckSession(sessionID)
|
||||||
|
|
||||||
if (session.status === 'fail') {
|
if (session.status === 'fail') {
|
||||||
console.log(session)
|
console.log(session)
|
||||||
if (process.env.AMP_REMEMBER_TOKEN) {
|
if (process.env.AMP_REMEMBER_TOKEN) {
|
||||||
@@ -83,17 +127,13 @@ module.exports = {
|
|||||||
host.AvailableInstances.forEach(instance => {
|
host.AvailableInstances.forEach(instance => {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: instance.FriendlyName,
|
name: instance.FriendlyName,
|
||||||
value: `**ID:** ${instance.InstanceID}
|
value: `**Running:** ${instance.Running}\n**Port:** ${instance.Port}\n**Module:** ${instance.Module}`,
|
||||||
**Running:** ${instance.Running}
|
|
||||||
**IP:** ${instance.IP}
|
|
||||||
**Port:** ${instance.Port}
|
|
||||||
**Module:** ${instance.Module}`,
|
|
||||||
inline: true
|
inline: true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
let embed = new EmbedBuilder()
|
let embed = new EmbedBuilder()
|
||||||
.setTitle('Instances')
|
.setTitle(host.FriendlyName)
|
||||||
.setDescription(`Liste des instances de l'hôte **${host.FriendlyName}** :`)
|
.setDescription(`Liste des ${host.AvailableInstances.length} instances :`)
|
||||||
.setColor(interaction.guild.members.me.displayColor)
|
.setColor(interaction.guild.members.me.displayColor)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFields(fields)
|
.setFields(fields)
|
||||||
@@ -104,10 +144,17 @@ module.exports = {
|
|||||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||||
}
|
}
|
||||||
else if (interaction.options.getSubcommand() == 'manage') {
|
else if (interaction.options.getSubcommand() == 'manage') {
|
||||||
let query = interaction.options.getString('name')
|
let instanceID = interaction.options.getString('instance', true)
|
||||||
let result = await API.ADSModule.ManageInstance(sessionID, query)
|
let result = await API.ADSModule.ManageInstance(sessionID, instanceID)
|
||||||
|
|
||||||
if (result.status === 'success') return await interaction.followUp(`Ok !`)
|
if (result.status === 'success') {
|
||||||
|
let server = await API.ADSModule.Servers(sessionID, instanceID)
|
||||||
|
console.log(server)
|
||||||
|
|
||||||
|
if (server.status === 'success') return await interaction.followUp(`Ok !`)
|
||||||
|
else if (server.status === 'fail') return await interaction.followUp(failMsg(server.data))
|
||||||
|
else if (server.status === 'error') return await interaction.followUp(errorMsg(server.data))
|
||||||
|
}
|
||||||
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
else if (result.status === 'fail') return await interaction.followUp(failMsg(result.data))
|
||||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ module.exports = (async (SESSIONID) => {
|
|||||||
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
||||||
SESSIONID
|
SESSIONID
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
console.log(response.data)
|
|
||||||
if (!response.data.result) return { status: 'fail', data: response.data }
|
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||||
return { status: 'success', data: response.data }
|
return { status: 'success', data: response.data }
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
|||||||
@@ -1,35 +1,16 @@
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
|
|
||||||
module.exports = (async (SESSIONID, FriendlyName) => {
|
module.exports = (async (SESSIONID, InstanceId) => {
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
||||||
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,
|
SESSIONID,
|
||||||
InstanceId: result.data.instance_id
|
InstanceId
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
|
|
||||||
//if (!response.data.success) return { status: 'fail', data: response.data }
|
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||||
return { status: 'success', data: response.data }
|
return { status: 'success', data: response.data }
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
return { status: 'error', data: error }
|
return { status: 'error', data: error }
|
||||||
})
|
})
|
||||||
else return result
|
|
||||||
})
|
})
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
|
|
||||||
module.exports = (async (SESSIONID, InstanceName) => {
|
module.exports = (async (SESSIONID, InstanceName) => {
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
||||||
SESSIONID,
|
SESSIONID,
|
||||||
InstanceName
|
InstanceName
|
||||||
|
|||||||
17
utilsAMP/ADSModule/Servers.js
Normal file
17
utilsAMP/ADSModule/Servers.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
module.exports = (async (SESSIONID, InstanceId) => {
|
||||||
|
return await axios.get(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`, {
|
||||||
|
SESSIONID,
|
||||||
|
InstanceId
|
||||||
|
}).then(response => {
|
||||||
|
console.log(response)
|
||||||
|
console.log(response.data)
|
||||||
|
|
||||||
|
if (!response.data.result) return { status: 'fail', data: response.data }
|
||||||
|
return { status: 'success', data: response.data }
|
||||||
|
}).catch(error => {
|
||||||
|
console.error(error)
|
||||||
|
return { status: 'error', data: error }
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -4,8 +4,6 @@ const appDir = require('path').dirname(require.main.filename)
|
|||||||
const writeEnv = require(appDir + '/utils/writeEnv')
|
const writeEnv = require(appDir + '/utils/writeEnv')
|
||||||
|
|
||||||
module.exports = (async (details) => {
|
module.exports = (async (details) => {
|
||||||
require('dotenv').config()
|
|
||||||
console.log(details)
|
|
||||||
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`,
|
return await axios.post(`${process.env.AMP_HOST}/API/${__filename.split('utilsAMP/')[1].split('.js')[0]}`,
|
||||||
details
|
details
|
||||||
).then(response => {
|
).then(response => {
|
||||||
|
|||||||
Reference in New Issue
Block a user