mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 22:16:08 +00:00
fix: mentionables defaults (#162)
This commit is contained in:
parent
b46c16cd50
commit
52d8501d55
@ -177,6 +177,8 @@ export class RoleSelectMenu extends SelectMenu<APIRoleSelectComponent, RoleSelec
|
||||
}
|
||||
}
|
||||
|
||||
export type MentionableDefaultElement = { id: string; type: keyof Omit<typeof SelectMenuDefaultValueType, 'Channel'> };
|
||||
|
||||
/**
|
||||
* Represents a Select Menu for selecting mentionable entities.
|
||||
* @example
|
||||
@ -187,6 +189,34 @@ export class MentionableSelectMenu extends SelectMenu<APIMentionableSelectCompon
|
||||
constructor(data: Partial<APIMentionableSelectComponent> = {}) {
|
||||
super({ ...data, type: ComponentType.MentionableSelect });
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default selected roles or users for the select menu.
|
||||
* @param mentionables - Role/User id and type to be set as default.
|
||||
* @returns The current MentionableSelectMenu instance.
|
||||
*/
|
||||
setDefaults(...mentionables: RestOrArray<MentionableDefaultElement>) {
|
||||
this.data.default_values = mentionables.flat().map(mentionable => ({
|
||||
id: mentionable.id,
|
||||
type: SelectMenuDefaultValueType[mentionable.type],
|
||||
}));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds default selected roles or users for the select menu.
|
||||
* @param mentionables - Role/User id and type to be added as default.
|
||||
* @returns The current MentionableSelectMenu instance.
|
||||
*/
|
||||
addDefaultMentionables(...mentionables: RestOrArray<MentionableDefaultElement>) {
|
||||
this.data.default_values = (this.data.default_values ?? []).concat(
|
||||
mentionables.flat().map(mentionable => ({
|
||||
id: mentionable.id,
|
||||
type: SelectMenuDefaultValueType[mentionable.type],
|
||||
})),
|
||||
);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user