-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.ts
54 lines (50 loc) · 2.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { type APIMessageActionRowComponent, ButtonStyle, ComponentType } from 'discord-api-types/v10';
import { BaseComponent } from './BaseComponent';
import { ButtonComponent, LinkButtonComponent } from './ButtonComponent';
import { ChannelSelectMenuComponent } from './ChannelSelectMenuComponent';
import { MentionableSelectMenuComponent } from './MentionableSelectMenuComponent';
import { RoleSelectMenuComponent } from './RoleSelectMenuComponent';
import { StringSelectMenuComponent } from './StringSelectMenuComponent';
import type { TextInputComponent } from './TextInputComponent';
import { UserSelectMenuComponent } from './UserSelectMenuComponent';
export type MessageComponents =
| ButtonComponent
| LinkButtonComponent
| RoleSelectMenuComponent
| UserSelectMenuComponent
| StringSelectMenuComponent
| ChannelSelectMenuComponent
| MentionableSelectMenuComponent
| TextInputComponent;
export type ActionRowMessageComponents = Exclude<MessageComponents, TextInputComponent>;
export * from './command';
export * from './componentcontext';
/**
* Return a new component instance based on the component type.
*
* @param component The component to create.
* @returns The component instance.
*/
export function componentFactory(
component: APIMessageActionRowComponent,
): ActionRowMessageComponents | BaseComponent<ActionRowMessageComponents['type']> {
switch (component.type) {
case ComponentType.Button:
if (component.style === ButtonStyle.Link) {
return new LinkButtonComponent(component);
}
return new ButtonComponent(component);
case ComponentType.ChannelSelect:
return new ChannelSelectMenuComponent(component);
case ComponentType.RoleSelect:
return new RoleSelectMenuComponent(component);
case ComponentType.StringSelect:
return new StringSelectMenuComponent(component);
case ComponentType.UserSelect:
return new UserSelectMenuComponent(component);
case ComponentType.MentionableSelect:
return new MentionableSelectMenuComponent(component);
default:
return new BaseComponent<ActionRowMessageComponents['type']>(component);
}
}