diff --git a/src/commands/add.ts b/src/commands/add.ts index e9082c2c..5ac8f2b4 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -56,10 +56,9 @@ export default class AddCommand extends BaseCommand { ReadMessageHistory: true, AttachFiles: true, ViewChannel: true, - }) - .catch((e) => console.log(e)); + }); - interaction.reply({ content: `> Added <@${added.id}> to the ticket` }).catch((e) => console.log(e)); + await interaction.reply({ content: `> Added <@${added.id}> to the ticket` }).catch((e) => console.log(e)); log( { diff --git a/src/commands/remove.ts b/src/commands/remove.ts index 758b6806..875621ea 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -10,7 +10,8 @@ please check https://creativecommons.org/licenses/by/4.0 for more informations. export default class RemoveCommand extends BaseCommand { public static data: SlashCommandBuilder = new SlashCommandBuilder() - .setName("remove").setDescription("Remove someone from the ticket"); + .setName("remove") + .setDescription("Remove someone from the ticket"); constructor(client: ExtendedClient) { super(client); } @@ -26,12 +27,12 @@ export default class RemoveCommand extends BaseCommand { }); if (!ticket) return interaction.reply({ content: "Ticket not found", ephemeral: true }).catch((e) => console.log(e)); - const invited = JSON.parse(ticket.invited) as string[]; - if (invited.length < 1) return interaction.reply({ content: "There are no users to remove", ephemeral: true }).catch((e) => console.log(e)); + const parseInvited = JSON.parse(ticket.invited) as string[]; + if (parseInvited.length < 1) return interaction.reply({ content: "There are no users to remove", ephemeral: true }).catch((e) => console.log(e)); const addedUsers: User[] = []; - for (let i = 0; i < invited.length; i++) { - addedUsers.push(await this.client.users.fetch(invited[i])); + for (let i = 0; i < parseInvited.length; i++) { + addedUsers.push(await this.client.users.fetch(parseInvited[i])); } const row = new ActionRowBuilder().addComponents( @@ -39,7 +40,7 @@ export default class RemoveCommand extends BaseCommand { .setCustomId("removeUser") .setPlaceholder("Please select a user to remove") .setMinValues(1) - .setMaxValues(ticket.invited.length) + .setMaxValues(parseInvited.length) .addOptions( // @TODO: Fix type definitions when I figure it out via ORM migration. For now assign a random type that gets the error removed. addedUsers.map((user) => { @@ -50,8 +51,7 @@ export default class RemoveCommand extends BaseCommand { }) ) ); - - interaction.reply({ components: [row] }).catch((e) => console.log(e)); } + await interaction.reply({ components: [row] }).catch((e) => console.log(e)); } } /* diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index d599dcd9..ac5c89dd 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -188,16 +188,15 @@ export default class InteractionCreateEvent extends BaseEvent { const ticket = await this.client.prisma.tickets.findUnique({ select: { id: true, + invited: true, }, where: { channelid: interaction.message.channelId } }); - for (const value of interaction.values) { await (interaction.channel as GuildChannel | null)?.permissionOverwrites.delete(value).catch((e) => console.log(e)); - - log( + await log( { LogType: "userRemoved", user: interaction.user, @@ -211,14 +210,24 @@ export default class InteractionCreateEvent extends BaseEvent { ); } - interaction + // Update the data in the database + await this.client.prisma.tickets.update({ + data: { + invited: JSON.stringify((JSON.parse(ticket?.invited ?? "[]") as string[]) + .filter(userid=>interaction.values.find(rUID=>rUID===userid) === undefined)) + }, + where: { + channelid: interaction.channel?.id + } + }); + + await interaction .update({ content: `> Removed ${ interaction.values.length < 1 ? interaction.values : interaction.values.map((a) => `<@${a}>`).join(", ") } from the ticket`, components: [], - }) - .catch((e) => console.log(e)); + }); } }