Skip to content

feat(bot): add the zalgo text auto-moderation rule - #260

Merged
RedStar071 merged 5 commits into
V7from
feat/automod-zalgo
Oct 7, 2026
Merged

RedStar071 merged 5 commits into
V7from
feat/automod-zalgo

Conversation

@RedStar071

@RedStar071 RedStar071 commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking 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.

# Only once, on a database that was not made by these migrations: its tables are @@control(external), so the baseline cannot create them.
prisma db sign --db "$DATABASE_URL"
prisma db migrate --db "$DATABASE_URL"

The baseline migration is in this PR because V7 has none. Then stars commands deploy for the new /automod-zalgo command.

🤖 AI disclosure: Wolfstar Agent Kit modified this description. My AI open-source policy.

RetriggerConfidence Score: 5/5

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:

  • New text samples match: A focused Node check returned every expected count. The combined sample has four marks at most, so the rule accepts it at the default limit.

Reviews (2) · Last reviewed commit: "test(bot): pin the combining marks of th..." · Reviewed by Greptile

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.
@coldtea-pr-lens

coldtea-pr-lens Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Note

This drawing shows d01f25a, and the branch has new commits since. Tick Redraw to draw the latest one

  • Redraw

Nothing flagged · reviewed d01f25a


Architecture

Architecture diagram for wolfstar-project/wolfstar at d01f25a

Play the walkthrough


Inside the changed components — 2 views

Component view — Zalgo moderation pipeline

The message inspection, unicode analysis, and moderation action path for zalgo text

Architecture view of Component view — Zalgo moderation pipeline in wolfstar-project/wolfstar

Component view — Auto-moderation configuration

The slash commands, settings cache, and database schema managing zalgo filter rules

Architecture view of Component view — Auto-moderation configuration in wolfstar-project/wolfstar

Data flow

Data flow diagram for wolfstar-project/wolfstar at d01f25a

Follow each request


The other flows — 1 sequence

Configuring zalgo filter via slash command

Sequence diagram of Configuring zalgo filter via slash command in wolfstar-project/wolfstar

View

  • Architecture lens
  • Data flow lens
  • Expand every detail

Tip

Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Untick Architecture lens or Data flow lens under View to hide a diagram, or tick Expand every detail to open every section. The comment redraws in a few seconds
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture and data flow row. Drawing still runs as before
  • Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • Push a commit and the drawing stays, with a note that it is out of date. Tick Redraw in the note to draw the new head

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.

❤️ Share

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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.ts NFD-normalizes and counts the longest run of \p{M}; isZalgo compares it to automod.zalgo.maximum.
  • Listener — guildUserMessageZalgoHandler.ts follows the guildUserMessageNewLinesHandler.ts pattern exactly.
  • Rule plumbing — AutoModerationRules.zalgo, AdderManager.zalgo, configuration.ts, roleDelete, locales, i18next types and the /automod-zalgo subcommands are all wired consistently with newlines.
  • Database — GuildAutoModerationZalgo in contract.prisma, plus Tables, Columns and 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:21 and :26 — toBeLessThanOrEqual(3) for Thai, Devanagari and Arabic would also pass if the function returned 0 for them, and toBeGreaterThan(4) for the Z̷a̶l̸g̷o̴ sample would pass for any count of 5 or more. Pinning the exact counts (as the toBe(6) case already does) would make these tests able to fail on a regression in the regex or the NFD step.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-sonnet-5-5 | 𝕏

greptile-apps[bot]
greptile-apps Bot previously approved these changes Oct 6, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Review Approved in Wolfstar Oct 6, 2026
@RedStar071
RedStar071 added this pull request to stack #261 October 6, 2026 22:17
Tibetan, Devanagari with a nukta and pointed Hebrew stay at 3 or 4, so
the default maximum of 4 does not flag them.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 toBe instead of toBeLessThanOrEqual(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.
  • isZalgo regression case — one mixed Tibetan, Devanagari and Hebrew string asserts false at 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.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

greptile-apps[bot]
greptile-apps Bot previously approved these changes Oct 7, 2026
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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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_baseline goes from null to the V7 contract hash d9315ae and creates only the public schema and the GuildAutoModerationHardAction and ModerationActionType enums, since the tables are @@control(external).
  • Zalgo table migration — 20261007T1309_add_zalgo_rule creates GuildAutoModerationZalgo and a cascading foreign key to GuildAutoModeration. The DDL matches contract.prisma (nullable enabled, int8[] defaults of {}, _pkey and _id_fkey names).
  • Contract snapshots and ref — the d9315ae snapshot has no zalgo model, ee006af adds it, and refs/db.json points 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_rule would fail at the foreign key because GuildAutoModeration doesn'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.toml is still there but unused by the new migrations/app/ layout.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@RedStar071
RedStar071 removed this pull request from stack #261 October 7, 2026 13:23
@RedStar071
RedStar071 merged commit 45f2a68 into V7 Oct 7, 2026
10 of 12 checks passed
@RedStar071
RedStar071 deleted the feat/automod-zalgo branch October 7, 2026 13:26
RedStar071 added a commit that referenced this pull request Oct 7, 2026
### ❓ 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
&#39;feat/automod-zalgo&#39; 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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant