1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 04:32:35 +01:00

Fix msg component typings

This commit is contained in:
TomatoCake 2024-07-19 15:09:02 +02:00 committed by Madeline
parent f047f93b77
commit a887608d30
5 changed files with 104285 additions and 2538 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -216,7 +216,7 @@ export class Message extends BaseClass {
};
@Column({ type: "simple-json", nullable: true })
components?: MessageComponent[];
components?: ActionRowComponent[];
@Column({ type: "simple-json", nullable: true })
poll?: Poll;
@ -248,21 +248,90 @@ export class Message extends BaseClass {
}
export interface MessageComponent {
type: number;
style?: number;
type: MessageComponentType;
}
export interface ActionRowComponent extends MessageComponent {
type: MessageComponentType.ActionRow;
components: (ButtonComponent | StringSelectMenuComponent | SelectMenuComponent | TextInputComponent)[];
}
export interface ButtonComponent extends MessageComponent {
type: MessageComponentType.Button;
style: ButtonStyle;
label?: string;
emoji?: PartialEmoji;
custom_id?: string;
sku_id?: string;
url?: string;
disabled?: boolean;
components: MessageComponent[];
}
export enum ButtonStyle {
Primary = 1,
Secondary = 2,
Success = 3,
Danger = 4,
Link = 5,
Premium = 6,
}
export interface SelectMenuComponent extends MessageComponent {
type: MessageComponentType.StringSelect | MessageComponentType.UserSelect | MessageComponentType.RoleSelect | MessageComponentType.MentionableSelect | MessageComponentType.ChannelSelect;
custom_id: string;
channel_types?: number[];
placeholder?: string;
default_values?: SelectMenuDefaultOption[]; // only for non-string selects
min_values?: number;
max_values?: number;
disabled?: boolean;
}
export interface SelectMenuOption {
label: string;
value: string;
description?: string;
emoji?: PartialEmoji;
default?: boolean;
}
export interface SelectMenuDefaultOption {
id: string;
type: "user" | "role" | "channel";
}
export interface StringSelectMenuComponent extends SelectMenuComponent {
type: MessageComponentType.StringSelect;
options: SelectMenuOption[];
}
export interface TextInputComponent extends MessageComponent {
type: MessageComponentType.TextInput;
custom_id: string;
style: TextInputStyle;
label: string;
min_length?: number;
max_length?: number;
required?: boolean;
value?: string;
placeholder?: string;
}
export enum TextInputStyle {
Short = 1,
Paragraph = 2,
}
export enum MessageComponentType {
Script = 0, // self command script
ActionRow = 1,
Button = 2,
StringSelect = 3,
TextInput = 4,
UserSelect = 5,
RoleSelect = 6,
MentionableSelect = 7,
ChannelSelect = 8,
}
export interface Embed {

View File

@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Embed, MessageComponent, PollAnswer, PollMedia } from "@spacebar/util";
import { ActionRowComponent, Embed, PollAnswer, PollMedia } from "@spacebar/util";
type Attachment = {
id: string;
@ -54,7 +54,7 @@ export interface MessageCreateSchema {
**/
attachments?: Attachment[];
sticker_ids?: string[];
components?: MessageComponent[];
components?: ActionRowComponent[];
// TODO: Fix TypeScript errors in src\api\util\handlers\Message.ts once this is enabled
poll?: PollCreationSchema;
enforce_nonce?: boolean; // For Discord compatibility, it's the default behavior here

View File

@ -17,9 +17,9 @@
*/
import {
ActionRowComponent,
Attachment,
Embed,
MessageComponent,
MessageType,
Poll,
PublicUser,
@ -42,7 +42,7 @@ export interface GuildMessagesSearchMessage {
timestamp: string;
edited_timestamp: string | null;
flags: number;
components: MessageComponent[];
components: ActionRowComponent[];
poll: Poll;
hit: true;
}