Version 3.0 sortie, fusion avec JujulBot
This commit is contained in:
@@ -1,35 +1,45 @@
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, AutocompleteInteraction, EmbedBuilder, inlineCode } from 'discord.js'
|
||||
import * as AMP from '../../utils/amp'
|
||||
import { SlashCommandBuilder, ChatInputCommandInteraction, AutocompleteInteraction, ApplicationCommandOptionChoiceData, EmbedBuilder, inlineCode, PermissionFlagsBits } from 'discord.js'
|
||||
import dbGuild from '../../schemas/guild'
|
||||
import * as AMP from '../../utils/amp'
|
||||
|
||||
interface ListInstancesResult {
|
||||
status: string
|
||||
data: [
|
||||
Host: {
|
||||
AvailableInstances: any[]
|
||||
FriendlyName: string
|
||||
}
|
||||
]
|
||||
}
|
||||
interface InstanceFields {
|
||||
name: string
|
||||
value: string
|
||||
inline: boolean
|
||||
}
|
||||
|
||||
interface failData {
|
||||
Title: string
|
||||
Message: string
|
||||
interface InstanceResult {
|
||||
status: string
|
||||
data: [
|
||||
Host
|
||||
]
|
||||
}
|
||||
interface errorData {
|
||||
error_code: string
|
||||
interface Host {
|
||||
AvailableInstances: Instance[]
|
||||
FriendlyName: string
|
||||
}
|
||||
interface Instance {
|
||||
InstanceID: string
|
||||
FriendlyName: string
|
||||
Running: boolean
|
||||
Module: string
|
||||
Port: number
|
||||
}
|
||||
interface FailMsgData {
|
||||
Title: string
|
||||
Message: string
|
||||
}
|
||||
interface ErrorMsgData {
|
||||
error_code: string
|
||||
}
|
||||
|
||||
function failMsg(data: any) { return `La commande a échouée !\n${inlineCode(`${data.Title}: ${data.Message}`)}` }
|
||||
function errorMsg(data: any) { return `Y'a eu une erreur !\n${inlineCode(`${data.error_code}`)}` }
|
||||
function failMsg(data: FailMsgData) { return `La commande a échouée !\n${inlineCode(`${data.Title}: ${data.Message}`)}` }
|
||||
function errorMsg(data: ErrorMsgData) { return `Y'a eu une erreur !\n${inlineCode(`${data.error_code}`)}` }
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder().setName('amp').setDescription('Accède à mon panel de jeu AMP !')
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('amp')
|
||||
.setDescription('Accède à mon panel de jeu AMP !')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.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))
|
||||
@@ -71,12 +81,12 @@ export default {
|
||||
}
|
||||
else if (session.status === 'error') return interaction.respond([])
|
||||
|
||||
let choices: any = []
|
||||
let choices: ApplicationCommandOptionChoiceData[] = []
|
||||
let result = await AMP.ADSModule.GetInstances(host, sessionID)
|
||||
if (result.status === 'success') {
|
||||
let hosts = result.data.result as any[]
|
||||
let hosts = result.data.result as Host[]
|
||||
hosts.forEach(host => {
|
||||
let instances = host.AvailableInstances as any[]
|
||||
let instances = host.AvailableInstances as Instance[]
|
||||
instances.forEach(instance => {
|
||||
if (instance.FriendlyName.includes(query)) choices.push({ name: `${host.FriendlyName} - ${instance.FriendlyName}`, value: instance.InstanceID })
|
||||
})
|
||||
@@ -105,10 +115,10 @@ export default {
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
let details = {
|
||||
username: interaction.options.getString('username'),
|
||||
password: interaction.options.getString('password'),
|
||||
token: interaction.options.getString('otp') || '',
|
||||
rememberMe: interaction.options.getBoolean('remember')
|
||||
username: interaction.options.getString('username') || '',
|
||||
password: interaction.options.getString('password') || '',
|
||||
rememberMe: interaction.options.getBoolean('remember') || '',
|
||||
token: interaction.options.getString('otp') || ''
|
||||
}
|
||||
|
||||
let result = await AMP.Core.Login(host, details)
|
||||
@@ -146,13 +156,13 @@ export default {
|
||||
|
||||
if (interaction.options.getSubcommandGroup() == 'instances') {
|
||||
if (interaction.options.getSubcommand() == 'list') {
|
||||
let result = await AMP.ADSModule.GetInstances(host, sessionID) as ListInstancesResult
|
||||
let result = await AMP.ADSModule.GetInstances(host, sessionID) as InstanceResult
|
||||
|
||||
if (result.status === 'success') {
|
||||
await interaction.followUp({ content: `${result.data.length} hôte(s) trouvé(s) !` })
|
||||
result.data.forEach(async host => {
|
||||
let fields = [] as InstanceFields[]
|
||||
host.AvailableInstances.forEach(instance => {
|
||||
host.AvailableInstances.forEach((instance: Instance) => {
|
||||
fields.push({
|
||||
name: instance.FriendlyName,
|
||||
value: `**Running:** ${instance.Running}\n**Port:** ${instance.Port}\n**Module:** ${instance.Module}`,
|
||||
@@ -168,8 +178,8 @@ export default {
|
||||
return await interaction.channel?.send({ embeds: [embed] })
|
||||
})
|
||||
}
|
||||
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 === 'fail') return await interaction.followUp(failMsg(result.data as unknown as FailMsgData))
|
||||
else if (result.status === 'error') return await interaction.followUp(errorMsg(result.data as unknown as ErrorMsgData))
|
||||
}
|
||||
else if (interaction.options.getSubcommand() == 'manage') {
|
||||
let instanceID = interaction.options.getString('instance', true)
|
||||
|
||||
Reference in New Issue
Block a user