From 86c53697ac01dca5e6242ea20571faea89d4d0d4 Mon Sep 17 00:00:00 2001 From: Peter Wilfahrt Date: Tue, 17 Nov 2026 21:37:08 +0000 Subject: [PATCH 1/3] Require ticket staff access for add, mass_add and remove commands --- i18n/en/index.ts | 3 ++- i18n/fr/index.ts | 3 ++- i18n/i18n-types.ts | 8 ++++++++ src/features/commands/add/command.ts | 11 ++++++++++- src/features/commands/mass_add/command.ts | 11 ++++++++++- src/features/commands/remove/command.ts | 19 ++++++++++++++++++- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/i18n/en/index.ts b/i18n/en/index.ts index 5d8f47a3..5dfd112f 100644 --- a/i18n/en/index.ts +++ b/i18n/en/index.ts @@ -119,7 +119,8 @@ const en: BaseTranslation = { records: { not_ticket_channel: "This interaction was not used in a ticket channel.", not_open_ticket: "This channel is not an open ticket.", - already_closed: "This ticket is already closed." + already_closed: "This ticket is already closed.", + only_staff_manage: "Only staff can manage this ticket's participants." }, panel: { no_visible_types: "You do not have access to any ticket types on this panel.", diff --git a/i18n/fr/index.ts b/i18n/fr/index.ts index f1f4ad51..132db220 100644 --- a/i18n/fr/index.ts +++ b/i18n/fr/index.ts @@ -118,7 +118,8 @@ const fr: Translation = { records: { not_ticket_channel: "Cette interaction n'a pas été utilisée dans un salon de ticket.", not_open_ticket: "Ce salon n'est pas un ticket ouvert.", - already_closed: "Ce ticket est déjà fermé." + already_closed: "Ce ticket est déjà fermé.", + only_staff_manage: "Seul le personnel peut gérer les participants de ce ticket." }, panel: { no_visible_types: "Vous n'avez accès à aucun type de ticket sur ce panneau.", diff --git a/i18n/i18n-types.ts b/i18n/i18n-types.ts index 4d62a6af..fe70238f 100644 --- a/i18n/i18n-types.ts +++ b/i18n/i18n-types.ts @@ -349,6 +349,10 @@ type RootTranslation = { * T​h​i​s​ ​t​i​c​k​e​t​ ​i​s​ ​a​l​r​e​a​d​y​ ​c​l​o​s​e​d​. */ already_closed: string; + /** + * Only staff can manage this ticket's participants. + */ + only_staff_manage: string; }; panel: { /** @@ -1413,6 +1417,10 @@ export type TranslationFunctions = { * This ticket is already closed. */ already_closed: () => LocalizedString; + /** + * Only staff can manage this ticket's participants. + */ + only_staff_manage: () => LocalizedString; }; panel: { /** diff --git a/src/features/commands/add/command.ts b/src/features/commands/add/command.ts index a2e3a0a6..9c7944d4 100644 --- a/src/features/commands/add/command.ts +++ b/src/features/commands/add/command.ts @@ -26,8 +26,9 @@ import { MAX_INVITED_TICKET_USERS, updateInvitedUserIds } from "@/features/tickets/participants"; +import { hasTicketStaffAccess } from "@/features/tickets/config-access"; import { getOpenTicketByChannel } from "@/features/tickets/records"; -import { getInteractionUser } from "@/features/tickets/utils"; +import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils"; export default defineCommand({ data: (LL) => ({ @@ -64,6 +65,14 @@ export default defineCommand({ return; } + if (!hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction))) { + await reply(app, interaction, { + content: LL.tickets.records.only_staff_manage(), + flags: MessageFlags.Ephemeral + }); + return; + } + const invitedUserIds = getInvitedUserIds(openTicket.ticket); if (selectedUser.userId === openTicket.ticket.createdBy) { diff --git a/src/features/commands/mass_add/command.ts b/src/features/commands/mass_add/command.ts index a48a25c3..773584ef 100644 --- a/src/features/commands/mass_add/command.ts +++ b/src/features/commands/mass_add/command.ts @@ -27,8 +27,9 @@ import { MAX_INVITED_TICKET_USERS, updateInvitedUserIds } from "@/features/tickets/participants"; +import { hasTicketStaffAccess } from "@/features/tickets/config-access"; import { getOpenTicketByChannel } from "@/features/tickets/records"; -import { getInteractionUser } from "@/features/tickets/utils"; +import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils"; export default defineCommand({ data: (LL) => ({ @@ -66,6 +67,14 @@ export default defineCommand({ return; } + if (!hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction))) { + await reply(app, interaction, { + content: LL.tickets.records.only_staff_manage(), + flags: MessageFlags.Ephemeral + }); + return; + } + const invitedUserIds = getInvitedUserIds(openTicket.ticket); const nextInvitedUserIds = [...invitedUserIds]; const addedUserIds: string[] = []; diff --git a/src/features/commands/remove/command.ts b/src/features/commands/remove/command.ts index 40fcff8d..dc1e2586 100644 --- a/src/features/commands/remove/command.ts +++ b/src/features/commands/remove/command.ts @@ -25,8 +25,9 @@ import { getUserOption } from "@/features/commands/shared/options"; import { sendTicketLog } from "@/features/logs/service"; import { createTicketLogContext } from "@/features/logs/utils"; import { getInvitedUserIds, revokeTicketParticipantAccess, updateInvitedUserIds } from "@/features/tickets/participants"; +import { hasTicketStaffAccess } from "@/features/tickets/config-access"; import { getOpenTicketByChannel } from "@/features/tickets/records"; -import { getInteractionUser } from "@/features/tickets/utils"; +import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils"; const REMOVE_USERS_CUSTOM_ID = createCustomId("tickets", "remove-users"); @@ -55,6 +56,14 @@ export default defineCommand({ return; } + if (!hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction))) { + await reply(app, interaction, { + content: LL.tickets.records.only_staff_manage(), + flags: MessageFlags.Ephemeral + }); + return; + } + const invitedUserIds = getInvitedUserIds(openTicket.ticket); if (invitedUserIds.length === 0) { @@ -121,6 +130,14 @@ export async function handleRemoveUsersSelect(context: ComponentExecutionContext return; } + if (!hasTicketStaffAccess(context.app, openTicket.ticketType, getMemberRoleIds(interaction))) { + await updateMessage(context.app, interaction, { + content: context.app.LL.tickets.records.only_staff_manage(), + components: [] + }); + return; + } + const invitedUserIds = getInvitedUserIds(openTicket.ticket); const selectedUserIds = interaction.data.values.filter((userId: string) => invitedUserIds.includes(userId)); From 019eab0e6a4a59a07570d049d45ef5b59f40643c Mon Sep 17 00:00:00 2001 From: Sayrix <43046854+Sayrix@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:46:50 +0100 Subject: [PATCH 2/3] fix(commands): sort participant command imports --- src/features/commands/add/command.ts | 2 +- src/features/commands/mass_add/command.ts | 2 +- src/features/commands/remove/command.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/features/commands/add/command.ts b/src/features/commands/add/command.ts index 9c7944d4..4580e87d 100644 --- a/src/features/commands/add/command.ts +++ b/src/features/commands/add/command.ts @@ -20,13 +20,13 @@ import { reply } from "@/core/respond"; import { getUserOption } from "@/features/commands/shared/options"; import { sendTicketLog } from "@/features/logs/service"; import { createTicketLogContext } from "@/features/logs/utils"; +import { hasTicketStaffAccess } from "@/features/tickets/config-access"; import { getInvitedUserIds, grantTicketParticipantAccess, MAX_INVITED_TICKET_USERS, updateInvitedUserIds } from "@/features/tickets/participants"; -import { hasTicketStaffAccess } from "@/features/tickets/config-access"; import { getOpenTicketByChannel } from "@/features/tickets/records"; import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils"; diff --git a/src/features/commands/mass_add/command.ts b/src/features/commands/mass_add/command.ts index 773584ef..b891e0e8 100644 --- a/src/features/commands/mass_add/command.ts +++ b/src/features/commands/mass_add/command.ts @@ -21,13 +21,13 @@ import type { BotApp } from "@/core/types"; import { getStringOption } from "@/features/commands/shared/options"; import { sendTicketLog } from "@/features/logs/service"; import { createTicketLogContext } from "@/features/logs/utils"; +import { hasTicketStaffAccess } from "@/features/tickets/config-access"; import { getInvitedUserIds, grantTicketParticipantAccess, MAX_INVITED_TICKET_USERS, updateInvitedUserIds } from "@/features/tickets/participants"; -import { hasTicketStaffAccess } from "@/features/tickets/config-access"; import { getOpenTicketByChannel } from "@/features/tickets/records"; import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils"; diff --git a/src/features/commands/remove/command.ts b/src/features/commands/remove/command.ts index dc1e2586..77fa51bd 100644 --- a/src/features/commands/remove/command.ts +++ b/src/features/commands/remove/command.ts @@ -24,8 +24,8 @@ import type { TicketRecord } from "@/db/schema"; import { getUserOption } from "@/features/commands/shared/options"; import { sendTicketLog } from "@/features/logs/service"; import { createTicketLogContext } from "@/features/logs/utils"; -import { getInvitedUserIds, revokeTicketParticipantAccess, updateInvitedUserIds } from "@/features/tickets/participants"; import { hasTicketStaffAccess } from "@/features/tickets/config-access"; +import { getInvitedUserIds, revokeTicketParticipantAccess, updateInvitedUserIds } from "@/features/tickets/participants"; import { getOpenTicketByChannel } from "@/features/tickets/records"; import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils"; From 0a4ebcf2ea90bbee1c03c2bf16611b747e25552f Mon Sep 17 00:00:00 2001 From: Sayrix <43046854+Sayrix@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:47:56 +0100 Subject: [PATCH 3/3] feat(tickets): make participant staff restriction configurable --- config/config.example.ts | 3 +++ src/config/index.ts | 2 ++ src/features/commands/add/command.ts | 5 ++++- src/features/commands/mass_add/command.ts | 5 ++++- src/features/commands/remove/command.ts | 10 ++++++++-- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/config/config.example.ts b/config/config.example.ts index bf6042b5..6c8b3d93 100644 --- a/config/config.example.ts +++ b/config/config.example.ts @@ -70,6 +70,9 @@ export default defineConfig("0.0.1", { maxOpenPerUser: 1, // Global staff roles that can see and manage tickets. staffRoleIds: ["111111111111111111"], + // Only staff can use /add, /mass_add and /remove. Defaults to true when omitted. + // Set to false to let anyone with access to the ticket manage its participants. + participantsStaffOnly: true, // Roles that are blocked from opening any ticket type by default. blockedRoleIds: ["222222222222222222"], // Roles mentioned in the welcome message when a ticket is opened. diff --git a/src/config/index.ts b/src/config/index.ts index 9444beb2..9a3d45eb 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -54,6 +54,8 @@ interface ConfigV0_0_1 { channelNameTemplate: string; maxOpenPerUser: number; staffRoleIds: string[]; + /** Restrict /add, /mass_add and /remove to staff. Defaults to true when omitted. */ + participantsStaffOnly?: boolean; blockedRoleIds: string[]; mentionRoleIds: string[]; defaultWelcomeMessage?: string; diff --git a/src/features/commands/add/command.ts b/src/features/commands/add/command.ts index 4580e87d..cb51f12e 100644 --- a/src/features/commands/add/command.ts +++ b/src/features/commands/add/command.ts @@ -65,7 +65,10 @@ export default defineCommand({ return; } - if (!hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction))) { + if ( + (app.config.tickets.participantsStaffOnly ?? true) && + !hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction)) + ) { await reply(app, interaction, { content: LL.tickets.records.only_staff_manage(), flags: MessageFlags.Ephemeral diff --git a/src/features/commands/mass_add/command.ts b/src/features/commands/mass_add/command.ts index b891e0e8..580c1ec6 100644 --- a/src/features/commands/mass_add/command.ts +++ b/src/features/commands/mass_add/command.ts @@ -67,7 +67,10 @@ export default defineCommand({ return; } - if (!hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction))) { + if ( + (app.config.tickets.participantsStaffOnly ?? true) && + !hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction)) + ) { await reply(app, interaction, { content: LL.tickets.records.only_staff_manage(), flags: MessageFlags.Ephemeral diff --git a/src/features/commands/remove/command.ts b/src/features/commands/remove/command.ts index 77fa51bd..95fd7ff2 100644 --- a/src/features/commands/remove/command.ts +++ b/src/features/commands/remove/command.ts @@ -56,7 +56,10 @@ export default defineCommand({ return; } - if (!hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction))) { + if ( + (app.config.tickets.participantsStaffOnly ?? true) && + !hasTicketStaffAccess(app, openTicket.ticketType, getMemberRoleIds(interaction)) + ) { await reply(app, interaction, { content: LL.tickets.records.only_staff_manage(), flags: MessageFlags.Ephemeral @@ -130,7 +133,10 @@ export async function handleRemoveUsersSelect(context: ComponentExecutionContext return; } - if (!hasTicketStaffAccess(context.app, openTicket.ticketType, getMemberRoleIds(interaction))) { + if ( + (context.app.config.tickets.participantsStaffOnly ?? true) && + !hasTicketStaffAccess(context.app, openTicket.ticketType, getMemberRoleIds(interaction)) + ) { await updateMessage(context.app, interaction, { content: context.app.LL.tickets.records.only_staff_manage(), components: []