command handler stuff

This commit is contained in:
Erik 2022-03-31 01:27:04 +03:00
parent e0c6eec092
commit 97cd174460
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -1,3 +1,5 @@
const { MessageEmbed } = require('discord.js');
const { Util } = require('../../../utilities');
const { Observer, CommandOption, CommandError } = require('../../interfaces/');
class CommandHandler extends Observer {
@ -52,10 +54,11 @@ class CommandHandler extends Observer {
});
const inhibitors = await this._handleInhibitors(interaction);
if(inhibitors.length) return this._generateError(interaction, { type: 'inhibitor', inhibitors });
if(inhibitors.length) return this._generateError(interaction, { type: 'inhibitor', ...inhibitors[0] });
const response = await this._parseInteraction(interaction);
if (response.error) {
console.log(response);
let content = interaction.format(`O_COMMANDHANDLER_TYPE${response.option.type}`, {
option: response.option.name, min: response.option.minimum, max: response.option.maximum
});
@ -67,7 +70,7 @@ class CommandHandler extends Observer {
ephemeral: true
});
} else if (command.showUsage && !Object.keys(response.options).length) {
return interaction.reply({ embeds: [command.usageEmbed(interaction.guild)] });
return interaction.reply({ embeds: [command.usageEmbed(interaction)] });
}
this.logger.info(`${interaction.user.tag} (${interaction.user.id}) is executing ${command.name}`);
@ -107,7 +110,13 @@ class CommandHandler extends Observer {
}
}
if (!response) interaction.reply({ index: 'O_COMMANDHANDLER_COMMAND_NORESPONSE', ephemeral: !interaction.replied });
if(response) {
if (response instanceof MessageEmbed) return interaction.reply({ embeds: [response] });
if (typeof response === 'string') return interaction.reply({ content: response });
if (typeof response === 'object') return interaction.reply(response);
}
if (!interaction.replied) return interaction.reply({ index: 'O_COMMANDHANDLER_COMMAND_NORESPONSE', ephemeral: !interaction.replied });
}
@ -183,21 +192,30 @@ class CommandHandler extends Observer {
const { guild } = interaction;
const types = {
// ROLES: (string) => {
// },
// MEMBERS: (string) => {
// },
ROLES: async (string) => {
const args = Util.parseQuotes(string).map(([str]) => str);
const roles = await guild.resolveRoles(args);
if (!roles.length) return { error: true };
return { value: roles };
},
MEMBERS: async (string) => {
const args = Util.parseQuotes(string).map(([str]) => str);
const members = await guild.resolveMembers(args);
if (!members.length) return { error: true };
return { value: members };
},
// USERS: (string) => {
// },
// CHANNELS: (string) => {
// },
// TEXT_CHANNELS: (string) => {
// },
TEXT_CHANNELS: async (string) => {
const args = Util.parseQuotes(string).map(([str]) => str);
const channels = await guild.resolveChannels(args);
if(!channels.length) return { error: true };
return { value: channels };
},
// VOICE_CHANNELS: (string) => {
// },
@ -314,7 +332,7 @@ class CommandHandler extends Observer {
},
inhibitor: () => {
return {
content: `${interaction.format(info.inhibitor.index, { command: interaction.command.resolveable, ...info.args })}**\`${info.inhibitor.resolveable}\`**`,
content: `${interaction.format(info.inhibitor.index, { command: interaction.command.resolveable, ...info.args })}\n**\`${info.inhibitor.resolveable}\`**`,
ephemeral: !interaction.replied
};
}