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

@ -5,9 +5,11 @@ import {
GuildMember,
GuildMemberRoleManager,
InteractionReplyOptions,
MessageFlags, PermissionFlagsBits,
MessageFlags,
PermissionFlagsBits,
roleMention,
SlashCommandBuilder, Snowflake,
SlashCommandBuilder,
Snowflake,
time,
userMention
} from "discord.js";
@ -23,7 +25,6 @@ import {PlaydateRepository} from "../../Database/Repositories/PlaydateRepository
import {Nullable} from "../../types/Nullable";
import {MenuRenderer} from "../../Menu/MenuRenderer";
import {MenuItemType} from "../../Menu/MenuRenderer.types";
import {ConfigurationMenuHandler} from "../../Configuration/Groups/ConfigurationMenuHandler";
import {MenuTraversal} from "../../Menu/MenuTraversal";
import {ConfigurationHandler} from "../../Configuration/ConfigurationHandler";
import {GroupConfigurationProvider} from "../../Configuration/Groups/GroupConfigurationProvider";
@ -31,6 +32,7 @@ import {MenuHandler} from "../../Configuration/MenuHandler";
import {ServerConfigurationProvider} from "../../Configuration/Server/ServerConfigurationProvider";
import {ServerConfigurationRepository} from "../../Database/Repositories/ServerConfigurationRepository";
import {PermissionError} from "../PermissionError";
import {EmbedLibrary, EmbedType} from "../EmbedLibrary";
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
private static GOODBYE_MESSAGES: string[] = [
@ -155,7 +157,16 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
Container.get<GroupRepository>(GroupRepository.name).create(group);
interaction.reply({content: `:white_check_mark: Created group \`${name}\``, flags: MessageFlags.Ephemeral})
interaction.reply({
embeds: [
EmbedLibrary.base(
'Created group',
`:white_check_mark: Created group \`${name}\``,
EmbedType.Success
)
],
flags: MessageFlags.Ephemeral
})
}
private allowedCreate(interaction: ChatInputCommandInteraction): boolean {
@ -192,8 +203,7 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
const playdateRepo = Container.get<PlaydateRepository>(PlaydateRepository.name);
const embed = new EmbedBuilder()
.setTitle("Your groups on this server:")
const embed = EmbedLibrary.base("Your groups on this server:", '', EmbedType.Info)
.setFields(
groups.map(group => {
const nextPlaydate = playdateRepo.getNextPlaydateForGroup(group);
@ -236,16 +246,14 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
}
repo.deleteGroup(group);
const embed = new EmbedBuilder()
.setTitle("Group deleted.")
.setDescription(
`:x: Deleted \`${group.name}\`. ${ArrayUtils.chooseRandom(GroupCommand.GOODBYE_MESSAGES)}`
)
await interaction.reply({
embeds: [
embed
EmbedLibrary.base(
"Group deleted",
`:x: Deleted \`${group.name}\`. ${ArrayUtils.chooseRandom(GroupCommand.GOODBYE_MESSAGES)}`,
EmbedType.Success
)
],
flags: MessageFlags.Ephemeral,
})
@ -332,7 +340,9 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
),
'Group Configuration',
"This UI allows you to change settings for your group."
)
),
null,null,
group.name
)
menu.display(interaction);
@ -358,17 +368,14 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
group.leader.memberid = newLeader.id
repo.update(group);
const embed = new EmbedBuilder()
.setTitle("Leadership transferred")
.setDescription(
`Leadership was successfully transferred to ${userMention(newLeader.user.id)}`
)
await interaction.reply({
embeds: [
embed
EmbedLibrary.base(
'Leadership transferred',
`Leadership was successfully transferred to ${userMention(newLeader.user.id)}`,
EmbedType.Success
)
],
flags: MessageFlags.Ephemeral,
})