From e3243836c6381d1d9081d4b3088d40afa513fde7 Mon Sep 17 00:00:00 2001 From: Hackerboi 69 Date: Sat, 9 Oct 2021 17:27:08 +0200 Subject: [PATCH 1/4] refactor: rename BaseCommandInteraction to ApplicationCommandInteraction --- src/index.js | 2 +- ...on.js => ApplicationCommandInteraction.js} | 12 ++-- src/structures/CommandInteraction.js | 6 +- src/structures/ContextMenuInteraction.js | 6 +- src/structures/Interaction.js | 8 +++ typings/index.d.ts | 64 ++++++++++--------- 6 files changed, 55 insertions(+), 43 deletions(-) rename src/structures/{BaseCommandInteraction.js => ApplicationCommandInteraction.js} (94%) diff --git a/src/index.js b/src/index.js index 09916d9f4f87..68325bcacf99 100644 --- a/src/index.js +++ b/src/index.js @@ -70,8 +70,8 @@ module.exports = { AnonymousGuild: require('./structures/AnonymousGuild'), Application: require('./structures/interfaces/Application'), ApplicationCommand: require('./structures/ApplicationCommand'), + ApplicationCommandInteraction: require('./structures/ApplicationCommandInteraction'), Base: require('./structures/Base'), - BaseCommandInteraction: require('./structures/BaseCommandInteraction'), BaseGuild: require('./structures/BaseGuild'), BaseGuildEmoji: require('./structures/BaseGuildEmoji'), BaseGuildTextChannel: require('./structures/BaseGuildTextChannel'), diff --git a/src/structures/BaseCommandInteraction.js b/src/structures/ApplicationCommandInteraction.js similarity index 94% rename from src/structures/BaseCommandInteraction.js rename to src/structures/ApplicationCommandInteraction.js index ec6eb4fd7f5d..ff14810cff86 100644 --- a/src/structures/BaseCommandInteraction.js +++ b/src/structures/ApplicationCommandInteraction.js @@ -7,26 +7,26 @@ const InteractionResponses = require('./interfaces/InteractionResponses'); const { ApplicationCommandOptionTypes } = require('../util/Constants'); /** - * Represents a command interaction. + * Represents an application command interaction. * @extends {Interaction} * @implements {InteractionResponses} * @abstract */ -class BaseCommandInteraction extends Interaction { +class ApplicationCommandInteraction extends Interaction { constructor(client, data) { super(client, data); /** * The channel this interaction was sent in * @type {?TextBasedChannels} - * @name BaseCommandInteraction#channel + * @name ApplicationCommandInteraction#channel * @readonly */ /** * The id of the channel this interaction was sent in * @type {Snowflake} - * @name BaseCommandInteraction#channelId + * @name ApplicationCommandInteraction#channelId */ /** @@ -190,9 +190,9 @@ class BaseCommandInteraction extends Interaction { followUp() {} } -InteractionResponses.applyToClass(BaseCommandInteraction, ['deferUpdate', 'update']); +InteractionResponses.applyToClass(ApplicationCommandInteraction, ['deferUpdate', 'update']); -module.exports = BaseCommandInteraction; +module.exports = ApplicationCommandInteraction; /* eslint-disable max-len */ /** diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index 4c8bd5d7535a..fe5cb77ed2ac 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -1,13 +1,13 @@ 'use strict'; -const BaseCommandInteraction = require('./BaseCommandInteraction'); +const ApplicationCommandInteraction = require('./ApplicationCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); /** * Represents a command interaction. - * @extends {BaseCommandInteraction} + * @extends {ApplicationCommandInteraction} */ -class CommandInteraction extends BaseCommandInteraction { +class CommandInteraction extends ApplicationCommandInteraction { constructor(client, data) { super(client, data); diff --git a/src/structures/ContextMenuInteraction.js b/src/structures/ContextMenuInteraction.js index f4f6ef47d274..38b7b0703f6b 100644 --- a/src/structures/ContextMenuInteraction.js +++ b/src/structures/ContextMenuInteraction.js @@ -1,14 +1,14 @@ 'use strict'; -const BaseCommandInteraction = require('./BaseCommandInteraction'); +const ApplicationCommandInteraction = require('./ApplicationCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); const { ApplicationCommandOptionTypes, ApplicationCommandTypes } = require('../util/Constants'); /** * Represents a context menu interaction. - * @extends {BaseCommandInteraction} + * @extends {ApplicationCommandInteraction} */ -class ContextMenuInteraction extends BaseCommandInteraction { +class ContextMenuInteraction extends ApplicationCommandInteraction { constructor(client, data) { super(client, data); /** diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 2afdacee023c..57106d247934 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -136,6 +136,14 @@ class Interaction extends Base { return Boolean(this.guildId && !this.guild && this.member); } + /** + * Indicates whether this interaction is an {@link AppplicationCommandInteraction}. + * @returns {boolean} + */ + isApplicationCommand() { + return InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND; + } + /** * Indicates whether this interaction is a {@link CommandInteraction}. * @returns {boolean} diff --git a/typings/index.d.ts b/typings/index.d.ts index 4816402f9216..14d93d911a76 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -242,6 +242,34 @@ export class ApplicationCommand extends Base { private static isAPICommandData(command: object): command is RESTPostAPIApplicationCommandsJSONBody; } +export abstract class ApplicationCommandInteraction extends Interaction { + public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; + public readonly channel: TextBasedChannels | null; + public channelId: Snowflake; + public commandId: Snowflake; + public commandName: string; + public deferred: boolean; + public ephemeral: boolean | null; + public replied: boolean; + public webhook: InteractionWebhook; + public inGuild(): this is BaseGuildCommandInteraction<'present'> & this; + public inCachedGuild(): this is BaseGuildCommandInteraction<'cached'> & this; + public inRawGuild(): this is BaseGuildCommandInteraction<'raw'> & this; + public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise; + public deferReply(options?: InteractionDeferReplyOptions): Promise; + public deleteReply(): Promise; + public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; + public fetchReply(): Promise; + public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise; + public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise; + public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; + private transformOption( + option: APIApplicationCommandOption, + resolved: APIApplicationCommandInteractionData['resolved'], + ): CommandInteractionOption; + private transformResolved(resolved: APIApplicationCommandInteractionData['resolved']): CommandInteractionResolvedData; +} + export type ApplicationResolvable = Application | Activity | Snowflake; export class ApplicationFlags extends BitField { @@ -284,34 +312,6 @@ export interface BaseGuildCommandInteraction>; } -export abstract class BaseCommandInteraction extends Interaction { - public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; - public readonly channel: TextBasedChannels | null; - public channelId: Snowflake; - public commandId: Snowflake; - public commandName: string; - public deferred: boolean; - public ephemeral: boolean | null; - public replied: boolean; - public webhook: InteractionWebhook; - public inGuild(): this is BaseGuildCommandInteraction<'present'> & this; - public inCachedGuild(): this is BaseGuildCommandInteraction<'cached'> & this; - public inRawGuild(): this is BaseGuildCommandInteraction<'raw'> & this; - public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise; - public deleteReply(): Promise; - public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; - public fetchReply(): Promise; - public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise; - public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise; - public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; - private transformOption( - option: APIApplicationCommandOption, - resolved: APIApplicationCommandInteractionData['resolved'], - ): CommandInteractionOption; - private transformResolved(resolved: APIApplicationCommandInteractionData['resolved']): CommandInteractionResolvedData; -} - export abstract class BaseGuild extends Base { protected constructor(client: Client, data: RawBaseGuildData); public readonly createdAt: Date; @@ -602,7 +602,10 @@ export abstract class Collector extends EventEmi export type GuildCommandInteraction = BaseGuildCommandInteraction & CommandInteraction; -export class CommandInteraction extends BaseCommandInteraction implements GuildCachedInteraction { +export class CommandInteraction + extends ApplicationCommandInteraction + implements GuildCachedInteraction +{ public options: CommandInteractionOptionResolver; } @@ -672,7 +675,7 @@ export interface GuildCachedInteraction { } export class ContextMenuInteraction - extends BaseCommandInteraction + extends ApplicationCommandInteraction implements GuildCachedInteraction { public options: CommandInteractionOptionResolver; @@ -1119,6 +1122,7 @@ export class Interaction extends Base { public inGuild(): this is GuildInteraction<'present'> & this; public inCachedGuild(): this is GuildInteraction<'cached'> & this; public inRawGuild(): this is GuildInteraction<'raw'> & this; + public isApplicationCommand(): this is ApplicationCommandInteraction; public isButton(): this is ButtonInteraction; public isCommand(): this is CommandInteraction; public isContextMenu(): this is ContextMenuInteraction; From 16503260b7927e1d0cec1ac27df26be7c23794c8 Mon Sep 17 00:00:00 2001 From: Hackerboi 69 Date: Sat, 9 Oct 2021 21:04:21 +0200 Subject: [PATCH 2/4] refactor: undo renaming --- src/index.js | 2 +- ...teraction.js => BaseCommandInteraction.js} | 12 ++-- src/structures/CommandInteraction.js | 6 +- src/structures/ContextMenuInteraction.js | 6 +- src/structures/Interaction.js | 2 +- typings/index.d.ts | 65 +++++++++---------- 6 files changed, 45 insertions(+), 48 deletions(-) rename src/structures/{ApplicationCommandInteraction.js => BaseCommandInteraction.js} (94%) diff --git a/src/index.js b/src/index.js index 68325bcacf99..09916d9f4f87 100644 --- a/src/index.js +++ b/src/index.js @@ -70,8 +70,8 @@ module.exports = { AnonymousGuild: require('./structures/AnonymousGuild'), Application: require('./structures/interfaces/Application'), ApplicationCommand: require('./structures/ApplicationCommand'), - ApplicationCommandInteraction: require('./structures/ApplicationCommandInteraction'), Base: require('./structures/Base'), + BaseCommandInteraction: require('./structures/BaseCommandInteraction'), BaseGuild: require('./structures/BaseGuild'), BaseGuildEmoji: require('./structures/BaseGuildEmoji'), BaseGuildTextChannel: require('./structures/BaseGuildTextChannel'), diff --git a/src/structures/ApplicationCommandInteraction.js b/src/structures/BaseCommandInteraction.js similarity index 94% rename from src/structures/ApplicationCommandInteraction.js rename to src/structures/BaseCommandInteraction.js index ff14810cff86..ec6eb4fd7f5d 100644 --- a/src/structures/ApplicationCommandInteraction.js +++ b/src/structures/BaseCommandInteraction.js @@ -7,26 +7,26 @@ const InteractionResponses = require('./interfaces/InteractionResponses'); const { ApplicationCommandOptionTypes } = require('../util/Constants'); /** - * Represents an application command interaction. + * Represents a command interaction. * @extends {Interaction} * @implements {InteractionResponses} * @abstract */ -class ApplicationCommandInteraction extends Interaction { +class BaseCommandInteraction extends Interaction { constructor(client, data) { super(client, data); /** * The channel this interaction was sent in * @type {?TextBasedChannels} - * @name ApplicationCommandInteraction#channel + * @name BaseCommandInteraction#channel * @readonly */ /** * The id of the channel this interaction was sent in * @type {Snowflake} - * @name ApplicationCommandInteraction#channelId + * @name BaseCommandInteraction#channelId */ /** @@ -190,9 +190,9 @@ class ApplicationCommandInteraction extends Interaction { followUp() {} } -InteractionResponses.applyToClass(ApplicationCommandInteraction, ['deferUpdate', 'update']); +InteractionResponses.applyToClass(BaseCommandInteraction, ['deferUpdate', 'update']); -module.exports = ApplicationCommandInteraction; +module.exports = BaseCommandInteraction; /* eslint-disable max-len */ /** diff --git a/src/structures/CommandInteraction.js b/src/structures/CommandInteraction.js index fe5cb77ed2ac..4c8bd5d7535a 100644 --- a/src/structures/CommandInteraction.js +++ b/src/structures/CommandInteraction.js @@ -1,13 +1,13 @@ 'use strict'; -const ApplicationCommandInteraction = require('./ApplicationCommandInteraction'); +const BaseCommandInteraction = require('./BaseCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); /** * Represents a command interaction. - * @extends {ApplicationCommandInteraction} + * @extends {BaseCommandInteraction} */ -class CommandInteraction extends ApplicationCommandInteraction { +class CommandInteraction extends BaseCommandInteraction { constructor(client, data) { super(client, data); diff --git a/src/structures/ContextMenuInteraction.js b/src/structures/ContextMenuInteraction.js index 38b7b0703f6b..f4f6ef47d274 100644 --- a/src/structures/ContextMenuInteraction.js +++ b/src/structures/ContextMenuInteraction.js @@ -1,14 +1,14 @@ 'use strict'; -const ApplicationCommandInteraction = require('./ApplicationCommandInteraction'); +const BaseCommandInteraction = require('./BaseCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); const { ApplicationCommandOptionTypes, ApplicationCommandTypes } = require('../util/Constants'); /** * Represents a context menu interaction. - * @extends {ApplicationCommandInteraction} + * @extends {BaseCommandInteraction} */ -class ContextMenuInteraction extends ApplicationCommandInteraction { +class ContextMenuInteraction extends BaseCommandInteraction { constructor(client, data) { super(client, data); /** diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 57106d247934..ccb4ee244aa9 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -137,7 +137,7 @@ class Interaction extends Base { } /** - * Indicates whether this interaction is an {@link AppplicationCommandInteraction}. + * Indicates whether this interaction is an {@link BaseCommandInteraction}. * @returns {boolean} */ isApplicationCommand() { diff --git a/typings/index.d.ts b/typings/index.d.ts index 14d93d911a76..9123c2cc94d2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -242,34 +242,6 @@ export class ApplicationCommand extends Base { private static isAPICommandData(command: object): command is RESTPostAPIApplicationCommandsJSONBody; } -export abstract class ApplicationCommandInteraction extends Interaction { - public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; - public readonly channel: TextBasedChannels | null; - public channelId: Snowflake; - public commandId: Snowflake; - public commandName: string; - public deferred: boolean; - public ephemeral: boolean | null; - public replied: boolean; - public webhook: InteractionWebhook; - public inGuild(): this is BaseGuildCommandInteraction<'present'> & this; - public inCachedGuild(): this is BaseGuildCommandInteraction<'cached'> & this; - public inRawGuild(): this is BaseGuildCommandInteraction<'raw'> & this; - public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise; - public deleteReply(): Promise; - public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; - public fetchReply(): Promise; - public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise; - public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise; - public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; - private transformOption( - option: APIApplicationCommandOption, - resolved: APIApplicationCommandInteractionData['resolved'], - ): CommandInteractionOption; - private transformResolved(resolved: APIApplicationCommandInteractionData['resolved']): CommandInteractionResolvedData; -} - export type ApplicationResolvable = Application | Activity | Snowflake; export class ApplicationFlags extends BitField { @@ -312,6 +284,34 @@ export interface BaseGuildCommandInteraction>; } +export abstract class BaseCommandInteraction extends Interaction { + public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; + public readonly channel: TextBasedChannels | null; + public channelId: Snowflake; + public commandId: Snowflake; + public commandName: string; + public deferred: boolean; + public ephemeral: boolean | null; + public replied: boolean; + public webhook: InteractionWebhook; + public inGuild(): this is BaseGuildCommandInteraction<'present'> & this; + public inCachedGuild(): this is BaseGuildCommandInteraction<'cached'> & this; + public inRawGuild(): this is BaseGuildCommandInteraction<'raw'> & this; + public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise; + public deferReply(options?: InteractionDeferReplyOptions): Promise; + public deleteReply(): Promise; + public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; + public fetchReply(): Promise; + public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise; + public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise; + public reply(options: string | MessagePayload | InteractionReplyOptions): Promise; + private transformOption( + option: APIApplicationCommandOption, + resolved: APIApplicationCommandInteractionData['resolved'], + ): CommandInteractionOption; + private transformResolved(resolved: APIApplicationCommandInteractionData['resolved']): CommandInteractionResolvedData; +} + export abstract class BaseGuild extends Base { protected constructor(client: Client, data: RawBaseGuildData); public readonly createdAt: Date; @@ -602,10 +602,7 @@ export abstract class Collector extends EventEmi export type GuildCommandInteraction = BaseGuildCommandInteraction & CommandInteraction; -export class CommandInteraction - extends ApplicationCommandInteraction - implements GuildCachedInteraction -{ +export class CommandInteraction extends BaseCommandInteraction implements GuildCachedInteraction { public options: CommandInteractionOptionResolver; } @@ -675,7 +672,7 @@ export interface GuildCachedInteraction { } export class ContextMenuInteraction - extends ApplicationCommandInteraction + extends BaseCommandInteraction implements GuildCachedInteraction { public options: CommandInteractionOptionResolver; @@ -1122,7 +1119,7 @@ export class Interaction extends Base { public inGuild(): this is GuildInteraction<'present'> & this; public inCachedGuild(): this is GuildInteraction<'cached'> & this; public inRawGuild(): this is GuildInteraction<'raw'> & this; - public isApplicationCommand(): this is ApplicationCommandInteraction; + public isApplicationCommand(): this is BaseCommandInteraction; public isButton(): this is ButtonInteraction; public isCommand(): this is CommandInteraction; public isContextMenu(): this is ContextMenuInteraction; From c038bf419ba596377d84cece3b48509bfa93df3b Mon Sep 17 00:00:00 2001 From: Hackerboi 69 Date: Sat, 9 Oct 2021 21:09:07 +0200 Subject: [PATCH 3/4] fix: spelling --- src/structures/Interaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index ccb4ee244aa9..5ecc463fbc21 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -137,7 +137,7 @@ class Interaction extends Base { } /** - * Indicates whether this interaction is an {@link BaseCommandInteraction}. + * Indicates whether this interaction is n {@link BaseCommandInteraction}. * @returns {boolean} */ isApplicationCommand() { From bb65b19c87aa069a54cd2271176fcec70eee3885 Mon Sep 17 00:00:00 2001 From: Hackerboi 69 Date: Sat, 9 Oct 2021 21:09:38 +0200 Subject: [PATCH 4/4] fix: spelling --- src/structures/Interaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 5ecc463fbc21..fa39123cc942 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -137,7 +137,7 @@ class Interaction extends Base { } /** - * Indicates whether this interaction is n {@link BaseCommandInteraction}. + * Indicates whether this interaction is a {@link BaseCommandInteraction}. * @returns {boolean} */ isApplicationCommand() {