add Exec command

This commit is contained in:
The Foxon 2023-06-28 04:12:46 +12:00
parent 320db6948c
commit 95d7ea1527
5 changed files with 51 additions and 5 deletions

View File

@ -16,7 +16,6 @@ export default {
const message = interaction.options.getString('message')
if (!interaction.deferred)
await interaction.deferReply({ ephemeral: true })
try {

42
src/commands/Exec.ts Normal file
View File

@ -0,0 +1,42 @@
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import ConfigManager from '../controller/ConfigManager';
import EcoManager from '../controller/EcoManager';
// const adminPermissions = new PermissionsBitField('Administrator');
export default {
data: new SlashCommandBuilder()
.setName('exec')
.setDescription('Exec command')
.addStringOption(opt => opt.setName("command").setDescription("Command").setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
const ecoManager = new EcoManager(config)
const command = interaction.options.getString('command')
await interaction.deferReply({ ephemeral: true })
try {
if (!command) {
await interaction.followUp(`Ошибка выполнения команды.`);
return
}
const status = await ecoManager.Exec(command)
if (!!status && !status.Errored) {
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat").length > 0) {
await interaction.followUp(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message)
} else
await interaction.followUp("Команда выполнена.\n" + JSON.stringify(status))
} else {
await interaction.followUp("Ошибка выполнения команды.\n" + JSON.stringify(status))
}
return
} catch (error) {
await interaction.followUp("Ошибка выполнения команды.")
console.log(error)
}
},
};

View File

@ -2,11 +2,13 @@ import { Collection } from 'discord.js'
import syncUsers from './syncUsers'
import Alert from './Alert'
import Message from './Message'
import Exec from './Exec'
const commands = new Collection
commands.set('sync_users', syncUsers)
commands.set('alert', Alert)
commands.set('message', Message)
commands.set('exec', Exec)
export default commands

View File

@ -13,7 +13,6 @@ export default {
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
const userManager = new UserManager(config)
if (!interaction.deferred)
await interaction.deferReply({ ephemeral: true })
try {

View File

@ -12,6 +12,10 @@ export default class EcoManager {
}
public async Alert(message: string) {
if (!message) return null
return await this.Exec(`manage alert ${message}`)
}
public async Exec(command: string) {
if (!command) return null
try {
const { data, status } = await axios<CommandReplyI>(`${process.env.ECO_API_BASE || "https://eco.kamgames.xyz"}/api/v1/command/exec`, {
method: "POST",
@ -20,7 +24,7 @@ export default class EcoManager {
"X-API-Key": process.env.ECO_API_KEY,
},
data: {
Command: `manage alert ${message}`
Command: command
},
});