Skip to content

feat(discord): Discord operator bot and Telegram moderation parity - #234

Merged
KingPin merged 36 commits into
mainfrom
feat/discord-moderation
Nov 15, 2026
Merged

KingPin merged 36 commits into
mainfrom
feat/discord-moderation

Conversation

@KingPin

@KingPin KingPin commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Adds an optional Discord operator bot and brings the Telegram bot to the same feature set. Both bots now run every action through one shared core (src/lib/opbot/), the same audited path as the admin dashboard.

Discord (off until DISCORD_BOT_TOKEN and DISCORD_PUBLIC_KEY are both set):

  • New discord_bot webhook adapter posts comment alerts as embeds with Approve / Spam / Delete / Restore / Ban / Resolve reports / Reply buttons.
  • POST /discord/interactions handles the buttons, a ban-with-reason modal, queue review, a saved-reply picker, and the slash commands /queue, /stats, /comment, /user, /unban, /link. Slow actions defer before Discord's 3 s deadline and deliver the result through the interaction webhook.
  • Optional once-daily digest to one channel, gated independently of alerts.
  • /admin/discord holds settings, account linking and command registration. Mods come from linked accounts or Discord role grants.
  • Discord 429s honor retry_after and never auto-disable an endpoint.

Telegram:

  • Queue review walks pending comments in place. A status keyboard stays on each card after an action.
  • Ban with a reason, /unban, and ban state in /user.
  • Reply to a comment with a saved reply or custom text.

Upgrade notes:

  • New secret DISCORD_BOT_TOKEN and new var DISCORD_PUBLIC_KEY, both optional.
  • Migration 0033_discord_links (with erasure and export coverage). Run npm run migrate.

Docs: docs/discord.md (new), docs/telegram.md, docs/webhooks.md, compliance docs, README.md, INSTALL.md, AGENTS.md, AGENTS-OPERATE.md.

Not yet verified live: a slow Discord action delivered through the deferred webhook, and the Telegram force-reply mention in a group.

banState read the latest 20 audit rows for a user and searched them for a
ban. Twenty later notes or session actions pushed the ban out of that
window, so both bots reported the reason as purged. Filter for ban/unban
in SQL and take the latest match.
The ban-reason and write-custom prompts used selective force_reply but
mentioned no one and replied to no one, so in a group no user got the
reply box. Mention the tapping moderator with a tg://user link so the
selective target exists.
…line

Every interaction waited for the whole handler before answering. Discord
fails an interaction not acknowledged within 3 s even when the action
already committed, so a slow D1 round trip showed operators a failure and
invited a duplicate retry.

Race the handler against a 2.5 s budget. On time, answer as before. Late,
acknowledge with a deferred response (ephemeral type 5 for commands,
type 6 for buttons and modal submits) and deliver the result through the
interaction webhook. Modal-opening paths stay synchronous: a modal cannot
be deferred.
sendSlow advanced fake timers 100 times without yielding to the real event
loop. Under suite load crypto.subtle.verify could outlast those turns, so the
gate opened before the defer timer existed and the command answered in time
(type 4), failing the deferred-response assertion about half the time.
The defer timer started after checkRateLimit resolved, so a slow
limiter plus a slow D1 read could push the first response past
Discord's 3 s deadline. Run the limiter inside the raced work.
@KingPin
KingPin merged commit 6c310e3 into main Nov 15, 2026
6 checks passed
@KingPin
KingPin deleted the feat/discord-moderation branch November 15, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant