Repository navigation
feat(discord): Discord operator bot and Telegram moderation parity - #234
Merged
Merged
Conversation
…oard after each action
…l and queue review
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_TOKENandDISCORD_PUBLIC_KEYare both set):discord_botwebhook adapter posts comment alerts as embeds with Approve / Spam / Delete / Restore / Ban / Resolve reports / Reply buttons.POST /discord/interactionshandles 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./admin/discordholds settings, account linking and command registration. Mods come from linked accounts or Discord role grants.retry_afterand never auto-disable an endpoint.Telegram:
/unban, and ban state in/user.Upgrade notes:
DISCORD_BOT_TOKENand new varDISCORD_PUBLIC_KEY, both optional.0033_discord_links(with erasure and export coverage). Runnpm 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.