add Exec command
This commit is contained in:
parent
320db6948c
commit
95d7ea1527
@ -16,7 +16,6 @@ export default {
|
|||||||
|
|
||||||
const message = interaction.options.getString('message')
|
const message = interaction.options.getString('message')
|
||||||
|
|
||||||
if (!interaction.deferred)
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
42
src/commands/Exec.ts
Normal file
42
src/commands/Exec.ts
Normal 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)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
@ -2,11 +2,13 @@ import { Collection } from 'discord.js'
|
|||||||
import syncUsers from './syncUsers'
|
import syncUsers from './syncUsers'
|
||||||
import Alert from './Alert'
|
import Alert from './Alert'
|
||||||
import Message from './Message'
|
import Message from './Message'
|
||||||
|
import Exec from './Exec'
|
||||||
|
|
||||||
const commands = new Collection
|
const commands = new Collection
|
||||||
|
|
||||||
commands.set('sync_users', syncUsers)
|
commands.set('sync_users', syncUsers)
|
||||||
commands.set('alert', Alert)
|
commands.set('alert', Alert)
|
||||||
commands.set('message', Message)
|
commands.set('message', Message)
|
||||||
|
commands.set('exec', Exec)
|
||||||
|
|
||||||
export default commands
|
export default commands
|
||||||
|
@ -13,7 +13,6 @@ export default {
|
|||||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
||||||
const userManager = new UserManager(config)
|
const userManager = new UserManager(config)
|
||||||
|
|
||||||
if (!interaction.deferred)
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -12,6 +12,10 @@ export default class EcoManager {
|
|||||||
}
|
}
|
||||||
public async Alert(message: string) {
|
public async Alert(message: string) {
|
||||||
if (!message) return null
|
if (!message) return null
|
||||||
|
return await this.Exec(`manage alert ${message}`)
|
||||||
|
}
|
||||||
|
public async Exec(command: string) {
|
||||||
|
if (!command) return null
|
||||||
try {
|
try {
|
||||||
const { data, status } = await axios<CommandReplyI>(`${process.env.ECO_API_BASE || "https://eco.kamgames.xyz"}/api/v1/command/exec`, {
|
const { data, status } = await axios<CommandReplyI>(`${process.env.ECO_API_BASE || "https://eco.kamgames.xyz"}/api/v1/command/exec`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -20,7 +24,7 @@ export default class EcoManager {
|
|||||||
"X-API-Key": process.env.ECO_API_KEY,
|
"X-API-Key": process.env.ECO_API_KEY,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
Command: `manage alert ${message}`
|
Command: command
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user