Skip to content
Draft
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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,33 @@ If some common data setup is required for the API endpoint (e.g. `/api/events` r
to the repository, the contributors are additionally granting VATPRC staffs an
unrevokeable right to use the code freely for any purposes related to VATSIM or
VATPRC.

### Discord event posts

Set `discord.event_forum_channel_id` to a Discord forum channel ID, in addition
to enabling the bot and configuring its token. If the forum requires tags, set
`discord.event_forum_tag_ids` to the permitted tag IDs. The bot needs View Channel,
Send Messages, Embed Links, Read Message History, and Send Messages in Threads
permissions there. Locked posts additionally require Manage Threads to reopen.

Event coordinators can publish a saved website event from its edit dialog. The
service stores the forum thread and guild IDs and returns `discord_message` in the
event API. `PUT /api/events/{id}/discord` creates the post once, or synchronizes
its existing title and starter message. Event updates automatically synchronize
linked posts. A failed sync preserves the website changes and exposes
`discord_message.status = OutOfSync`; the editor offers a retry. Unpublished events are never
automatically published. Long descriptions are shortened to Discord's embed
limit, with a link to the full website event. Mentions are disabled.

Run database migrations before deploying this version. Discord associations live
in `event_discord_message`, keyed by `event_id`. Its `status` column is a text enum
restricted to `Sync` and `OutOfSync`; `synced_at` records the last successful sync.
Failed updates retain that timestamp. First publication failures create no
association and return an API error.

Discord requests run after website changes are committed, without holding a
transaction or row lock. Concurrent first publications can create duplicate posts;
there is no cross-system atomicity. Local tests use a mock Discord HTTP server.

The API exposes `discord_message` with string `guild_id` and `message_id`
snowflakes, `status`, and `synced_at`.
3 changes: 3 additions & 0 deletions assets/config/settings.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ endpoint = "http://localhost:4318/v1/traces"
headers = {}

[discord]
# Target Discord forum channel for website event posts (optional).
# event_forum_channel_id = 123456789012345678
# event_forum_tag_ids = [123456789012345678]
enabled = false
token = ""

Expand Down
7 changes: 7 additions & 0 deletions migrations/20260908000000_add_event_discord_post.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE public.event_discord_message (
event_id uuid PRIMARY KEY REFERENCES public.event(id) ON DELETE CASCADE,
guild_id text NOT NULL,
message_id text NOT NULL,
status text NOT NULL CHECK (status IN ('Sync', 'OutOfSync')),
synced_at timestamptz NOT NULL
);
Loading