Repository navigation
feat(bot): add the zalgo text auto-moderation rule - #260
Conversation
GuildAutoModerationZalgo has the columns of the other rule tables and `maximum`, the most combining marks a character may carry. Its settings are automodZalgo*.
A message infringes the rule when one of its characters carries more combining marks than automod.zalgo.maximum (4 by default): the text is decomposed first, so precomposed and combining accents count the same, and the languages that stack marks by design (Thai, Vietnamese, Arabic, Devanagari) stay under it. It is a rule like the others: /automod-zalgo show, edit and reset, the soft actions, the punishment with its threshold, ignored roles and channels.
|
Note This drawing shows
Nothing flagged · reviewed Architecture Inside the changed components — 2 viewsComponent view — Zalgo moderation pipeline The message inspection, unicode analysis, and moderation action path for zalgo text Component view — Auto-moderation configuration The slash commands, settings cache, and database schema managing zalgo filter rules Data flow The other flows — 1 sequence
View
Tip Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion 🪧 More tips
Thanks for using PR Lens! It's built by Coldtea, free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
ℹ️ No critical issues — one default worth validating, plus a rollout note.
Reviewed changes
Reviewed the full diff of the zalgo auto-moderation rule against the existing newlines rule it mirrors.
- Detection util —
zalgo.tsNFD-normalizes and counts the longest run of\p{M};isZalgocompares it toautomod.zalgo.maximum. - Listener —
guildUserMessageZalgoHandler.tsfollows theguildUserMessageNewLinesHandler.tspattern exactly. - Rule plumbing —
AutoModerationRules.zalgo,AdderManager.zalgo,configuration.ts,roleDelete, locales, i18next types and the/automod-zalgosubcommands are all wired consistently with newlines. - Database —
GuildAutoModerationZalgoincontract.prisma, plusTables,Columnsand defaults. Missing child rows fall back to defaults on read and are upserted on write (storage.ts), so existing guilds are unaffected once the table exists.
ℹ️ Deploy order: the table must exist before this ships
fetchGuildData reads every entry of Tables, so once this lands without GuildAutoModerationZalgo in the database, every guild settings read fails, not just zalgo. The PR description already covers the SQL, prisma db sign and stars commands deploy; just make sure the SQL runs before the bot deploys, and that prisma db sign is committed if the contract hash is tracked somewhere I couldn't see.
Technical details
# Zalgo table rollout sequencing
## Affected sites
- projects/database/src/settings/columns.ts:21 — `'GuildAutoModerationZalgo'` added to `Tables`
- projects/database/src/settings/storage.ts:59 — `Tables.map(... .first({ id: key }))` queries every table on each settings read
## Required outcome
- The `GuildAutoModerationZalgo` table exists in every target database before the new bot build starts.
## Open questions for the human
- Is the contract hash (`prisma db sign`) stored in a file outside this repo? Nothing in `projects/database` looks like it.ℹ️ Nitpicks
projects/bot/tests/lib/utilities/zalgo.test.ts:21and:26—toBeLessThanOrEqual(3)for Thai, Devanagari and Arabic would also pass if the function returned0for them, andtoBeGreaterThan(4)for the Z̷a̶l̸g̷o̴ sample would pass for any count of 5 or more. Pinning the exact counts (as thetoBe(6)case already does) would make these tests able to fail on a regression in the regex or the NFD step.
claude-sonnet-5-5 | 𝕏
Tibetan, Devanagari with a nukta and pointed Hebrew stay at 3 or 4, so the default maximum of 4 does not flag them.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (d01f25a → d66ec95), which touches only projects/bot/tests/lib/utilities/zalgo.test.ts.
- Exact counts for the by-design stackers — Thai (2), Devanagari (1), Arabic (1), Khmer (2) and Burmese (2) now use
toBeinstead oftoBeLessThanOrEqual(3). - New heavy-stacker samples — Tibetan clusters (3), Devanagari with a nukta (3), pointed Hebrew (3) and Hebrew with a cantillation mark (4) pin the claim that the default maximum of 4 doesn't flag ordinary text.
- Zalgo sample pinned to 8 — replaces
toBeGreaterThan(4), so the test can fail on a regex or NFD regression. isZalgoregression case — one mixed Tibetan, Devanagari and Hebrew string assertsfalseat the default maximum.
I ran each sample through the same NFD plus \p{M} logic as getMaximumCombiningMarks, and every pinned count matches. This closes the default-4 validation thread and the loose-assertion nitpick from the earlier review; the deploy-order note (table must exist before the bot deploys) still stands as a human step.
claude-sonnet-5-5 | 𝕏
The tables are @@control(external), so the baseline only has what the contract controls: the schema and the two enums. A database that already has the tables is signed at this contract with prisma db sign.
GuildAutoModerationZalgo is controlled by the contract instead of external, so prisma migration plan derives its table and foreign key. The db ref is the baseline contract.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (d66ec95 → f7bd022), which adds only database migration artifacts.
- Baseline migration —
20261007T1308_baselinegoes fromnullto the V7 contract hashd9315aeand creates only thepublicschema and theGuildAutoModerationHardActionandModerationActionTypeenums, since the tables are@@control(external). - Zalgo table migration —
20261007T1309_add_zalgo_rulecreatesGuildAutoModerationZalgoand a cascading foreign key toGuildAutoModeration. The DDL matchescontract.prisma(nullableenabled,int8[]defaults of{},_pkeyand_id_fkeynames). - Contract snapshots and ref — the
d9315aesnapshot has no zalgo model,ee006afadds it, andrefs/db.jsonpoints at the baseline hash.
This resolves the earlier deploy-order note on the tooling side: the migration now exists and the PR body documents prisma db sign, then prisma db migrate, then stars commands deploy. The table still has to be migrated before the bot deploys, because every settings read queries GuildAutoModerationZalgo.
Two observations, neither blocking:
- The baseline creates no tables, so on a fresh database
add_zalgo_rulewould fail at the foreign key becauseGuildAutoModerationdoesn't exist. This is consistent with the external-schema model the PR body describes, but anyone bootstrapping a clean dev database needs the tables created first. projects/database/src/migrations/migration_lock.tomlis still there but unused by the newmigrations/app/layout.
claude-sonnet-5-5 | 𝕏
### ❓ Type of change - [x] ✨ New feature - [x]⚠️ Breaking change ### 📚 Description Includes the zalgo rule of #260, so merge that one first. A server could only configure one rule per type: one word filter, one link filter, and so on, each with a single set of actions and exemptions. This brings what Dyno does: several named rules, for example a word filter that only deletes and a second one, with other words, that bans. Rules are now rows of `GuildAutoModerationRule` instead of settings. A server has up to 25, as many of one type as it wants, each with its own options, actions, threshold and exempt roles and channels. `/automod create|edit|delete|list|show|add|remove|ignore` manages them, and so do `GET/POST /guilds/:guild/automod/rules` and `GET/PATCH/DELETE /guilds/:guild/automod/rules/:rule` for the dashboard. Things a reviewer should know: - When a message infringes several rules of the same type, only the first enabled one is applied. Rules of different types still all run, as before. - The `Mentions` rule (`automodMentions*` and its overrides table) had no listener, so it is dropped rather than migrated. - The cap of 25 rules and of 200 entries per list are my picks. Say if you want other numbers. - Writes are queued per server and read the rule from the database first, so two edits at once no longer undo each other within a process. Across shards the window is one read and one write wide; the unique index on the name covers the case that would leave a rule unreachable. - Not sure about `/automod ignore` toggling. Separate `ignore`/`unignore` subcommands would be clearer, but cost command size. ###⚠️ Breaking Changes - The `/automod-<type>` commands are gone, replaced by `/automod`. - The `automod<Type>*` keys are gone from the settings, so from `GET/PATCH /guilds/:guild/settings` too. The dashboard has to use the new routes. `automodChannel` and `automodTrackNative` stay. ### 📝 Migration Two Prisma 8 migrations, on top of the baseline and the zalgo one from #260. The tables of the old rules are `@@control(external)`, so the drop is a migration of its own, not part of the first. ```sh # 1. Before the deploy: the table, the enum and the unique index on the lowercase name, and one rule per enabled # configuration of the old tables. The old tables stay, so the build that is running keeps working and a rollback has them. prisma db migrate --db "$DATABASE_URL" --to 20261007T1312_add_automod_rules # 2. Once the deploy is verified: drops the old tables (and the zalgo one). There is no way back after it. prisma db migrate --db "$DATABASE_URL" ``` Rules edited with the old commands between the two steps are not carried over. Then `stars commands deploy`. > 🤖 AI disclosure: [Wolfstar Agent Kit](https://github.com/wolfstar-project/wolfstar-agent-kit) modified this description. [My AI open-source policy](https://harlanzw.com/blog/ai-in-open-source). <!-- greptile_comment --> <!-- greptile_summary --> <h2><a href="https://app.greptile.com/api/retrigger?id=76196422"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a>Confidence Score: 3/5</h2> <!-- greptile-risk --> Not safe to merge until concurrent edits preserve both successful changes and migrated filters retain their existing entries; the exemption-list display problem is non-blocking. <!-- greptile_confidence_score:3 --> <sub>Reviews (1) · Last reviewed commit: ["Merge branch 'feat/automod-zalgo' into f..."](a4016c7) · [Reviewed by Greptile](https://www.greptile.com/?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews&utm_content=wolfstar-project/wolfstar)</sub> <!-- /greptile_comment -->

❓ Type of change
📚 Description
Based on
V7.Zalgo text (
Za̶̡͑lgo̴͖͊) makes a channel unreadable and none of the existing rules catches it: it is not capitals, links or new lines. This adds it as an auto-moderation rule like the others, with/automod-zalgo show|edit|reset, the soft actions, the punishment and its threshold, and ignored roles and channels.A message infringes when one character carries more combining marks than
automod.zalgo.maximum, 4 by default. The text is decomposed first, soécounts one mark however it was typed.4 holds for the scripts that stack the most. Thai, Khmer and Burmese reach 2, Tibetan clusters, Devanagari with a nukta and pointed Hebrew reach 3, Hebrew with a cantillation mark reaches 4, and the tests pin a sample of each. The Zalgo sample in the tests carries 8. What still goes over is rare by design, such as the Tibetan seed syllable of Kalachakra, a single stack of seven.
📝 Migration
The table is a Prisma 8 migration now,
20261007T1309_add_zalgo_rule. Run it before the bot deploys, since every read of the guild settings fails without the table.The baseline migration is in this PR because
V7has none. Thenstars commands deployfor the new/automod-zalgocommand.No blocking issues are reported; deployment still requires the external database table, updated contract signing, and command deployment described in the PR.
What we checked:
Reviews (2) · Last reviewed commit: "test(bot): pin the combining marks of th..." · Reviewed by Greptile