Adds initial progress

This commit is contained in:
Michel Fedde 2025-03-28 23:19:54 +01:00
commit a0b668cb90
34 changed files with 2680 additions and 0 deletions

View file

@ -0,0 +1,46 @@
import {
AutocompleteInteraction,
ChatInputCommandInteraction,
CommandInteraction,
GuildMember,
SlashCommandStringOption
} from "discord.js";
import {Container} from "../../Container/Container";
import {GroupRepository} from "../../Repositories/GroupRepository";
import {GroupModel} from "../../Models/GroupModel";
import {UserError} from "../UserError";
export class GroupSelection {
public static createOptionSetup(): SlashCommandStringOption {
return new SlashCommandStringOption()
.setName("group")
.setDescription("Defines the group you want to manage the playdates for")
.setRequired(true)
.setAutocomplete(true)
}
public static async handleAutocomplete(interaction: AutocompleteInteraction): Promise<void> {
const value = interaction.options.getFocused();
const repo = Container.get<GroupRepository>(GroupRepository.name);
const groups = repo.findGroupsByMember(<GuildMember>interaction.member);
await interaction.respond(
groups
.filter((group) => group.name.startsWith(value))
.map((group) => ({name: group.name, value: group.name }))
)
}
public static getGroup(interaction: CommandInteraction): GroupModel {
const groupname = interaction.options.get("group");
if (!groupname) {
throw new UserError("No group name provided");
}
const group = Container.get<GroupRepository>(GroupRepository.name).findGroupByName((groupname.value ?? '').toString());
if (!group) {
throw new UserError("No group found");
}
return <GroupModel>group;
}
}