64 lines
No EOL
1.5 KiB
TypeScript
64 lines
No EOL
1.5 KiB
TypeScript
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"
|
|
})
|
|
}
|
|
} |