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 { MessageInteraction } from './interactions';
import type { StickerItem } from './sticker';
import type { Embed } from './embed';
import { Embed, NewEmbed } from './embed';
import { MessageFlags } from '../utils/util';
import { Snowflake } from '../snowflakes';
import { ChannelFactory, ThreadChannel } from './channels';
@ -424,7 +424,7 @@ export class Message implements Model {
replied_user: options.allowedMentions?.repliedUser,
},
flags: options.flags,
embeds: options.embeds,
embeds: options.embeds?.map(NewEmbed),
components: options.components,
files: options.files,
attachments: options.attachments
@ -479,7 +479,7 @@ export class Message implements Model {
true,
}
: undefined,
embeds: options.embeds,
embeds: options.embeds?.map(NewEmbed),
tts: options.tts,
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 {
text: string;
@ -21,20 +21,26 @@ export interface EmbedVideo {
width?: number;
}
export interface EmbedField {
name: string;
value: string;
inline?: boolean;
}
export interface EmbedProvider {
url?: string;
name?: string;
}
export class EmbedBuilder {
#data: DiscordEmbed;
constructor(data: DiscordEmbed = {}) {
#data: Embed;
constructor(data: Embed = {}) {
this.#data = data;
if (!this.#data.fields) this.#data.fields = [];
}
setAuthor(author: EmbedAuthor): EmbedBuilder {
this.#data.author = {
name: author.name,
icon_url: author.iconUrl,
proxy_icon_url: author.proxyIconUrl,
url: author.url,
};
this.#data.author = author;
return this;
}
@ -48,17 +54,13 @@ export class EmbedBuilder {
return this;
}
addField(field: DiscordEmbedField): EmbedBuilder {
addField(field: EmbedField): EmbedBuilder {
this.#data.fields!.push(field);
return this;
}
setFooter(footer: EmbedFooter): EmbedBuilder {
this.#data.footer = {
text: footer.text,
icon_url: footer.iconUrl,
proxy_icon_url: footer.proxyIconUrl,
};
this.#data.footer = footer;
return this;
}
@ -67,7 +69,7 @@ export class EmbedBuilder {
return this;
}
setProvider(provider: DiscordEmbedProvider): EmbedBuilder {
setProvider(provider: EmbedProvider): EmbedBuilder {
this.#data.provider = provider;
return this;
}
@ -94,16 +96,11 @@ export class EmbedBuilder {
}
setVideo(video: EmbedVideo): EmbedBuilder {
this.#data.video = {
height: video.height,
proxy_url: video.proxyUrl,
url: video.url,
width: video.width,
};
this.#data.video = video;
return this;
}
toJSON(): DiscordEmbed {
toJSON(): Embed {
return this.#data;
}
}

View File

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