finish embed components

This commit is contained in:
MapleLeaf
2021-12-26 14:11:17 -06:00
parent fefb57fcc3
commit 97581cfabd
13 changed files with 514 additions and 51 deletions

View File

@@ -1,30 +1,18 @@
import React from "react"
import type { CamelCasedPropertiesDeep } from "type-fest"
import { snakeCaseDeep } from "../../helpers/convert-object-property-case"
import { omit } from "../../helpers/omit"
import { ReacordElement } from "../element.js"
import type { MessageOptions } from "../message"
import { Node } from "../node.js"
import { EmbedChildNode } from "./embed-child.js"
import type { EmbedOptions } from "./embed-options"
export type EmbedProps = {
description?: string
url?: string
timestamp?: string
color?: number
footer?: {
text: string
iconURL?: string
}
image?: {
url: string
}
thumbnail?: {
url: string
}
author?: {
name: string
url?: string
iconURL?: string
}
export type EmbedProps = Omit<
CamelCasedPropertiesDeep<EmbedOptions>,
"timestamp"
> & {
timestamp?: string | number | Date
children?: React.ReactNode
}
@@ -38,14 +26,19 @@ export function Embed(props: EmbedProps) {
class EmbedNode extends Node<EmbedProps> {
override modifyMessageOptions(options: MessageOptions): void {
const embed = omit(this.props, ["children"])
const embed: EmbedOptions = {
...snakeCaseDeep(omit(this.props, ["children", "timestamp"])),
timestamp: this.props.timestamp
? new Date(this.props.timestamp).toISOString()
: undefined,
}
for (const child of this.children) {
if (child instanceof EmbedChildNode) {
child.modifyEmbedOptions(embed)
}
}
options.embeds ??= []
options.embeds.push(embed)
}
}