message payload tweaks

This commit is contained in:
itsMapleLeaf
2022-08-05 11:44:46 -05:00
parent 3bd0b33750
commit 9c60c24dca

View File

@@ -30,7 +30,7 @@ import {
import { SelectNode } from "./react/select" import { SelectNode } from "./react/select"
export type MessageUpdatePayload = { export type MessageUpdatePayload = {
content: string content: string | null
embeds: APIEmbed[] embeds: APIEmbed[]
components: Array< components: Array<
APIActionRowComponent<APIButtonComponent | APISelectMenuComponent> APIActionRowComponent<APIButtonComponent | APISelectMenuComponent>
@@ -39,7 +39,8 @@ export type MessageUpdatePayload = {
export function makeMessageUpdatePayload(root: Node): MessageUpdatePayload { export function makeMessageUpdatePayload(root: Node): MessageUpdatePayload {
return { return {
content: root.extractText(), // eslint-disable-next-line unicorn/no-null
content: root.extractText() || null,
embeds: makeEmbeds(root), embeds: makeEmbeds(root),
components: makeActionRows(root), components: makeActionRows(root),
} }
@@ -167,7 +168,7 @@ function makeActionRows(root: Node) {
type: ComponentType.Button, type: ComponentType.Button,
custom_id: node.customId, custom_id: node.customId,
label: node.extractText(Number.POSITIVE_INFINITY), label: node.extractText(Number.POSITIVE_INFINITY),
emoji: { name: node.props.emoji }, emoji: node.props.emoji ? { name: node.props.emoji } : undefined,
style: translateButtonStyle(node.props.style ?? "secondary"), style: translateButtonStyle(node.props.style ?? "secondary"),
disabled: node.props.disabled, disabled: node.props.disabled,
}) })
@@ -201,7 +202,9 @@ function makeActionRows(root: Node) {
const options = [...node.children] const options = [...node.children]
.flatMap((child) => (child instanceof OptionNode ? child : [])) .flatMap((child) => (child instanceof OptionNode ? child : []))
.map<APISelectMenuOption>((child) => ({ .map<APISelectMenuOption>((child) => ({
label: child.findInstanceOf(OptionLabelNode)?.extractText() ?? "", label:
child.findInstanceOf(OptionLabelNode)?.extractText() ||
child.props.value,
description: child description: child
.findInstanceOf(OptionDescriptionNode) .findInstanceOf(OptionDescriptionNode)
?.extractText(), ?.extractText(),