00:00 / 00:00

Rinnegan

Live Mode

Live mode (rinnegan live) connects to a real-time danmaku event source over WebSocket, evaluates every sender in a streaming window, and bans spammers through bilibili's official room silent-user API.

rinnegan live --url ws://lef.example:8080 --token "$BRIDGE_TOKEN" --room 25034104

Event Source Connection

  • --url (or RINNEGAN_EVENT_URL) points at LAPLACE Event Fetcher with BRIDGE_MODE=1 (ws://host:8080) or LAPLACE Event Bridge (default ws://localhost:9696).
  • --token (or RINNEGAN_EVENT_TOKEN) is the fetcher's BRIDGE_TOKEN or the bridge's --auth token.
  • --room (or RINNEGAN_ROOMS) selects which rooms to watch (comma-separated or repeated). Short room IDs are automatically resolved to canonical long room IDs on startup. Rooms are passed to the fetcher as ?rooms= for server-side filtering and filtered client-side as well; leave empty to watch every room the source sends.
  • The event source must be logged in: configure LOGIN_SYNC_TOKEN on the fetcher, otherwise bilibili hides sender UIDs and messages are skipped as anonymous.
  • Reconnection and deduplication: on disconnect, Rinnegan reconnects with exponential backoff (starting at 1 s, doubling up to 30 s) and remembers the last 20,000 event IDs in a ring buffer so replayed events after a reconnect are never counted twice.

Logging In

Placing real bans requires a bilibili account that is the streamer or a room admin. Rinnegan supports two login methods:

LAPLACE Login Sync

Set LOGIN_SYNC_TOKEN (or --login-sync-token) to the uuid@password shown by the LAPLACE Login Sync browser extension:

LOGIN_SYNC_TOKEN='uuid@password' rinnegan live --url ws://localhost:8080 --room 25034104
  • Cookies are pulled again every 30 minutes (loginSync.refreshMinutes) and whenever bilibili rejects them, so they follow the browser's login state automatically.
  • Custom Login Sync servers can be configured via --login-sync-url (LOGIN_SYNC_URL) and LOGIN_SYNC_AUTH_KEY.

QR Code Login

Run rinnegan login to draw a QR code in the terminal, then scan and confirm it with the bilibili mobile app:

rinnegan login
  • Cookies are saved to data/bilibili-login.json (--login-file, RINNEGAN_LOGIN_FILE), with permissions restricted to its owner (0600).
  • On Windows the file inherits its folder's permissions instead, so keep it in a directory only you can read.
  • To log out, stop any running live process and delete the file; the session stays valid on bilibili's side until it expires.
  • Nothing renews QR cookies automatically: once bilibili stops accepting them, run rinnegan login again, and a running live process picks up the new login the next time bilibili rejects the old one.

Ban Policy and Safety Brake

Silent-List Preflight Check

On startup, Rinnegan reads each room's silent list:

  • Users already on the silent list (as well as users reported via live user-block events) are recorded so Rinnegan never bans the same user twice.
  • Reading the silent list also proves that the account may moderate the room. A room the account cannot moderate automatically falls back to detection-only mode with a warning, without affecting other rooms.

Exemptions

The following users are never banned (logged once as skip in the console and audit log):

ExemptionFlag / OptionDescription
StreamerBuilt-inuserType === 100
Room adminBuilt-inuserType === 1
UID whitelist--exempt-uidComma-separated or repeated UIDs that are never banned
Guard members--exempt-guardsNever ban 舰长, 提督, or 总督
Fan medal level--exempt-medal <n>Never ban users wearing a fan medal at or above level n (0 disables)
Pattern filter--patterns <list>Patterns outside this list are reported only (flood is never banned)

Safety Brake and API Pacing

  • Per-minute cap: at most --max-per-minute bans per room per rolling minute (default 5). Additional spammers wait in queue until the 1-minute window slides past.
  • Per-session cap: at most --max-bans bans per live run (default 100).
  • API call pacing: moderation API calls are serialized with at least 1.2 s between consecutive requests so a burst of detections never hammers bilibili's API; failed ban attempts back off for 60 s before retrying.

Ban Duration and Reason Template

  • Ban duration: --ban-hours <n> sets the hour parameter sent to bilibili; defaults to -1 (permanent).
  • Scheduled auto-lift: --expire-after <hours> makes Rinnegan lift the ban itself after the specified number of hours (see Ban Store and Lift Rules).
  • Reason template: --reason <template> (default '独轮车 ×{count}:{sample}'), stripped of invisible characters and capped at 60 characters. Supported placeholders:
PlaceholderMeaning
{count}Sends in the top cluster inside the window (or trigger hits + 1)
{minutes}Sliding detection window length in minutes
{sample}Representative message sample with invisible characters stripped
{pattern}Chinese pattern label (such as 循环独轮车 or 跟风机器人)
{score}Rounded integer detector score

Admin Commands

bans and unban share the same login credentials and ban store configuration as live:

Inspect Silent List and Ban Records

rinnegan bans --room 25034104                    # bilibili's silent list + Rinnegan's local records
rinnegan bans --room 25034104 --remote           # only bilibili's remote silent list
rinnegan bans --room 25034104 --local --limit 50 # only the latest 50 local ban records

Unban Users or Revert a Session

# Lift bans for specific UIDs and mark their local store records as lifted
rinnegan unban --room 25034104 --uid 123456 --uid 789012 --reason '误封解除'

# Revert every real ban placed during a specific live session from the audit log
rinnegan unban --session 6f1c2a4e-8d3b-4f5a-9c7e-1b2d3e4f5a6b

# Preview which users would be unbanned without calling the API
rinnegan unban --session 6f1c2a4e-8d3b-4f5a-9c7e-1b2d3e4f5a6b --dry-run

Last updated on November 29, 2026

Tech otakus destroy the world