-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.ts
53 lines (50 loc) · 1.47 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
import { type APIActionRowComponent, type APIActionRowComponentTypes, ComponentType } from 'discord-api-types/v10';
import { ActionRow } from './ActionRow';
import { Button } from './Button';
import { TextInput } from './Modal';
import {
ChannelSelectMenu,
MentionableSelectMenu,
RoleSelectMenu,
StringSelectMenu,
UserSelectMenu,
} from './SelectMenu';
import type { BuilderComponents } from './types';
export * from './ActionRow';
export * from './Attachment';
export * from './Base';
export * from './Button';
export * from './Embed';
export * from './Modal';
export * from './SelectMenu';
export * from './Poll';
export * from './types';
export function fromComponent(
data:
| BuilderComponents
| APIActionRowComponentTypes
| APIActionRowComponent<APIActionRowComponentTypes>
| ActionRow<BuilderComponents>,
): BuilderComponents | ActionRow<BuilderComponents> {
if ('toJSON' in data) {
return data;
}
switch (data.type) {
case ComponentType.Button:
return new Button(data);
case ComponentType.StringSelect:
return new StringSelectMenu(data);
case ComponentType.TextInput:
return new TextInput(data);
case ComponentType.UserSelect:
return new UserSelectMenu(data);
case ComponentType.RoleSelect:
return new RoleSelectMenu(data);
case ComponentType.MentionableSelect:
return new MentionableSelectMenu(data);
case ComponentType.ChannelSelect:
return new ChannelSelectMenu(data);
case ComponentType.ActionRow:
return new ActionRow(data);
}
}