Skip to content

Commit

Permalink
chore: make a few changes
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed May 4, 2023
1 parent aa473f9 commit 12df9cc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
Expand Up @@ -289,6 +289,10 @@ export class PaginatedMessage {

/**
* Sets the {@link PaginatedMessage.selectMenuPlaceholder} for this instance of {@link PaginatedMessage}.
*
* This applies only to the string select menu from the {@link PaginatedMessage.defaultActions}
* that offers "go to page" (we internally check the customId for this)
*
* This will only apply to this one instance and no others.
* @param placeholder The new placeholder to set
* @returns The current instance of {@link PaginatedMessage}
Expand Down Expand Up @@ -1277,6 +1281,7 @@ export class PaginatedMessage {

if (isMessageStringSelectInteractionData(interaction)) {
return new StringSelectMenuBuilder({
...interaction,
...(interaction.customId === '@sapphire/paginated-messages.goToPage' && {
options: await Promise.all(
this.pages.map(async (_, index) => {
Expand All @@ -1290,8 +1295,7 @@ export class PaginatedMessage {
})
),
placeholder: this.selectMenuPlaceholder
}),
...interaction
})
});
}

Expand Down Expand Up @@ -1528,6 +1532,7 @@ export class PaginatedMessage {
{
customId: '@sapphire/paginated-messages.goToPage',
type: ComponentType.StringSelect,
options: [],
run: ({ handler, interaction }) => interaction.isStringSelectMenu() && (handler.index = parseInt(interaction.values[0], 10))
},
{
Expand Down
Expand Up @@ -6,10 +6,12 @@ import type {
ActionRowComponentOptions,
ActionRowData,
BaseMessageOptions,
BaseSelectMenuComponentData,
ButtonInteraction,
ChannelSelectMenuComponentData,
ChannelType,
CollectedInteraction,
CommandInteraction,
ComponentType,
EmbedBuilder,
Guild,
Interaction,
Expand All @@ -19,19 +21,15 @@ import type {
InteractionUpdateOptions,
JSONEncodable,
LinkButtonComponentData,
MentionableSelectMenuComponentData,
Message,
MessageActionRowComponentBuilder,
MessageComponentInteraction,
MessageEditOptions,
MessageReplyOptions,
ModalSubmitInteraction,
RoleSelectMenuComponentData,
SelectMenuComponentOptionData,
StageChannel,
StringSelectMenuComponentData,
User,
UserSelectMenuComponentData,
VoiceChannel,
WebhookMessageEditOptions
} from 'discord.js';
Expand Down Expand Up @@ -92,15 +90,19 @@ export type PaginatedMessageActionLink = LinkButtonComponentData;
* }
* ```
*/
export type PaginatedMessageActionStringMenu = StringSelectMenuComponentData & PaginatedMessageActionRun;
type PaginatedMessageActionStringMenu = PaginatedMessageActionRun &
BaseSelectMenuComponentData & {
type: ComponentType.StringSelect;
options: SelectMenuComponentOptionData[];
};

/**
* To utilize User Select Menus you can pass an object with the structure of {@link PaginatedMessageActionUserMenu} to {@link PaginatedMessage} actions.
* @example
* ```typescript
* const UserMenu: PaginatedMessageActionUserMenu = {
* customId: 'CustomUserSelectMenu',
* type: ComponentType.ChannelSelect,
* type: ComponentType.UserSelect,
* run: ({ interaction }) => {
* if (interaction.isChannelSelectMenu()) {
* console.log(interaction.values[0])
Expand All @@ -109,7 +111,11 @@ export type PaginatedMessageActionStringMenu = StringSelectMenuComponentData & P
* }
* ```
*/
export type PaginatedMessageActionUserMenu = UserSelectMenuComponentData & PaginatedMessageActionRun;
type PaginatedMessageActionUserMenu = PaginatedMessageActionRun &
BaseSelectMenuComponentData & {
type: ComponentType.UserSelect;
options?: never;
};

/**
* To utilize Role Select Menus you can pass an object with the structure of {@link PaginatedMessageActionRoleMenu} to {@link PaginatedMessage} actions.
Expand All @@ -126,7 +132,11 @@ export type PaginatedMessageActionUserMenu = UserSelectMenuComponentData & Pagin
* }
* ```
*/
export type PaginatedMessageActionRoleMenu = RoleSelectMenuComponentData & PaginatedMessageActionRun;
type PaginatedMessageActionRoleMenu = PaginatedMessageActionRun &
BaseSelectMenuComponentData & {
type: ComponentType.RoleSelect;
options?: never;
};

/**
* To utilize Mentionable Select Menus you can pass an object with the structure of {@link PaginatedMessageActionMentionableMenu} to {@link PaginatedMessage} actions.
Expand All @@ -143,7 +153,11 @@ export type PaginatedMessageActionRoleMenu = RoleSelectMenuComponentData & Pagin
* }
* ```
*/
export type PaginatedMessageActionMentionableMenu = MentionableSelectMenuComponentData & PaginatedMessageActionRun;
type PaginatedMessageActionMentionableMenu = PaginatedMessageActionRun &
BaseSelectMenuComponentData & {
type: ComponentType.MentionableSelect;
options?: never;
};

/**
* To utilize Channel Select Menus you can pass an object with the structure of {@link PaginatedMessageActionChannelMenu} to {@link PaginatedMessage} actions.
Expand All @@ -161,7 +175,12 @@ export type PaginatedMessageActionMentionableMenu = MentionableSelectMenuCompone
* }
* ```
*/
export type PaginatedMessageActionChannelMenu = ChannelSelectMenuComponentData & PaginatedMessageActionRun;
type PaginatedMessageActionChannelMenu = PaginatedMessageActionRun &
BaseSelectMenuComponentData & {
type: ComponentType.ChannelSelect;
channelTypes?: ChannelType[];
options?: never;
};

/**
* The context to be used in {@link PaginatedMessageActionButton}.
Expand Down

0 comments on commit 12df9cc

Please sign in to comment.