new select menus (#122)

This commit is contained in:
MARCROCK22 2022-11-05 11:40:28 -04:00 committed by GitHub
parent 6a5fce0f58
commit f6b745c726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 139 additions and 109 deletions

View File

@ -79,6 +79,14 @@ export enum MessageComponentTypes {
SelectMenu = 3, SelectMenu = 3,
/** A text input object */ /** A text input object */
InputText = 4, InputText = 4,
/** A select menu for picking from users */
UserSelect = 5,
/** A select menu for picking from roles */
RoleSelect = 6,
/** A select menu for picking from users and roles */
MentionableSelect = 7,
/** A select menu for picking from channels */
ChannelSelect = 8
} }
export enum TextStyles { export enum TextStyles {

View File

@ -1187,7 +1187,11 @@ export interface DiscordActionRow {
} }
export interface DiscordSelectMenuComponent { export interface DiscordSelectMenuComponent {
type: MessageComponentTypes.SelectMenu; type: MessageComponentTypes.SelectMenu |
MessageComponentTypes.RoleSelect |
MessageComponentTypes.UserSelect |
MessageComponentTypes.MentionableSelect |
MessageComponentTypes.ChannelSelect;
/** A custom identifier for this component. Maximum 100 characters. */ /** A custom identifier for this component. Maximum 100 characters. */
custom_id: string; custom_id: string;
/** A custom placeholder text if nothing is selected. Maximum 150 characters. */ /** A custom placeholder text if nothing is selected. Maximum 150 characters. */

View File

@ -223,6 +223,10 @@ export class ActionRow extends BaseComponent implements ActionRowComponent {
} }
return new Button(session, component); return new Button(session, component);
case MessageComponentTypes.SelectMenu: case MessageComponentTypes.SelectMenu:
case MessageComponentTypes.RoleSelect:
case MessageComponentTypes.UserSelect:
case MessageComponentTypes.MentionableSelect:
case MessageComponentTypes.ChannelSelect:
return new SelectMenu(session, component); return new SelectMenu(session, component);
case MessageComponentTypes.InputText: case MessageComponentTypes.InputText:
return new TextInput( return new TextInput(
@ -257,6 +261,10 @@ export class ComponentFactory {
} }
return new Button(session, component); return new Button(session, component);
case MessageComponentTypes.SelectMenu: case MessageComponentTypes.SelectMenu:
case MessageComponentTypes.RoleSelect:
case MessageComponentTypes.UserSelect:
case MessageComponentTypes.MentionableSelect:
case MessageComponentTypes.ChannelSelect:
return new SelectMenu(session, component); return new SelectMenu(session, component);
case MessageComponentTypes.InputText: case MessageComponentTypes.InputText:
return new TextInput( return new TextInput(

View File

@ -47,9 +47,19 @@ export class SelectMenuBuilder {
} }
#data: DiscordSelectMenuComponent; #data: DiscordSelectMenuComponent;
type: MessageComponentTypes.SelectMenu; type: MessageComponentTypes.SelectMenu |
MessageComponentTypes.RoleSelect |
MessageComponentTypes.UserSelect |
MessageComponentTypes.MentionableSelect |
MessageComponentTypes.ChannelSelect;
options: SelectMenuOptionBuilder[]; options: SelectMenuOptionBuilder[];
setType(type: this['type']) {
this.type = type;
return this;
}
setPlaceholder(placeholder: string): this { setPlaceholder(placeholder: string): this {
this.#data.placeholder = placeholder; this.#data.placeholder = placeholder;
return this; return this;

View File

@ -73,7 +73,7 @@ export class DefaultRestAdapter implements RestAdapter {
private url: string; private url: string;
constructor(options: DefaultRestOptions) { constructor(options: DefaultRestOptions) {
this.options = Object.assign(Object.create(DefaultRestAdapter.DEFAULTS), options); this.options = Object.assign({}, DefaultRestAdapter.DEFAULTS, options);
if (this.options.url) { if (this.options.url) {
this.url = `${options.url}/v${this.options.version}`; this.url = `${options.url}/v${this.options.version}`;

View File

@ -33,7 +33,7 @@ export class ShardManager {
readonly shards = new Map<number, Shard>(); readonly shards = new Map<number, Shard>();
constructor(options: ShardManagerOptions) { constructor(options: ShardManagerOptions) {
this.options = Options({}, ShardManager.DEFAULTS, options); this.options = Options(ShardManager.DEFAULTS, options);
} }
/** Invokes internal processing and respawns shards */ /** Invokes internal processing and respawns shards */

View File

@ -27,7 +27,7 @@ export class Shard {
resumeURL: string | null = null; resumeURL: string | null = null;
sessionID: string | null = null; sessionID: string | null = null;
sequence = 0 ; sequence = 0;
resolves: Map<string, (payload?: unknown) => void> = new Map(); resolves: Map<string, (payload?: unknown) => void> = new Map();
@ -40,7 +40,7 @@ export class Shard {
ws: WebSocket | null = null; ws: WebSocket | null = null;
constructor(options: ShardOptions) { constructor(options: ShardOptions) {
this.options = Options({}, Shard.DEFAULTS, options); this.options = Options(Shard.DEFAULTS, options);
this.bucket = createLeakyBucket({ this.bucket = createLeakyBucket({
max: 120, max: 120,