feat(polish): Adds EmbedLibrary
This commit is contained in:
parent
cf9c88a2d6
commit
b3d0b3a90c
12 changed files with 240 additions and 136 deletions
|
|
@ -18,12 +18,12 @@ import {ComponentInteractionEvent} from "../Events/EventClasses/ComponentInterac
|
|||
import {MenuTraversal} from "./MenuTraversal";
|
||||
import {Prompt} from "./Modals/Prompt";
|
||||
import _ from "lodash";
|
||||
import {EmbedLibrary} from "../Discord/EmbedLibrary";
|
||||
|
||||
export class MenuRenderer {
|
||||
private readonly menuId: string;
|
||||
private eventId: Nullable<string>;
|
||||
|
||||
private exitButton: ButtonBuilder;
|
||||
private backButton: ButtonBuilder;
|
||||
private static MAX_BUTTON_PER_ROW = 5;
|
||||
private static MAX_ROWS = 5;
|
||||
|
|
@ -33,18 +33,13 @@ export class MenuRenderer {
|
|||
constructor(
|
||||
private readonly traversal: MenuTraversal,
|
||||
private readonly eventHandler: EventHandler|null = null,
|
||||
private readonly iconCache: Nullable<IconCache> = null
|
||||
private readonly iconCache: Nullable<IconCache> = null,
|
||||
private readonly rootName: string = '',
|
||||
) {
|
||||
this.eventHandler ??= Container.get<EventHandler>(EventHandler.name);
|
||||
this.iconCache ??= Container.get<IconCache>(IconCache.name);
|
||||
this.menuId = randomUUID();
|
||||
|
||||
this.exitButton = new ButtonBuilder()
|
||||
.setLabel("Exit")
|
||||
.setStyle(ButtonStyle.Danger)
|
||||
.setCustomId(this.getInteractionId("EXIT"))
|
||||
.setEmoji(this.iconCache?.get("door_open_solid_white") ?? '');
|
||||
|
||||
this.backButton = new ButtonBuilder()
|
||||
.setLabel("Back")
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
|
|
@ -119,11 +114,11 @@ export class MenuRenderer {
|
|||
}
|
||||
|
||||
private getEmbed(): EmbedBuilder {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(this.traversal.currentMenuItem.label)
|
||||
.setDescription(this.traversal.currentMenuItem.description ?? '')
|
||||
.setAuthor({
|
||||
name: "/ " + this.traversal.path.join(' / ')
|
||||
const embed = EmbedLibrary.base(
|
||||
this.traversal.currentMenuItem.label,
|
||||
this.traversal.currentMenuItem.description ?? '',
|
||||
).setFooter({
|
||||
text: this.rootName + " / " + this.traversal.getTraversedLabels().join(' / ')
|
||||
});
|
||||
|
||||
if (this.traversal.currentMenuItem.type === MenuItemType.Field) {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,16 @@ export class MenuTraversal {
|
|||
return <AnyMenuItem>this.traversalMap.get(path);
|
||||
}
|
||||
|
||||
public getTraversedLabels(): string[] {
|
||||
const labels = [];
|
||||
for (let i = 0; i < this.currentPath.length; i++) {
|
||||
const path = this.currentPath.slice(0, i + 1);
|
||||
labels.push(this.getMenuItem(this.stringifyTraversalPath(path)).label);
|
||||
}
|
||||
|
||||
return labels;
|
||||
}
|
||||
|
||||
public static unstringifyTraversalPath(path: StringifiedTraversalPath): TraversalPath {
|
||||
return path.split('/');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue