fix: restore backwards compatibility

This commit is contained in:
Yuzu 2022-08-20 02:47:05 -05:00
parent f62b8c1854
commit ab4b1f0d74
3 changed files with 24 additions and 27 deletions

View File

@ -15,7 +15,7 @@ import type { Channel } from './channels';
import type { Component } from './components'; import type { Component } from './components';
import type { MessageInteraction } from './interactions'; import type { MessageInteraction } from './interactions';
import type { StickerItem } from './sticker'; import type { StickerItem } from './sticker';
import type { Embed } from './embed'; import { Embed, NewEmbed } from './embed';
import { MessageFlags } from '../utils/util'; import { MessageFlags } from '../utils/util';
import { Snowflake } from '../snowflakes'; import { Snowflake } from '../snowflakes';
import { ChannelFactory, ThreadChannel } from './channels'; import { ChannelFactory, ThreadChannel } from './channels';
@ -424,7 +424,7 @@ export class Message implements Model {
replied_user: options.allowedMentions?.repliedUser, replied_user: options.allowedMentions?.repliedUser,
}, },
flags: options.flags, flags: options.flags,
embeds: options.embeds, embeds: options.embeds?.map(NewEmbed),
components: options.components, components: options.components,
files: options.files, files: options.files,
attachments: options.attachments attachments: options.attachments
@ -479,7 +479,7 @@ export class Message implements Model {
true, true,
} }
: undefined, : undefined,
embeds: options.embeds, embeds: options.embeds?.map(NewEmbed),
tts: options.tts, tts: options.tts,
components: options.components, components: options.components,
} }

View File

@ -1,4 +1,4 @@
import { DiscordEmbed, DiscordEmbedField, DiscordEmbedProvider } from '@biscuitland/api-types'; import type { Embed } from '@biscuitland/core';
export interface EmbedFooter { export interface EmbedFooter {
text: string; text: string;
@ -21,20 +21,26 @@ export interface EmbedVideo {
width?: number; width?: number;
} }
export interface EmbedField {
name: string;
value: string;
inline?: boolean;
}
export interface EmbedProvider {
url?: string;
name?: string;
}
export class EmbedBuilder { export class EmbedBuilder {
#data: DiscordEmbed; #data: Embed;
constructor(data: DiscordEmbed = {}) { constructor(data: Embed = {}) {
this.#data = data; this.#data = data;
if (!this.#data.fields) this.#data.fields = []; if (!this.#data.fields) this.#data.fields = [];
} }
setAuthor(author: EmbedAuthor): EmbedBuilder { setAuthor(author: EmbedAuthor): EmbedBuilder {
this.#data.author = { this.#data.author = author;
name: author.name,
icon_url: author.iconUrl,
proxy_icon_url: author.proxyIconUrl,
url: author.url,
};
return this; return this;
} }
@ -48,17 +54,13 @@ export class EmbedBuilder {
return this; return this;
} }
addField(field: DiscordEmbedField): EmbedBuilder { addField(field: EmbedField): EmbedBuilder {
this.#data.fields!.push(field); this.#data.fields!.push(field);
return this; return this;
} }
setFooter(footer: EmbedFooter): EmbedBuilder { setFooter(footer: EmbedFooter): EmbedBuilder {
this.#data.footer = { this.#data.footer = footer;
text: footer.text,
icon_url: footer.iconUrl,
proxy_icon_url: footer.proxyIconUrl,
};
return this; return this;
} }
@ -67,7 +69,7 @@ export class EmbedBuilder {
return this; return this;
} }
setProvider(provider: DiscordEmbedProvider): EmbedBuilder { setProvider(provider: EmbedProvider): EmbedBuilder {
this.#data.provider = provider; this.#data.provider = provider;
return this; return this;
} }
@ -94,16 +96,11 @@ export class EmbedBuilder {
} }
setVideo(video: EmbedVideo): EmbedBuilder { setVideo(video: EmbedVideo): EmbedBuilder {
this.#data.video = { this.#data.video = video;
height: video.height,
proxy_url: video.proxyUrl,
url: video.url,
width: video.width,
};
return this; return this;
} }
toJSON(): DiscordEmbed { toJSON(): Embed {
return this.#data; return this.#data;
} }
} }

View File

@ -13,4 +13,4 @@ export * from './builders/slash/ApplicationCommand';
export * from './builders/slash/ApplicationCommandOption'; export * from './builders/slash/ApplicationCommandOption';
// Embed // Embed
export * from './builders/embed-builder'; export * from './builders/embeds/embed-builder';