diff --git a/index.d.ts b/index.d.ts index 299eb3e3d..519eb315d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -146,6 +146,7 @@ declare namespace Dysnomia { // Message type ActionRowComponents = Button | SelectMenu; + type BaseSelectMenuTypes = Exclude; type Button = InteractionButton | URLButton; type ButtonStyles = Constants["ButtonStyles"][keyof Constants["ButtonStyles"]]; type ButtonStyleNormal = Exclude; @@ -158,6 +159,10 @@ declare namespace Dysnomia { type MessageContentEdit = string | AdvancedMessageContentEdit; type MFALevel = Constants["MFALevels"][keyof Constants["MFALevels"]]; type PossiblyUncachedMessage = Message | { channel: TextableChannel | { id: string; guild?: Uncached }; guildID?: string; id: string }; + type SelectMenu = BaseSelectMenu | ChannelSelectMenu | StringSelectMenu; + type SelectMenuTypes = Constants["ComponentTypes"][keyof Pick]; + type SelectMenuExtendedTypes = Constants["ComponentTypes"][keyof Pick]; + // Permission type PermissionType = Constants["PermissionOverwriteTypes"][keyof Constants["PermissionOverwriteTypes"]]; @@ -1126,12 +1131,9 @@ declare namespace Dysnomia { resolved?: CommandInteractionResolvedData; options?: InteractionDataOptions[]; } - interface CommandInteractionResolvedData { - channels?: Collection; - members?: Collection; + interface CommandInteractionResolvedData extends InteractionResolvedData { + attachments?: Collection; messages?: Collection; - roles?: Collection; - users?: Collection; } interface ComponentInteractionButtonData { @@ -1140,36 +1142,10 @@ declare namespace Dysnomia { } interface ComponentInteractionSelectMenuData { - component_type: Constants["ComponentTypes"]["SELECT_MENU"]; - custom_id: string; - values: string[]; - } - interface InteractionAutocomplete { - choices: ApplicationCommandOptionsChoice[]; - } - interface CommandInteractionData { - id: string; - name: string; - type: ApplicationCommandTypes; - target_id?: string; - resolved?: CommandInteractionResolvedData; - options?: InteractionDataOptions[]; - } - interface CommandInteractionResolvedData { - channels?: Collection; - members?: Collection; - messages?: Collection; - roles?: Collection; - users?: Collection; - } - interface InteractionComponentButtonData { - component_type: Constants["ComponentTypes"]["BUTTON"]; - custom_id: string; - } - interface InteractionComponentSelectMenuData { - component_type: Constants["ComponentTypes"]["SELECT_MENU"]; + component_type: SelectMenuTypes; custom_id: string; values: string[]; + resolved?: InteractionResolvedData; } interface InteractionDataOptionsBase { focused?: T extends ApplicationCommandOptionsTypesWithAutocomplete ? boolean : never; @@ -1189,6 +1165,12 @@ declare namespace Dysnomia { custom_id: string; components: ModalContentActionRow[]; } + interface InteractionResolvedData { + channels?: Collection; + members?: Collection; + roles?: Collection; + users?: Collection; + } interface InteractionResponseAutocomplete { data: ApplicationCommandOptionsChoice[]; type: Constants["InteractionResponseTypes"]["APPLICATION_COMMAND_AUTOCOMPLETE_RESULT"]; @@ -1316,6 +1298,10 @@ declare namespace Dysnomia { label?: string; type: Constants["ComponentTypes"]["BUTTON"]; } + interface ChannelSelectMenu extends SelectMenuBase { + channel_types?: GuildChannelTypes[]; + type: Constants["ComponentTypes"]["CHANNEL_SELECT"]; + } interface CreateStickerOptions extends Required> { file: FileContent; } @@ -1324,14 +1310,20 @@ declare namespace Dysnomia { name?: string; tags?: string; } - interface SelectMenu { + interface BaseSelectMenu extends SelectMenuBase { + type: BaseSelectMenuTypes; + } + interface SelectMenuBase { custom_id: string; disabled?: boolean; max_values?: number; min_values?: number; - options: SelectMenuOptions[]; placeholder?: string; - type: Constants["ComponentTypes"]["SELECT_MENU"]; + type: SelectMenuTypes; + } + interface StringSelectMenu extends SelectMenuBase { + options: SelectMenuOptions[]; + type: Constants["ComponentTypes"]["STRING_SELECT"]; } interface SelectMenuOptions { default?: boolean; @@ -1873,10 +1865,16 @@ declare namespace Dysnomia { GUILD_STAGE_VOICE: 13; }; ComponentTypes: { - ACTION_ROW: 1; - BUTTON: 2; - SELECT_MENU: 3; - TEXT_INPUT: 4; + ACTION_ROW: 1; + BUTTON: 2; + STRING_SELECT: 3; + /** @deprecated */ + SELECT_MENU: 3; + TEXT_INPUT: 4; + USER_SELECT: 5; + ROLE_SELECT: 6; + MENTIONABLE_SELECT: 7; + CHANNEL_SELECT: 8; }; ConnectionVisibilityTypes: { NONE: 0; diff --git a/lib/Constants.js b/lib/Constants.js index 88cae4aaa..3338bd0f8 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -190,10 +190,14 @@ module.exports.ChannelTypes = { }; module.exports.ComponentTypes = { - ACTION_ROW: 1, - BUTTON: 2, - SELECT_MENU: 3, - TEXT_INPUT: 4 + ACTION_ROW: 1, + BUTTON: 2, + STRING_SELECT: 3, SELECT_MENU: 3, // [DEPRECATED] + TEXT_INPUT: 4, + USER_SELECT: 5, + ROLE_SELECT: 6, + MENTIONABLE_SELECT: 7, + CHANNEL_SELECT: 8 }; module.exports.ConnectionVisibilityTypes = { diff --git a/lib/structures/ComponentInteraction.js b/lib/structures/ComponentInteraction.js index 9882fa561..872f79258 100644 --- a/lib/structures/ComponentInteraction.js +++ b/lib/structures/ComponentInteraction.js @@ -1,7 +1,12 @@ "use strict"; const Interaction = require("./Interaction"); +const Member = require("./Member"); +const User = require("./User"); +const Role = require("./Role"); +const Channel = require("./Channel"); const Message = require("./Message"); +const Collection = require("../util/Collection"); const Permission = require("./Permission"); const {InteractionResponseTypes} = require("../Constants"); @@ -13,6 +18,11 @@ const {InteractionResponseTypes} = require("../Constants"); * @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 +* @prop {Object?} data.resolved resolved objects within the interaction (e.x. the user for a user option) (select menus only) +* @prop {Collection?} data.resolved.channels resolved channels +* @prop {Collection?} data.resolved.members resolved members +* @prop {Collection?} data.resolved.roles resolved roles +* @prop {Collection?} data.resolved.users resolved users * @prop {Array?} data.values The value of the run selected options (Select Menus Only) * @prop {String?} guildID The ID of the guild in which the interaction was created * @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild) @@ -27,7 +37,49 @@ class ComponentInteraction extends Interaction { id: data.channel_id }; - this.data = data.data; + this.data = JSON.parse(JSON.stringify(data.data)); + + if(data.data.resolved !== undefined) { + //Users + if(data.data.resolved.users !== undefined) { + const usermap = new Collection(User); + Object.entries(data.data.resolved.users).forEach(([id, user]) => { + usermap.set(id, this._client.users.update(user, client)); + }); + this.data.resolved.users = usermap; + } + //Members + if(data.data.resolved.members !== undefined) { + const membermap = new Collection(Member); + Object.entries(data.data.resolved.members).forEach(([id, member]) => { + member.id = id; + member.user = {id}; + if(this.channel.guild) { + membermap.set(id, this.channel.guild.members.update(member, this.channel.guild)); + } else { + const guild = this._client.guilds.get(data.guild_id); + membermap.set(id, guild.members.update(member, guild)); + } + }); + this.data.resolved.members = membermap; + } + //Roles + if(data.data.resolved.roles !== undefined) { + const rolemap = new Collection(Role); + Object.entries(data.data.resolved.roles).forEach(([id, role]) => { + rolemap.set(id, new Role(role, this.channel.guild)); + }); + this.data.resolved.roles = rolemap; + } + //Channels + if(data.data.resolved.channels !== undefined) { + const channelmap = new Collection(Channel); + Object.entries(data.data.resolved.channels).forEach(([id, channel]) => { + channelmap.set(id, Channel.from(channel, this._client) || new Channel(channel, this._client)); + }); + this.data.resolved.channels = channelmap; + } + } if(data.guild_id !== undefined) { this.guildID = data.guild_id;