Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
3 changes: 2 additions & 1 deletion i18n/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
8 changes: 8 additions & 0 deletions i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
/**
Expand Down Expand Up @@ -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: {
/**
Expand Down
2 changes: 2 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion src/features/commands/add/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ 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 { getOpenTicketByChannel } from "@/features/tickets/records";
import { getInteractionUser } from "@/features/tickets/utils";
import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils";

export default defineCommand({
data: (LL) => ({
Expand Down Expand Up @@ -64,6 +65,17 @@ export default defineCommand({
return;
}

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
});
return;
}

const invitedUserIds = getInvitedUserIds(openTicket.ticket);

if (selectedUser.userId === openTicket.ticket.createdBy) {
Expand Down
14 changes: 13 additions & 1 deletion src/features/commands/mass_add/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ 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 { getOpenTicketByChannel } from "@/features/tickets/records";
import { getInteractionUser } from "@/features/tickets/utils";
import { getInteractionUser, getMemberRoleIds } from "@/features/tickets/utils";

export default defineCommand({
data: (LL) => ({
Expand Down Expand Up @@ -66,6 +67,17 @@ export default defineCommand({
return;
}

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
});
return;
}

const invitedUserIds = getInvitedUserIds(openTicket.ticket);
const nextInvitedUserIds = [...invitedUserIds];
const addedUserIds: string[] = [];
Expand Down
25 changes: 24 additions & 1 deletion src/features/commands/remove/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ 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 { hasTicketStaffAccess } from "@/features/tickets/config-access";
import { getInvitedUserIds, revokeTicketParticipantAccess, updateInvitedUserIds } from "@/features/tickets/participants";
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");

Expand Down Expand Up @@ -55,6 +56,17 @@ export default defineCommand({
return;
}

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
});
return;
}

const invitedUserIds = getInvitedUserIds(openTicket.ticket);

if (invitedUserIds.length === 0) {
Expand Down Expand Up @@ -121,6 +133,17 @@ export async function handleRemoveUsersSelect(context: ComponentExecutionContext
return;
}

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: []
});
return;
}

const invitedUserIds = getInvitedUserIds(openTicket.ticket);
const selectedUserIds = interaction.data.values.filter((userId: string) => invitedUserIds.includes(userId));

Expand Down
Loading