Files
reacord/src.new/root-node.ts
2021-12-25 00:52:21 -06:00

35 lines
699 B
TypeScript

import type { CommandInteraction, MessageOptions } from "discord.js"
import type { TextNode } from "./text-node.js"
export class RootNode {
private children = new Set<TextNode>()
constructor(private interaction: CommandInteraction) {}
add(child: TextNode) {
this.children.add(child)
}
clear() {
this.children.clear()
}
remove(child: TextNode) {
this.children.delete(child)
}
render() {
this.interaction.reply(this.getMessageOptions()).catch(console.error)
}
getMessageOptions() {
const options: MessageOptions = {}
for (const child of this.children) {
options.content = (options.content ?? "") + child.text
}
return options
}
}