Adds Deletion
This commit is contained in:
parent
a0b668cb90
commit
0d9cf6a370
8 changed files with 174 additions and 35 deletions
|
|
@ -2,7 +2,7 @@ import {
|
|||
AutocompleteInteraction,
|
||||
ChatInputCommandInteraction,
|
||||
CommandInteraction,
|
||||
GuildMember,
|
||||
GuildMember, SlashCommandIntegerOption,
|
||||
SlashCommandStringOption
|
||||
} from "discord.js";
|
||||
import {Container} from "../../Container/Container";
|
||||
|
|
@ -11,32 +11,32 @@ import {GroupModel} from "../../Models/GroupModel";
|
|||
import {UserError} from "../UserError";
|
||||
|
||||
export class GroupSelection {
|
||||
public static createOptionSetup(): SlashCommandStringOption {
|
||||
return new SlashCommandStringOption()
|
||||
public static createOptionSetup(): SlashCommandIntegerOption {
|
||||
return new SlashCommandIntegerOption()
|
||||
.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> {
|
||||
public static async handleAutocomplete(interaction: AutocompleteInteraction, onlyLeaders: boolean = false): Promise<void> {
|
||||
const value = interaction.options.getFocused();
|
||||
const repo = Container.get<GroupRepository>(GroupRepository.name);
|
||||
const groups = repo.findGroupsByMember(<GuildMember>interaction.member);
|
||||
let groups = repo.findGroupsByMember(<GuildMember>interaction.member, onlyLeaders);
|
||||
await interaction.respond(
|
||||
groups
|
||||
.filter((group) => group.name.startsWith(value))
|
||||
.map((group) => ({name: group.name, value: group.name }))
|
||||
.map((group) => ({name: group.name, value: group.id }))
|
||||
)
|
||||
}
|
||||
|
||||
public static getGroup(interaction: CommandInteraction): GroupModel {
|
||||
const groupname = interaction.options.get("group");
|
||||
const groupname = interaction.options.get("group", true);
|
||||
if (!groupname) {
|
||||
throw new UserError("No group name provided");
|
||||
}
|
||||
|
||||
const group = Container.get<GroupRepository>(GroupRepository.name).findGroupByName((groupname.value ?? '').toString());
|
||||
const group = Container.get<GroupRepository>(GroupRepository.name).getById(<number>(groupname.value ?? 0));
|
||||
if (!group) {
|
||||
throw new UserError("No group found");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue