fix: embed reverse transformer which fixes embeds being in snake case

This commit is contained in:
Yuzu 2022-08-20 02:36:42 -05:00
parent e4ffaa2ff6
commit f62b8c1854
2 changed files with 61 additions and 6 deletions

View File

@ -47,7 +47,7 @@ export interface Embed {
};
}
export function embed(data: Embed): DiscordEmbed {
export function NewEmbed(data: Embed): DiscordEmbed {
return {
title: data.title,
timestamp: data.timestamp,
@ -98,3 +98,57 @@ export function embed(data: Embed): DiscordEmbed {
};
}
export const embed = NewEmbed;
export function NewEmbedR(data: DiscordEmbed): Embed {
return {
title: data.title,
timestamp: data.timestamp,
type: data.type,
url: data.url,
color: data.color,
description: data.description,
author: data.author && {
name: data.author.name,
url: data.author.url,
iconURL: data.author.icon_url,
proxyIconURL: data.author.proxy_icon_url,
},
footer: data.footer && {
text: data.footer.text,
iconURL: data.footer.icon_url,
proxyIconURL: data.footer.proxy_icon_url,
},
fields: data.fields?.map(f => {
return {
name: f.name,
value: f.value,
inline: f.inline,
};
}),
thumbnail: data.thumbnail && {
url: data.thumbnail.url,
proxyURL: data.thumbnail.proxy_url,
width: data.thumbnail.width,
height: data.thumbnail.height,
},
video: {
url: data.video?.url,
proxyURL: data.video?.proxy_url,
width: data.video?.width,
height: data.video?.height,
},
image: data.image && {
url: data.image.url,
proxyURL: data.image.proxy_url,
width: data.image.width,
height: data.image.height,
},
provider: {
url: data.provider?.url,
name: data.provider?.name,
},
};
}
export const embed_ = NewEmbedR;

View File

@ -3,7 +3,6 @@ import type { Model } from './base';
import type { Session } from '../biscuit';
import type {
AllowedMentionsTypes,
DiscordEmbed,
DiscordMessage,
DiscordMessageComponents,
DiscordUser,
@ -15,6 +14,8 @@ import type {
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 { MessageFlags } from '../utils/util';
import { Snowflake } from '../snowflakes';
import { ChannelFactory, ThreadChannel } from './channels';
@ -25,7 +26,7 @@ import { ComponentFactory } from './components';
import { MessageReaction } from './message-reaction';
import { Application, NewTeam } from './application';
import { InteractionFactory } from './interactions';
import type { StickerItem } from './sticker';
import { NewEmbedR } from './embed';
import {
CHANNEL_PIN,
@ -79,7 +80,7 @@ export interface CreateMessageReference {
* Posts a message to a guild text or DM channel. Returns a message object. Fires a Message Create Gateway event.
*/
export interface CreateMessage {
embeds?: DiscordEmbed[];
embeds?: Embed[];
content?: string;
allowedMentions?: AllowedMentions;
files?: FileContent[];
@ -163,7 +164,7 @@ export class Message implements Model {
this.attachments = data.attachments.map(
attachment => new Attachment(session, attachment)
);
this.embeds = data.embeds;
this.embeds = data.embeds.map(NewEmbedR);
if (data.interaction) {
this.interaction = InteractionFactory.fromMessage(
@ -328,7 +329,7 @@ export class Message implements Model {
attachments: Attachment[];
/** any embedded content */
embeds: DiscordEmbed[];
embeds: Embed[];
/** member properties for this message's author */
member?: Member;