feat(polish): Adds EmbedLibrary

This commit is contained in:
Michel Fedde 2025-06-24 21:59:55 +02:00
parent cf9c88a2d6
commit b3d0b3a90c
12 changed files with 240 additions and 136 deletions

View file

@ -0,0 +1,64 @@
import {ColorResolvable, Colors, EmbedBuilder} from "discord.js";
import {ArrayUtils} from "../Utilities/ArrayUtils";
import {GroupModel} from "../Database/Models/GroupModel";
export enum EmbedType {
Unknown,
Success,
Info,
Error,
}
export class EmbedLibrary {
private static TYPE_COLOR_MAP: Record<EmbedType, ColorResolvable> = {
[EmbedType.Unknown]: Colors.Yellow,
[EmbedType.Success]: Colors.Green,
[EmbedType.Info]: Colors.Blue,
[EmbedType.Error]: Colors.Red,
}
public static base(
title: string,
description: string|null = null,
type: EmbedType = EmbedType.Unknown
): EmbedBuilder {
const embed = new EmbedBuilder()
.setTitle(title)
.setColor(this.TYPE_COLOR_MAP[type])
if (description) {
embed.setDescription(description);
}
return embed
}
public static playdate(
group: GroupModel,
title: string,
description: string|null = null,
type: EmbedType = EmbedType.Unknown
): EmbedBuilder {
return this.base(title, description, type)
.setFooter({
text: `Group: ${group.name}`
})
}
public static error(
error: Error
): EmbedBuilder {
if ("getEmbed" in error) {
return (<(error: Error) => EmbedBuilder>error.getEmbed)(error);
}
return this.base(
"A unexpected error occurred",
":x: There was an error while executing this command!",
EmbedType.Error
).setFooter({
text: "Type: Generic"
})
}
}