refactor(configuration): Setup configuration and menu to be reuseable

This commit is contained in:
Michel Fedde 2025-06-23 00:57:02 +02:00
parent 863ae3fab2
commit d46bbd84c5
21 changed files with 551 additions and 452 deletions

View file

@ -18,9 +18,6 @@ import {Container} from "../../Container/Container";
import {GroupSelection} from "../CommandPartials/GroupSelection";
import {UserError} from "../UserError";
import {ArrayUtils} from "../../Utilities/ArrayUtils";
import {GroupConfigurationRenderer} from "../../Configuration/Groups/GroupConfigurationRenderer";
import {GroupConfigurationHandler} from "../../Configuration/Groups/GroupConfigurationHandler";
import {GroupConfigurationTransformers} from "../../Configuration/Groups/GroupConfigurationTransformers";
import {GroupConfigurationRepository} from "../../Database/Repositories/GroupConfigurationRepository";
import {PlaydateRepository} from "../../Database/Repositories/PlaydateRepository";
import {Nullable} from "../../types/Nullable";
@ -28,6 +25,9 @@ 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";
import {MenuHandler} from "../../Configuration/MenuHandler";
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
private static GOODBYE_MESSAGES: string[] = [
@ -238,17 +238,75 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
private async runConfigurator(interaction: ChatInputCommandInteraction) {
const group = GroupSelection.getGroup(interaction);
const menuHandler = new ConfigurationMenuHandler(
new GroupConfigurationHandler(
Container.get<GroupConfigurationRepository>(GroupConfigurationRepository.name),
group
),
new GroupConfigurationTransformers(),
const menuHandler = new MenuHandler(
new ConfigurationHandler(
new GroupConfigurationProvider(
Container.get<GroupConfigurationRepository>(GroupConfigurationRepository.name),
group
)
)
)
const menu = new MenuRenderer(
new MenuTraversal(
menuHandler.getMenuItems(),
menuHandler.fillMenuItems(
[
{
traversalKey: "channels",
label: "Channels",
description: "Provides settings to define in what channels the bot sends messages, when not directly interacting with it.",
type: MenuItemType.Collection,
children: [
{
traversalKey: "newPlaydates",
label: "New Playdates",
description: "Sets the channel, where the group gets notified, when new Playdates are set.",
},
{
traversalKey: "playdateReminders",
label: 'Playdate Reminders',
description: "Sets the channel, where the group gets reminded of upcoming playdates.",
}
]
},
{
traversalKey: "permissions",
label: "Permissions",
description: "Allows customization, how the members are allowed to interact with the data stored in the group.",
type: MenuItemType.Collection,
children: [
{
traversalKey: "allowMemberManagingPlaydates",
label: "Manage Playdates",
description: "Defines if the members are allowed to manage playdates like adding or deleting them.",
}
]
},
{
traversalKey: "calendar",
label: "Calendar",
description: "Provides settings for the metadata contained in the playdate exports.",
type: MenuItemType.Collection,
children: [
{
traversalKey: "title",
label: "Title",
description: "Defines how the calendar entry should be called.",
},
{
traversalKey: "description",
label: "Description",
description: "Sets the description for the calendar entry.",
},
{
traversalKey: "location",
label: "Location",
description: "Sets the location where the calendar should point to."
}
]
},
]
),
'Group Configuration',
"This UI allows you to change settings for your group."
)

View file

@ -7,9 +7,6 @@ import {
ChatInputCommandInteraction,
time,
AttachmentBuilder,
ActivityFlagsBitField,
Options,
User,
GuildMember
} from "discord.js";
import {AutocompleteCommand, ChatInteractionCommand, Command} from "./Command";
@ -21,10 +18,10 @@ import {PlaydateRepository} from "../../Database/Repositories/PlaydateRepository
import {GroupModel} from "../../Database/Models/GroupModel";
import * as ics from 'ics';
import ical from 'node-ical';
import {GroupConfigurationHandler} from "../../Configuration/Groups/GroupConfigurationHandler";
import {GroupConfigurationRepository} from "../../Database/Repositories/GroupConfigurationRepository";
import {privateDecrypt} from "node:crypto";
import {GroupRepository} from "../../Database/Repositories/GroupRepository";
import {GroupConfigurationProvider} from "../../Configuration/Groups/GroupConfigurationProvider";
import { ConfigurationHandler } from "../../Configuration/ConfigurationHandler";
export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInteractionCommand {
definition(): SlashCommandBuilder {
@ -314,10 +311,12 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
}
private async export(interaction: ChatInputCommandInteraction, group: GroupModel): Promise<void> {
const groupConfig = new GroupConfigurationHandler(
Container.get<GroupConfigurationRepository>(GroupConfigurationRepository.name),
group
).getConfiguration();
const groupConfig = new ConfigurationHandler(
new GroupConfigurationProvider(
Container.get<GroupConfigurationRepository>(GroupConfigurationRepository.name),
group
)
).getCompleteConfiguration();
const playdates = this.getExportTargets(interaction, group);
@ -396,10 +395,12 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
return false;
}
const config = new GroupConfigurationHandler(
Container.get<GroupConfigurationRepository>(GroupConfigurationRepository.name),
group
const config = new ConfigurationHandler(
new GroupConfigurationProvider(
Container.get<GroupConfigurationRepository>(GroupConfigurationRepository.name),
group
)
);
return config.getConfiguration().permissions.allowMemberManagingPlaydates;
return config.getConfigurationByPath("permissions.allowMemberManagingPlaydates") === true;
}
}