Add support tickets that work with private threads

Members open a ticket from a panel in the ticket channel: one button per
category (a dropdown past five), then a short form. Each ticket is a private
thread named after the category, number and opener, with a first message
that mentions the category's staff role so its members join, and Claim and
Close buttons.

- Claim: staff (the category's role, or Manage Threads / Manage Server)
  take a ticket; the first message shows who has it.
- Close: the opener or staff close it, with an optional reason. The thread
  is locked and archived, and the log channel gets a summary and a .txt
  transcript of the whole thread.
- /ticket add|remove|claim|close inside a ticket; /tickets setup,
  /tickets category add|remove|list and /tickets panel for admins.
- Per-member limit on open tickets (default 1), per-server ticket numbers
  handed out atomically, a deleted thread closes its ticket.
- The dashboard asks the bot to post or refresh the panel through
  ticket_commands (LISTEN/NOTIFY, like music); the listener reconnects if
  the database connection drops.
- Setup warns about missing bot permissions in the ticket and log channels.

The flows live in internal/tickets behind small Discord and store
interfaces, with unit tests on fakes; the repo and the listener have
integration tests (-tags integration, TICKETS_TEST_DB).

Needs the ticket tables (velox-dashboard-api migration 000016_tickets).
.gitignore gains the /tldr benchmark rules so private chat exports and
benchmark results on disk can't be committed from this branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
FernandoJVideiraandClaude Opus 5.5 committed 2026-10-20 19:31:52 +01:00
1 parent b1ea5f17e3
commit d294b3463b
20 files changed
+2800

No files matched your search

+52
View File
@@ -176,3 +176,55 @@ CREATE TABLE IF NOT EXISTS music_commands (
created_at TIMESTAMPTZ DEFAULT NOW(),
processed_at TIMESTAMPTZ
);
-- Tickets (mirror of velox-dashboard-api migration 000016_tickets)
CREATE TABLE IF NOT EXISTS ticket_settings (
guild_id BIGINT PRIMARY KEY,
enabled BOOLEAN NOT NULL DEFAULT TRUE,
channel_id BIGINT,
log_channel_id BIGINT,
panel_message_id BIGINT,
panel_title TEXT NOT NULL DEFAULT 'Need help?',
panel_description TEXT NOT NULL DEFAULT 'Pick a category below to open a private ticket with the staff team.',
max_open_per_user INT NOT NULL DEFAULT 1 CHECK (max_open_per_user BETWEEN 1 AND 10),
next_number INT NOT NULL DEFAULT 1
);
CREATE TABLE IF NOT EXISTS ticket_categories (
id BIGSERIAL PRIMARY KEY,
guild_id BIGINT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) BETWEEN 1 AND 40),
emoji TEXT,
description TEXT NOT NULL DEFAULT '',
staff_role_id BIGINT,
position INT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS tickets (
id BIGSERIAL PRIMARY KEY,
guild_id BIGINT NOT NULL,
number INT NOT NULL,
category_id BIGINT REFERENCES ticket_categories (id) ON DELETE SET NULL,
category_name TEXT NOT NULL,
thread_id BIGINT NOT NULL UNIQUE,
intro_message_id BIGINT,
opener_id BIGINT NOT NULL,
subject TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'closed')),
claimed_by BIGINT,
closed_by BIGINT,
close_reason TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
closed_at TIMESTAMPTZ,
UNIQUE (guild_id, number)
);
CREATE TABLE IF NOT EXISTS ticket_commands (
id BIGSERIAL PRIMARY KEY,
guild_id BIGINT NOT NULL,
command_type TEXT NOT NULL CHECK (command_type IN ('post_panel')),
requested_by BIGINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
processed_at TIMESTAMPTZ
);