separated TargetID to its own parameter

This commit is contained in:
mmacierzanka committed 2021-09-08 23:07:43 +02:00
1 parent 2ca3143a76
commit c3bf914a81
6 files changed
+11 -12

No files matched your search

+2 -2
View File
@@ -98,13 +98,13 @@ export class BaseCommand {
* @param {InputParameter[]} [cmdParams] - list of processed parameters passed in a Discord interaction
* @returns {Promise<void>}
*/
public async start(args: ReadonlyMap<string, ParameterResolvable> | TargetID, interaction: Message | Interaction): Promise<void> {
public async start(args: ReadonlyMap<string, ParameterResolvable>, interaction: Message | Interaction, target?: TargetID): Promise<void> {
if (interaction instanceof Interaction && !interaction.isCommand() && !interaction.isContextMenu()) throw new TypeError(`Interaction not recognized`);
if (this.permissionChecker(interaction)) {
if (interaction instanceof Interaction) {
await interaction.deferReply();
}
await this.handleReply(interaction, await this.function(args, interaction));
await this.handleReply(interaction, await this.function(args, interaction, target));
} else {
throw new PermissionsError(this, interaction.member as GuildMember);
}
+2 -2
View File
@@ -88,11 +88,11 @@ export class ChatCommand extends BaseCommand {
* @param {InputParameter[]} [cmdParams] - list of processed parameters passed in a Discord interaction
* @returns {Promise<void>}
*/
public async start(args: ReadonlyMap<string, ParameterResolvable> | TargetID, interaction: Message | Interaction): Promise<void> {
public async start(args: ReadonlyMap<string, ParameterResolvable>, interaction: Message | Interaction, target?: TargetID): Promise<void> {
if (!this.slash && interaction instanceof Interaction) {
throw new Error("This command is not available as a slash command");
}
super.start(args, interaction);
super.start(args, interaction, target);
}
/**
+2 -1
View File
@@ -112,7 +112,8 @@ export class CommandManager {
const target = new TargetID(i.targetId, i.targetType);
return {
command: cmd,
parameters: target,
parameters: new Map(),
target: target,
};
} else {
throw new CommandNotFound(i.commandName);
+1 -4
View File
@@ -20,16 +20,13 @@ export class HelpMessage extends ChatCommand {
},
],
function: (args, i) => {
if (!(args instanceof Map)) {
return;
}
const helpMsg = new MessageEmbed();
helpMsg.setColor(params.color);
helpMsg.setTimestamp();
helpMsg.setFooter(botName || "");
if (helpMsg != null) {
if (args.get("command_name")) {
const cmd: ChatCommand | null = cmdManager.get(args.get("command_name") || "", "CHAT");
const cmd: ChatCommand | null = cmdManager.get(args.get("command_name")?.toString() || "", "CHAT");
if (cmd) {
if (Array.isArray(cmd.guilds) && cmd.guilds.length > 0 && !cmd.guilds.find((g) => i?.guild?.id === g)) {
throw new ReferenceError(`Command "${cmd.name}" is not available`);
+3 -2
View File
@@ -11,9 +11,10 @@ export type CommandType = "CHAT" | "CONTEXT";
export type CommandFunctionReturnTypes = void | string | MessageEmbed | ReplyMessageOptions | Promise<void | string | MessageEmbed | ReplyMessageOptions>;
export type CommandFunction = (args: ReadonlyMap<string, ParameterResolvable> | TargetID, interaction?: Message | CommandInteraction) => CommandFunctionReturnTypes;
export type CommandFunction = (args: ReadonlyMap<string, ParameterResolvable>, i: Message | CommandInteraction, t?: TargetID) => CommandFunctionReturnTypes;
export interface CommandInteractionData {
command: BaseCommand;
parameters: ReadonlyMap<string, ParameterResolvable> | TargetID;
parameters: ReadonlyMap<string, ParameterResolvable>;
target?: TargetID;
}
+1 -1
View File
@@ -205,7 +205,7 @@ export class Bot extends EventEmitter {
cmd = this.commands.fetch(i);
if (cmd) {
this.emit("COMMAND", i, cmd);
await cmd.command.start(cmd.parameters, i);
await cmd.command.start(cmd.parameters, i, cmd.target);
}
} catch (e) {
if (e instanceof PermissionsError) {