00:00 / 00:00

Rinnegan

Ban Store & Lift Rules

In live enforcement mode, every real ban placed by Rinnegan (outside dry-run mode) is persisted to a BanStore together with its full assessment evidence, and tracked by the background BanLifecycle engine for automatic lifting.

Storage Backends

Select a backend via --store <url>, the RINNEGAN_STORE_URL environment variable, or storeUrl in your configuration file. All backends use Bun's built-in runtime drivers with zero external database client dependencies:

Connection URL FormatDriverDescription
sqlite:data/rinnegan.sqlite (or a bare file path)bun:sqliteDefault. Recommended for single-node deployments; automatically enables WAL mode and maintains local indexes.
postgres://user:pass@host:5432/db or postgresql://…Bun.sqlIdeal for multi-instance shared state and centralized queries. Automatically creates the rinnegan_bans table and indexes.
redis://host:6379, rediss://…, or valkey://…Bun.redisStores ban records in hashes and tracks active bans and expiry queues with sorted sets (ZSET).
memory:In-process memoryEphemeral storage for the lifetime of the current process; also used automatically in --dry-run mode.

Ban Record Schema

Each BanRecord captures the detector score, pattern, evidence snapshot, and subsequent lifecycle transitions:

Prop

Type

Built-In Auto-Lift Rules

BanLifecycle evaluates registered rules in order whenever a paid event arrives in the room or on a periodic 60-second tick:

Scheduled Auto-Expiry (--expire-after)

Pass --expire-after <hours> (or ban.expireAfterHours) to have Rinnegan automatically lift bans it placed after the specified number of hours:

# Place a permanent bilibili ban, then automatically lift it after 24 hours
rinnegan live --room 21452505 --ban-hours -1 --expire-after 24
  • Once expiresAt <= now, the built-in expiryRule() lifts the ban on the next periodic tick and marks the record status as expired.
  • If the unban API call fails due to a transient network error or expired credentials, the record stays active and is retried on the next minute tick.

Spend-to-Unban (--unban-spend)

Pass --unban-spend <cny> (or unbanSpendCny) to automatically lift a user's active ban once their cumulative paid spending in that room reaches the specified CNY amount:

# Lift a user's ban automatically once they spend 30 CNY in the room
rinnegan live --room 21452505 --unban-spend 30
  • Counted Paid Events: Gold-coin gifts (gift with coinType === 'gold'), SuperChats (superchat), and Guard memberships (toast). Free silver-coin gifts are ignored.
  • Immediate Evaluation and Periodic Retry: Every paid event adds its CNY value to the spend field of the user's newest active ban in that room and immediately evaluates spendToUnbanRule(thresholdCny). As soon as ban.spend >= thresholdCny, Rinnegan calls the unban API and sets the record status to lifted (with reason spend ¥X.XX >= ¥Y).

Custom Lifecycle Rules (Programmatic API)

When embedding @laplace.live/rinnegan as a library, you can pass custom BanRule objects to BanLifecycle. Rules run in order, and the first decision other than keep wins:

  • { action: 'keep' }: Keep the ban active.
  • { action: 'lift', reason: string }: Immediately call the unban API and record the lift reason.
  • { action: 'extend', expiresAt: number, reason: string }: Update the ban's scheduled expiry timestamp (in Unix milliseconds).
import { BanLifecycle, createBanStore, expiryRule, spendToUnbanRule } from '@laplace.live/rinnegan'

const store = await createBanStore('sqlite:data/rinnegan.sqlite')
const lifecycle = new BanLifecycle({
  store,
  unban: async (ban, reason) => {
    // Call the unban API and return true on success
    return true
  },
  rules: [
    expiryRule(),
    spendToUnbanRule(50),
  ],
})

Prop

Type

Last updated on November 29, 2026

Tech otakus destroy the world