seyfert/src/components/BaseComponent.ts
David 017ccfc3bf
fix: github actions (#210)
* fix: github actions

* fix: pnpm version

* fix: github actions checkout

* fix: brackets in failure function

* fix: github actions

* fix: github actions

* fix: github actions

* fix: github actions

* fix: github actions

* fix: github actions

* fix: github actions

* fix: github actions

* chore: apply formatting

* fix: github actions

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-06-14 14:23:58 -04:00

40 lines
1.1 KiB
TypeScript

import {
type APIActionRowComponent,
type APIActionRowComponentTypes,
type APIButtonComponent,
type APIChannelSelectComponent,
type APIMentionableSelectComponent,
type APIRoleSelectComponent,
type APIStringSelectComponent,
type APITextInputComponent,
type APIUserSelectComponent,
ComponentType,
} from 'discord-api-types/v10';
import { fromComponent } from '../builders';
export class BaseComponent<T extends ComponentType> {
constructor(public data: APIComponentsMap[T]) {}
get type() {
return this.data.type;
}
toJSON() {
return this.data;
}
toBuilder() {
return fromComponent(this.data);
}
}
export interface APIComponentsMap {
[ComponentType.ActionRow]: APIActionRowComponent<APIActionRowComponentTypes>;
[ComponentType.Button]: APIButtonComponent;
[ComponentType.ChannelSelect]: APIChannelSelectComponent;
[ComponentType.MentionableSelect]: APIMentionableSelectComponent;
[ComponentType.RoleSelect]: APIRoleSelectComponent;
[ComponentType.StringSelect]: APIStringSelectComponent;
[ComponentType.UserSelect]: APIUserSelectComponent;
[ComponentType.TextInput]: APITextInputComponent;
}