Adds Deletion
This commit is contained in:
parent
a0b668cb90
commit
0d9cf6a370
8 changed files with 174 additions and 35 deletions
|
|
@ -3,15 +3,25 @@ import {
|
|||
Interaction,
|
||||
CommandInteraction,
|
||||
ChatInputCommandInteraction,
|
||||
MessageFlags, GuildMemberRoleManager, InteractionReplyOptions, GuildMember
|
||||
MessageFlags, GuildMemberRoleManager, InteractionReplyOptions, GuildMember, EmbedBuilder, AutocompleteInteraction
|
||||
} from "discord.js";
|
||||
import {ChatInteractionCommand, Command} from "./Command";
|
||||
import {AutocompleteCommand, ChatInteractionCommand, Command} from "./Command";
|
||||
import {GroupModel} from "../../Models/GroupModel";
|
||||
import {GroupRepository} from "../../Repositories/GroupRepository";
|
||||
import {DatabaseConnection} from "../../Database/DatabaseConnection";
|
||||
import {Container} from "../../Container/Container";
|
||||
import {GroupSelection} from "../CommandPartials/GroupSelection";
|
||||
import {UserError} from "../UserError";
|
||||
import {ArrayUtils} from "../../Utilities/ArrayUtils";
|
||||
|
||||
export class GroupCommand implements Command, ChatInteractionCommand {
|
||||
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
|
||||
private static GOODBYE_MESSAGES: string[] = [
|
||||
'Sad to see you go.',
|
||||
'May your next adventure be fruitful.',
|
||||
'I hope, I served you well.',
|
||||
'I wish you, good luck on your next adventures.',
|
||||
]
|
||||
|
||||
definition(): SlashCommandBuilder {
|
||||
// @ts-ignore
|
||||
return new SlashCommandBuilder()
|
||||
|
|
@ -35,8 +45,17 @@ export class GroupCommand implements Command, ChatInteractionCommand {
|
|||
listCommand
|
||||
.setName("list")
|
||||
.setDescription("Displays the groups you are apart of.")
|
||||
)
|
||||
.addSubcommand(command => command
|
||||
.setName('config')
|
||||
.setDescription("Starts the config manager for the group.")
|
||||
.addIntegerOption(GroupSelection.createOptionSetup())
|
||||
)
|
||||
.addSubcommand(command => command
|
||||
.setName("remove")
|
||||
.setDescription("Deletes a group you are the leader for.")
|
||||
.addIntegerOption(GroupSelection.createOptionSetup())
|
||||
);
|
||||
|
||||
}
|
||||
execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||
switch (interaction.options.getSubcommand()) {
|
||||
|
|
@ -46,6 +65,11 @@ export class GroupCommand implements Command, ChatInteractionCommand {
|
|||
case "list":
|
||||
this.list(interaction);
|
||||
break;
|
||||
case "remove":
|
||||
this.remove(interaction);
|
||||
break;
|
||||
case "config":
|
||||
this.runConfigurator(interaction);
|
||||
default:
|
||||
throw new Error("Unsupported command");
|
||||
}
|
||||
|
|
@ -79,22 +103,65 @@ export class GroupCommand implements Command, ChatInteractionCommand {
|
|||
const repo = Container.get<GroupRepository>(GroupRepository.name);
|
||||
const groups = repo.findGroupsByMember(<GuildMember>interaction.member);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Your groups on this server:")
|
||||
.setFields(
|
||||
groups.map(group => {
|
||||
return {
|
||||
name: group.name,
|
||||
value: `
|
||||
Role: <@&${group.role.roleid}>
|
||||
`
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
const reply: InteractionReplyOptions = {
|
||||
embeds: [
|
||||
{
|
||||
title: "Your groups on this server:",
|
||||
|
||||
fields: groups.map((group) => {
|
||||
return {
|
||||
name: group.name,
|
||||
value: ""
|
||||
}
|
||||
})
|
||||
}
|
||||
embed
|
||||
],
|
||||
allowedMentions: { roles: [] },
|
||||
flags: MessageFlags.Ephemeral
|
||||
}
|
||||
|
||||
interaction.reply(reply);
|
||||
}
|
||||
|
||||
private async remove(interaction: ChatInputCommandInteraction) {
|
||||
const group = GroupSelection.getGroup(interaction);
|
||||
|
||||
const repo = Container.get<GroupRepository>(GroupRepository.name);
|
||||
if (group.leader.memberid != interaction.member?.user.id) {
|
||||
throw new UserError("Can't remove group. You are not the leader.");
|
||||
}
|
||||
|
||||
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
|
||||
],
|
||||
flags: MessageFlags.Ephemeral,
|
||||
})
|
||||
}
|
||||
|
||||
async handleAutocomplete(interaction: AutocompleteInteraction): Promise<void> {
|
||||
const option = interaction.options.getFocused(true);
|
||||
if (option.name == "group") {
|
||||
await GroupSelection.handleAutocomplete(interaction, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private runConfigurator(interaction: ChatInputCommandInteraction) {
|
||||
const group = GroupSelection.getGroup(interaction);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
.addSubcommand((subcommand) => subcommand
|
||||
.setName("create")
|
||||
.setDescription("Creates a new playdate")
|
||||
.addStringOption(GroupSelection.createOptionSetup())
|
||||
.addIntegerOption(GroupSelection.createOptionSetup())
|
||||
.addStringOption((option) => option
|
||||
.setName("from")
|
||||
.setDescription("Defines the start date & time. Format: YYYY-MM-DD HH:mm")
|
||||
|
|
@ -48,12 +48,12 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
.addSubcommand((subcommand) => subcommand
|
||||
.setName("list")
|
||||
.setDescription("Lists all playdates")
|
||||
.addStringOption(GroupSelection.createOptionSetup())
|
||||
.addIntegerOption(GroupSelection.createOptionSetup())
|
||||
)
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
.setName("remove")
|
||||
.setDescription("Removes a playdate")
|
||||
.addStringOption(GroupSelection.createOptionSetup())
|
||||
.addIntegerOption(GroupSelection.createOptionSetup())
|
||||
.addIntegerOption((option) => option
|
||||
.setName("playdate")
|
||||
.setDescription("Selects a playdate")
|
||||
|
|
@ -179,8 +179,6 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
throw new UserError("No playdate found");
|
||||
}
|
||||
|
||||
console.log(selected, group);
|
||||
|
||||
if (selected.group?.id != group.id) {
|
||||
throw new UserError("No playdate found");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue