Skip to content

Commit

Permalink
refactor(interactions): remove redundant interaction typeguards (#8027)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Jun 9, 2022
1 parent d7b8357 commit f57d676
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 126 deletions.
43 changes: 7 additions & 36 deletions packages/discord.js/src/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,28 +186,23 @@ class Interaction extends Base {
return Boolean(this.guildId && !this.guild && this.member);
}

/**
* Indicates whether this interaction is a {@link CommandInteraction}.
* @returns {boolean}
*/
isCommand() {
return this.type === InteractionType.ApplicationCommand;
}

/**
* Indicates whether this interaction is a {@link ChatInputCommandInteraction}.
* @returns {boolean}
*/
isChatInputCommand() {
return this.isCommand() && this.commandType === ApplicationCommandType.ChatInput;
return this.type === InteractionType.ApplicationCommand && this.commandType === ApplicationCommandType.ChatInput;
}

/**
* Indicates whether this interaction is a {@link ContextMenuCommandInteraction}
* @returns {boolean}
*/
isContextMenuCommand() {
return this.isCommand() && [ApplicationCommandType.User, ApplicationCommandType.Message].includes(this.commandType);
return (
this.type === InteractionType.ApplicationCommand &&
[ApplicationCommandType.User, ApplicationCommandType.Message].includes(this.commandType)
);
}

/**
Expand All @@ -226,44 +221,20 @@ class Interaction extends Base {
return this.isContextMenuCommand() && this.commandType === ApplicationCommandType.Message;
}

/**
* Indicates whether this interaction is a {@link ModalSubmitInteraction}
* @returns {boolean}
*/
isModalSubmit() {
return this.type === InteractionType.ModalSubmit;
}

/**
* Indicates whether this interaction is an {@link AutocompleteInteraction}
* @returns {boolean}
*/
isAutocomplete() {
return this.type === InteractionType.ApplicationCommandAutocomplete;
}

/**
* Indicates whether this interaction is a {@link MessageComponentInteraction}.
* @returns {boolean}
*/
isMessageComponent() {
return this.type === InteractionType.MessageComponent;
}

/**
* Indicates whether this interaction is a {@link ButtonInteraction}.
* @returns {boolean}
*/
isButton() {
return this.isMessageComponent() && this.componentType === ComponentType.Button;
return this.type === InteractionType.MessageComponent && this.componentType === ComponentType.Button;
}

/**
* Indicates whether this interaction is a {@link SelectMenuInteraction}.
* @returns {boolean}
*/
isSelectMenu() {
return this.isMessageComponent() && this.componentType === ComponentType.SelectMenu;
return this.type === InteractionType.MessageComponent && this.componentType === ComponentType.SelectMenu;
}

/**
Expand Down
8 changes: 0 additions & 8 deletions packages/discord.js/src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,6 @@ class ThreadChannel extends Channel {
return this.archived && this.sendable && (!this.locked || this.manageable);
}

/**
* Whether this thread is a private thread
* @returns {boolean}
*/
isPrivate() {
return this.type === ChannelType.GuildPrivateThread;
}

/**
* Deletes this thread.
* @param {string} [reason] Reason for deleting this thread
Expand Down
Loading

0 comments on commit f57d676

Please sign in to comment.