mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-30 15:30:07 +00:00
* fix: check new types idea * fix: type errors * fix: new style * fix: more cleanup * fix: more cleanup * fix: cleanup audit logs * fix: cleanup stickers * fix: cleanup integrations * fix: more cleanup * fix: organize into 1 place * fix: few errors * fix: some broken import fixes * fix: quite a lot of fixes across the board * fix: more fixes for broken imports * fix: more fixes for broken imports * fix: handler imports * fix: all remaining import errors * fix: more errors needing fixes * fix: clearing up transformers * fix: few moer types * fix: more cleanup of extra types * fix: fmt * fix: cleanup discordeno file * Nuke Base Types (#2102) * fix: cleanup snake stuff * convert camelCase to snake_case (#2103) * fix: add camelize * fix: finalize remaining errors * fix: imports in test Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
96 lines
3.3 KiB
TypeScript
96 lines
3.3 KiB
TypeScript
import { Bot } from "../bot.ts";
|
|
import { ButtonStyles, MessageComponentTypes, TextStyles } from "../mod.ts";
|
|
import { DiscordComponent, DiscordSelectOption } from "../types/discord.ts";
|
|
|
|
export function transformComponent(bot: Bot, payload: DiscordComponent): Component {
|
|
return {
|
|
type: payload.type,
|
|
customId: payload.custom_id,
|
|
disabled: payload.disabled,
|
|
style: payload.style,
|
|
label: payload.label,
|
|
emoji: payload.emoji
|
|
? {
|
|
id: payload.emoji.id ? bot.transformers.snowflake(payload.emoji.id) : undefined,
|
|
name: payload.emoji.name,
|
|
animated: payload.emoji.animated,
|
|
}
|
|
: undefined,
|
|
url: payload.url,
|
|
options: payload.options?.map((option) => ({
|
|
label: option.label,
|
|
value: option.value,
|
|
description: option.description,
|
|
emoji: option.emoji
|
|
? {
|
|
id: option.emoji.id ? bot.transformers.snowflake(option.emoji.id) : undefined,
|
|
name: option.emoji.name,
|
|
animated: option.emoji.animated,
|
|
}
|
|
: undefined,
|
|
default: option.default,
|
|
})),
|
|
placeholder: payload.placeholder,
|
|
minValues: payload.min_values,
|
|
maxValues: payload.max_values,
|
|
components: payload.components?.map((component) => bot.transformers.component(bot, component)),
|
|
};
|
|
}
|
|
|
|
// export interface Component extends ReturnType<typeof transformComponent> {};
|
|
// THIS TRANSFORMER HAS A CIRCULAR REFERENCE TO CALL ITSELF FOR COMPONENTS SO AN AUTOMATED TYPE CAN NOT BE CREATED!
|
|
|
|
export interface Component {
|
|
/** component type */
|
|
type: MessageComponentTypes;
|
|
/** a developer-defined identifier for the component, max 100 characters */
|
|
customId?: string;
|
|
/** whether the component is disabled, default false */
|
|
disabled?: boolean;
|
|
/** For different styles/colors of the buttons */
|
|
style?: ButtonStyles | TextStyles;
|
|
/** text that appears on the button (max 80 characters) */
|
|
label?: string;
|
|
/** Emoji object that includes fields of name, id, and animated supporting unicode and custom emojis. */
|
|
emoji?: {
|
|
/** Emoji id */
|
|
id?: bigint;
|
|
/** Emoji name */
|
|
name?: string;
|
|
/** Whether this emoji is animated */
|
|
animated?: boolean;
|
|
};
|
|
/** optional url for link-style buttons that can navigate a user to the web. Only type 5 Link buttons can have a url */
|
|
url?: string;
|
|
/** The choices! Maximum of 25 items. */
|
|
options?: SelectOption[];
|
|
/** A custom placeholder text if nothing is selected. Maximum 100 characters. */
|
|
placeholder?: string;
|
|
/** The minimum number of items that must be selected. Default 1. Between 1-25. */
|
|
minValues?: number;
|
|
/** The maximum number of items that can be selected. Default 1. Between 1-25. */
|
|
maxValues?: number;
|
|
/** a list of child components */
|
|
components?: Component[];
|
|
}
|
|
|
|
export interface SelectOption {
|
|
/** The user-facing name of the option. Maximum 25 characters. */
|
|
label: string;
|
|
/** The dev-defined value of the option. Maximum 100 characters. */
|
|
value: string;
|
|
/** An additional description of the option. Maximum 50 characters. */
|
|
description?: string;
|
|
/** The id, name, and animated properties of an emoji. */
|
|
emoji?: {
|
|
/** Emoji id */
|
|
id?: bigint;
|
|
/** Emoji name */
|
|
name?: string;
|
|
/** Whether this emoji is animated */
|
|
animated?: boolean;
|
|
};
|
|
/** Will render this option as already-selected by default. */
|
|
default?: boolean;
|
|
}
|