[PR #5372] [MERGED] horizon-server: [discord] posts the server's chat to a Discord channel, drawn as in game #6244

Closed
opened 2026-11-03 06:16:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5372
Author: @ludovic111
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: feat/discord-bridge


📝 Commits (6)

  • 466d68c horizon-server: [discord] posts the chat to a Discord channel, drawn as in game
  • a5fcf75 horizon-server [discord]: transparent ground, never chat_filtered, in the template
  • c6d7e29 Merge remote-tracking branch 'origin/main' into feat/discord-bridge
  • 8602b10 Merge remote-tracking branch 'origin/main' into feat/discord-bridge
  • 8f789bd horizon-server [discord]: players are named by their account, never a nickname alone
  • fe3ef4c Merge remote-tracking branch 'origin/main' into feat/discord-bridge

📊 Changes

10 files changed (+738 additions, -12 deletions)

View changed files

📝 Cargo.lock (+2 -0)
📝 crates/horizon-server/Cargo.toml (+3 -0)
📝 crates/horizon-server/src/config.rs (+10 -0)
➕ crates/horizon-server/src/discord.rs (+676 -0)
📝 crates/horizon-server/src/events.rs (+1 -1)
📝 crates/horizon-server/src/main.rs (+1 -0)
📝 crates/horizon-server/src/settings.rs (+11 -9)
📝 crates/horizon-server/src/supervisor.rs (+1 -0)
📝 docs/api/server-reference.md (+10 -0)
📝 docs/hosting.md (+23 -2)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Asked by Anthony S. (Sculk Hosting, Horizon Team) via Ludovic: the official server's chat in a Discord channel, drawn like in game, never pinging.

What

A new [discord] table in server.toml:

[discord]
webhook = ""                 # the channel's webhook URL (a secret); "" off
events = ["chat", "join", "leave", "death"]   # "kick" too if you like
enabled = true               # false pauses it and keeps the webhook

horizon-server (the supervisor) reads its typed event stream (events.rs: the game's server-events), not the log, and forwards from its own thread, off the game's:

  • Picture: the lines of each 2 s, drawn as one transparent PNG of the in-game chat's text: § colours and bold, a 1-pixel shadow under each glyph (readable on Discord's light and dark themes), wrapped at the chat's 320 GUI px, GUI scale 2.
  • Font: Pixelify Sans Medium (SIL OFL, already in crates/horizon-theme/fonts, credited in docs/hosting.md), rasterised with ab_glyph on its own pixel grid. No Mojang font or asset, and not the dafont "Minecraft" font (a copy of Mojang's glyphs, under a licence not on our list).
  • No pings: every post sets allowed_mentions: {"parse": []}, and every @, <@, <# gets a zero-width joiner, in the alt text and in the plain-text fallback too (which also escapes markdown).
  • Rate: at most one post every 2 s. It waits longer when X-RateLimit-Remaining: 0 or a 429 says to (retry_after, 3 tries). In a burst, lines past 20 per picture are counted ("(N more lines skipped)"). Posting stops on 401/403/404 (the webhook is deleted).
  • Who: a batch from one player gets their name and head as the webhook's avatar (mc-heads.net, by UUID). The join event's IP address is never sent.
  • Only Discord: webhook must be https://(discord|discordapp|ptb.discord|canary.discord).com/api/webhooks/…. The API and the panel show it as (set), and the control API can't change [discord]. Errors never print the URL.
  • Only chat: a chat_filtered event (the server's slur filter, chat-filter-1) is never forwarded, and isn't accepted in events.
  • Fallback: plain text (defused) when drawing fails.

Design note: it's all in horizon-server, so a server picks it up with a new horizon-server and the engine stays the same. The supervisor has no version coupling with the engine, and the official server's 1629fa2-smp engine already emits these events.

Tests

discord::tests: nothing_posted_can_ping (defusing + allowed_mentions in both payload kinds), section_codes_colour_the_runs (colour parsing, no address, no chat_filtered), the_picture_is_the_chat_box (PNG size, wrapping), one_post_per_gap_or_longer_when_told (rate limiter), only_discord_webhooks. Plus reference::the_reference_lists_every_setting (regenerated docs/api/server-reference.md).

Live check: a post from this code to the real #server-chat webhook with @everyone @here <@id>. Discord reported mention_everyone: false, mentions: [], mention_roles: [].

Discord side, already done: #server-chat under 👋 start here (read-only; staff and Kira post), and its webhook, stored only in 1Password. In Kira's layout: horizon-rust/kira#102 (merged).

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at b8cf85f8c, 36 min 22 s)

Check Result
Scope ⚠️ 9 files, +697 −12; 686 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ❌ 500 run, FAILED (errors=1, skipped=1) (4 min 24 s)
rustfmt ✅ (20 s)
clippy ✅ (9 min 6 s)
tests: workspace ❌ 3005 passed, 1 failed (8 min 29 s)
doc tests ✅ 0 passed (13 s)
content root tests ✅ 13 passed (2 min 19 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (5 s)
launcher clippy ✅ (5 min 29 s)
launcher tests ✅ 334 passed (5 min 56 s)
Parity ➖ 363 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 351 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

On the two ❌, both from the first commit's run:

  • tests: workspace: reference::the_reference_lists_every_setting wanted the discord.* keys in the template. Fixed in the second commit ([discord] is a real section of init's template, docs/api/server-reference.md regenerated). After it: cargo test -p horizon-server 75/75, cargo clippy -p horizon-server --all-targets -D warnings clean, cargo fmt --check clean.
  • Python tests: test_perf_bench (ValueError: cannot compare RD 8). It fails the same at main b8cf85f8c; this PR touches no Python.
  • Scope: 686 lines, about 270 of them discord.rs tests and rustfmt's line breaks. The bridge is one piece; splitting it wouldn't ship anything usable.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5372 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/discord-bridge` --- ### 📝 Commits (6) - [`466d68c`](https://github.com/horizon-rust/horizon/commit/466d68c4650e2a440f4a33bb742532d85feaa303) horizon-server: [discord] posts the chat to a Discord channel, drawn as in game - [`a5fcf75`](https://github.com/horizon-rust/horizon/commit/a5fcf7599212b43b36b9c6350f312997cd48d45b) horizon-server [discord]: transparent ground, never chat_filtered, in the template - [`c6d7e29`](https://github.com/horizon-rust/horizon/commit/c6d7e290049b83bb898b1c28f58ee0c80e952df7) Merge remote-tracking branch 'origin/main' into feat/discord-bridge - [`8602b10`](https://github.com/horizon-rust/horizon/commit/8602b105cecd4060cd6682bc59bd08bae1578725) Merge remote-tracking branch 'origin/main' into feat/discord-bridge - [`8f789bd`](https://github.com/horizon-rust/horizon/commit/8f789bde17afd720fbf203251a3d6b19f3b8f2c2) horizon-server [discord]: players are named by their account, never a nickname alone - [`fe3ef4c`](https://github.com/horizon-rust/horizon/commit/fe3ef4c6d177e01d41417fb01dcba4ad86908991) Merge remote-tracking branch 'origin/main' into feat/discord-bridge ### 📊 Changes **10 files changed** (+738 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+2 -0) 📝 `crates/horizon-server/Cargo.toml` (+3 -0) 📝 `crates/horizon-server/src/config.rs` (+10 -0) ➕ `crates/horizon-server/src/discord.rs` (+676 -0) 📝 `crates/horizon-server/src/events.rs` (+1 -1) 📝 `crates/horizon-server/src/main.rs` (+1 -0) 📝 `crates/horizon-server/src/settings.rs` (+11 -9) 📝 `crates/horizon-server/src/supervisor.rs` (+1 -0) 📝 `docs/api/server-reference.md` (+10 -0) 📝 `docs/hosting.md` (+23 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Asked by Anthony S. (Sculk Hosting, Horizon Team) via Ludovic: the official server's chat in a Discord channel, drawn like in game, never pinging. ## What A new `[discord]` table in `server.toml`: ```toml [discord] webhook = "" # the channel's webhook URL (a secret); "" off events = ["chat", "join", "leave", "death"] # "kick" too if you like enabled = true # false pauses it and keeps the webhook ``` `horizon-server` (the supervisor) reads its typed event stream (`events.rs`: the game's `server-events`), not the log, and forwards from its own thread, off the game's: - **Picture**: the lines of each 2 s, drawn as one transparent PNG of the in-game chat's text: § colours and bold, a 1-pixel shadow under each glyph (readable on Discord's light and dark themes), wrapped at the chat's 320 GUI px, GUI scale 2. - **Font**: Pixelify Sans Medium (SIL OFL, already in `crates/horizon-theme/fonts`, credited in docs/hosting.md), rasterised with `ab_glyph` on its own pixel grid. No Mojang font or asset, and not the dafont "Minecraft" font (a copy of Mojang's glyphs, under a licence not on our list). - **No pings**: every post sets `allowed_mentions: {"parse": []}`, and every `@`, `<@`, `<#` gets a zero-width joiner, in the alt text and in the plain-text fallback too (which also escapes markdown). - **Rate**: at most one post every 2 s. It waits longer when `X-RateLimit-Remaining: 0` or a 429 says to (`retry_after`, 3 tries). In a burst, lines past 20 per picture are counted ("(N more lines skipped)"). Posting stops on 401/403/404 (the webhook is deleted). - **Who**: a batch from one player gets their name and head as the webhook's avatar (mc-heads.net, by UUID). The join event's IP address is never sent. - **Only Discord**: `webhook` must be `https://(discord|discordapp|ptb.discord|canary.discord).com/api/webhooks/…`. The API and the panel show it as `(set)`, and the control API can't change `[discord]`. Errors never print the URL. - **Only `chat`**: a `chat_filtered` event (the server's slur filter, chat-filter-1) is never forwarded, and isn't accepted in `events`. - Fallback: plain text (defused) when drawing fails. Design note: it's all in horizon-server, so a server picks it up with a new `horizon-server` and the engine stays the same. The supervisor has no version coupling with the engine, and the official server's 1629fa2-smp engine already emits these events. ## Tests `discord::tests`: `nothing_posted_can_ping` (defusing + `allowed_mentions` in both payload kinds), `section_codes_colour_the_runs` (colour parsing, no address, no `chat_filtered`), `the_picture_is_the_chat_box` (PNG size, wrapping), `one_post_per_gap_or_longer_when_told` (rate limiter), `only_discord_webhooks`. Plus `reference::the_reference_lists_every_setting` (regenerated `docs/api/server-reference.md`). Live check: a post from this code to the real `#server-chat` webhook with `@everyone @here <@id>`. Discord reported `mention_everyone: false`, `mentions: []`, `mention_roles: []`. Discord side, already done: `#server-chat` under 👋 start here (read-only; staff and Kira post), and its webhook, stored only in 1Password. In Kira's layout: horizon-rust/kira#102 (merged). ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at b8cf85f8c, 36 min 22 s) | Check | Result | | --- | --- | | Scope | ⚠️ 9 files, +697 −12; 686 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ❌ 500 run, FAILED (errors=1, skipped=1) (4 min 24 s) | | rustfmt | ✅ (20 s) | | clippy | ✅ (9 min 6 s) | | tests: workspace | ❌ 3005 passed, 1 failed (8 min 29 s) | | doc tests | ✅ 0 passed (13 s) | | content root tests | ✅ 13 passed (2 min 19 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (5 s) | | launcher clippy | ✅ (5 min 29 s) | | launcher tests | ✅ 334 passed (5 min 56 s) | | Parity | ➖ 363 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 351 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | On the two ❌, both from the first commit's run: - tests: workspace: `reference::the_reference_lists_every_setting` wanted the `discord.*` keys in the template. Fixed in the second commit (`[discord]` is a real section of `init`'s template, `docs/api/server-reference.md` regenerated). After it: `cargo test -p horizon-server` 75/75, `cargo clippy -p horizon-server --all-targets -D warnings` clean, `cargo fmt --check` clean. - Python tests: `test_perf_bench` (`ValueError: cannot compare RD 8`). It fails the same at main b8cf85f8c; this PR touches no Python. - Scope: 686 lines, about 270 of them `discord.rs` tests and rustfmt's line breaks. The bridge is one piece; splitting it wouldn't ship anything usable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:16:17 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6244
No description provided.