Skip to content

Commit

Permalink
refactor(interactions): use the new channel field (#63)
Browse files Browse the repository at this point in the history
* refactor(interactions): use the new `channel` field

Ref: discord/discord-api-docs@88a7618

* use a better type for PossiblyUncachedInteractionChannel
  • Loading branch information
TTtie committed May 11, 2023
1 parent 465bb62 commit 8b8a0ac
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
9 changes: 5 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare namespace Dysnomia {
type GuildTextableChannel = TextChannel | TextVoiceChannel | NewsChannel | StageChannel;
type GuildTextableWithThreads = GuildTextableChannel | AnyThreadChannel;
type InviteChannel = InvitePartialChannel | Exclude<AnyGuildChannel, CategoryChannel | AnyThreadChannel>;
type PossiblyUncachedInteractionChannel = TextableChannel | PartialChannel;
type PossiblyUncachedSpeakableChannel = VoiceChannel | StageChannel | Uncached;
type PossiblyUncachedTextable = Textable | Uncached;
type PossiblyUncachedTextableChannel = TextableChannel | Uncached;
Expand Down Expand Up @@ -2474,7 +2475,7 @@ declare namespace Dysnomia {
}

// Classes
export class AutocompleteInteraction<T extends PossiblyUncachedTextable = TextableChannel> extends Interaction {
export class AutocompleteInteraction<T extends PossiblyUncachedInteractionChannel = TextableChannel> extends Interaction {
appPermissions?: Permission;
channel: T;
data: AutocompleteInteractionData;
Expand Down Expand Up @@ -2941,7 +2942,7 @@ declare namespace Dysnomia {
toString(): string;
}

export class CommandInteraction<T extends PossiblyUncachedTextable = TextableChannel> extends Interaction {
export class CommandInteraction<T extends PossiblyUncachedInteractionChannel = TextableChannel> extends Interaction {
appPermissions?: Permission;
channel: T;
data: CommandInteractionData;
Expand Down Expand Up @@ -2969,7 +2970,7 @@ declare namespace Dysnomia {
getOriginalMessage(): Promise<Message>;
}

export class ComponentInteraction<T extends PossiblyUncachedTextable = TextableChannel> extends Interaction {
export class ComponentInteraction<T extends PossiblyUncachedInteractionChannel = TextableChannel> extends Interaction {
appPermissions?: Permission;
channel: T;
data: ComponentInteractionButtonData | ComponentInteractionSelectMenuData;
Expand Down Expand Up @@ -3494,7 +3495,7 @@ declare namespace Dysnomia {
unpin(): Promise<void>;
}

export class ModalSubmitInteraction<T extends PossiblyUncachedTextable = TextableChannel> extends Interaction {
export class ModalSubmitInteraction<T extends PossiblyUncachedInteractionChannel = TextableChannel> extends Interaction {
channel: T;
data: ModalSubmitInteractionData;
guildID?: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/AutocompleteInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {InteractionResponseTypes} = require("../Constants");
* Represents an application command autocomplete interaction. See Interaction for more properties.
* @extends Interaction
* @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id and type if the channel is not cached
* @prop {Object} data The data attached to the interaction
* @prop {String} data.id The ID of the Application Command
* @prop {String} data.name The command name
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {InteractionResponseTypes} = require("../Constants");
* Represents an application command interaction. See Interaction for more properties.
* @extends Interaction
* @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id and type if the channel is not cached
* @prop {Object} data The data attached to the interaction
* @prop {String} data.id The ID of the Application Command
* @prop {String} data.name The command name
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/ComponentInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {InteractionResponseTypes} = require("../Constants");
* Represents a message component interaction. See Interaction for more properties
* @extends Interaction
* @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id and type if the channel is not cached
* @prop {Object} data The data attached to the interaction
* @prop {Number} data.component_type The type of Message Component
* @prop {String} data.custom_id The ID of the Message Component
Expand Down
8 changes: 3 additions & 5 deletions lib/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Permission = require("./Permission");
* @prop {Boolean} acknowledged Whether or not the interaction has been acknowledged
* @prop {String} applicationID The ID of the interaction's application
* @prop {Permission?} appPermissions The permissions the app or bot has within the channel the interaction was sent from
* @prop {(PrivateChannel | TextChannel | NewsChannel)?} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached.
* @prop {(PrivateChannel | TextChannel | NewsChannel)?} channel The channel the interaction was created in. Can be partial with only the id and type if the channel is not cached.
* @prop {Object} data The data attached to the interaction. See AutocompleteInteraction, CommandInteraction, and ComponentInteraction for specific details
* @prop {String?} guildID The ID of the guild in which the interaction was created
* @prop {String?} guildLocale The selected language of the guild the command was invoked from (e.g. "en-US")
Expand All @@ -33,10 +33,8 @@ class Interaction extends Base {
this.version = data.version;
this.acknowledged = false;

if(data.channel_id !== undefined) {
this.channel = this._client.getChannel(data.channel_id) || {
id: data.channel_id
};
if(data.channel !== undefined) {
this.channel = this._client.getChannel(data.channel.id) || data.channel;
}

if(data.data !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/ModalSubmitInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {InteractionResponseTypes} = require("../Constants");
/**
* Represents a modal submit interaction. See Interaction for more properties
* @extends Interaction
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id if the channel is not cached
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the interaction was created in. Can be partial with only the id and type if the channel is not cached
* @prop {Object} data The data attached to the interaction
* @prop {String} data.custom_id The ID of the Modal
* @prop {Array<Object>} data.components The values submitted by the user
Expand Down

0 comments on commit 8b8a0ac

Please sign in to comment.