Skip to content

Commit

Permalink
Merge pull request #290 from Sayrix/289fix
Browse files Browse the repository at this point in the history
Fix: Issues with remove command
  • Loading branch information
zhiyan114 authored Oct 24, 2023
2 parents 288f86f + 6e6a57e commit 2e2959f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
16 changes: 8 additions & 8 deletions src/commands/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <SlashCommandBuilder>new SlashCommandBuilder()
.setName("remove").setDescription("Remove someone from the ticket");
.setName("remove")
.setDescription("Remove someone from the ticket");
constructor(client: ExtendedClient) {
super(client);
}
Expand All @@ -26,20 +27,20 @@ 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<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.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) => {
Expand All @@ -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)); }
}

/*
Expand Down
21 changes: 15 additions & 6 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
});
}
}

Expand Down

0 comments on commit 2e2959f

Please sign in to comment.