seyfert/src/builders/index.ts
Marcos Susaña bd951397a2
feat: Reduce dependencies (#221)
* feat: add support for new Discord application emojis features

* feat: add support for new Discord application emojis features

* feat: applications emojis routes

* chore: switch typings provider

* fix: unnecesary type

* feat: magic bytes

* chore: move api-types

* chore: ?

* fix: omg npm

* chore: apply formatting

* fix: for fast merge

---------

Co-authored-by: Tony Supremacy <165050835+VanStk@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-07-21 22:58:40 -04:00

54 lines
1.5 KiB
TypeScript

import { type APIActionRowComponent, type APIActionRowComponentTypes, ComponentType } from '../types';
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);
}
}