Public
Nightbot !rip, !deaths, !clear — Pokemon death counter
chatbotnightbotpokemonsqlitetwitch
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Pokémon death counter for Nightbot

!rip, !deaths and !clear — a death counter that survives between streams. It's a tiny HTTP API backed by SQLite, which Nightbot calls with $(urlfetch).

Live endpoint: https://rip-counter.val.run

Nightbot's built-in $(count) can't do this: a counter is welded to one command, so !clear can't reset what !rip counts. This val keeps one shared number that all three commands read and write.

Setup: three Nightbot commands

Go to nightbot.tv → Commands → Custom → Add Command, and create:

CommandMessage (this is the important field)UserlevelCooldown
!rip$(urlfetch https://rip-counter.val.run/rip)Everyone3s global
!deaths$(urlfetch https://rip-counter.val.run/deaths)Everyone10s global
!clear$(urlfetch https://rip-counter.val.run/clear)Moderator5s global

Paste the $(urlfetch …) part into Message — not Command. Nothing else needs configuring; no API keys, no env vars required.

Cooldowns matter. !rip fires every time something faints, so a 3-second global cooldown keeps one person from spamming it. The API also ignores repeat !rips from the same user within 3 seconds, so it still behaves if you forget.

What chat sees

!rip        → 💀 RIP! deaths: 7. F
!deaths     → 💀 deaths: 7 — last RIP by Nightbot 2m ago.
!clear      → 🧹 deaths cleared (was 7). Good luck!

!clear from a non-mod is politely refused, and a fresh run reads 💀 deaths: 0 — no deaths yet. Looking clean!

Optional niceties

Name the fallen. Add a label by giving !rip a querystring:

$(urlfetch https://rip-counter.val.run/rip?label=$(querystring))

⚠️ Nightbot does not URL-encode $(querystring), so spaces break the URL. Single words (!rip Pikachu) work; for multi-word names use the encoding trick:

$(eval `$(urlfetch https://rip-counter.val.run/rip?label=${encodeURIComponent('$(querystring)')})`)

Track more than deaths. Every endpoint takes ?counter=:

!shiny  → $(urlfetch https://rip-counter.val.run/rip?counter=shiny)
!shinies → $(urlfetch https://rip-counter.val.run/deaths?counter=shiny)
!resets → $(urlfetch https://rip-counter.val.run/rip?counter=resets)

Counters are per-channel, keyed off the channel Nightbot reports, so the same val can serve several streams without them mixing.

A dashboard lives at the root URL: https://rip-counter.val.run — current count, recent RIPs, and the exact command strings to copy. By hand you can undo a mis-clicked RIP ("Undo last RIP") or wipe the counter ("Reset to 0").

To unlock those two buttons, add an ADMIN_TOKEN and open the page with it:

👉 Add ADMIN_TOKEN here: https://www.val.town/x/popperl0ck/pokemon-rip-counter/environment-variables?key=ADMIN_TOKEN

then visit https://rip-counter.val.run/?token=YOUR_TOKEN. Without a token the dashboard is display-only — and public, including the usernames in the RIP log. Use a token you don't mind typing; it is a mid-stream convenience, not a login.

For an OBS overlay, format=json returns the raw number:

https://rip-counter.val.run/deaths?format=json
→ {"channel":"teststream","counter":"deaths","value":7,"lastRip":{"username":"…"}}

How it works

Rendering mermaid diagram...

Nightbot sends who ran the command in a Nightbot-User header (userLevel=owner|moderator|…) and the channel in Nightbot-Channel. The val reads those headers — not URL parameters — to decide whether a !clear is allowed, and to pick which channel's counter to touch.

Files

  • main.tsx — routes: /rip, /deaths, /clear, /admin/undo, /admin/reset, / (dashboard)
  • db.ts — counters + rips tables and all queries
  • chat.ts — Nightbot header parsing, mod check, chat-message formatting
  • components/Dashboard.tsx — the dashboard page
  • components/Layout.tsx — shared HTML shell

Notes and limits

  • Nightbot truncates $(urlfetch) replies at 400 characters, and the response must be plain text. Every chat route returns a single line capped at 390 chars.
  • The endpoints are public and unauthenticated — that's what lets Nightbot reach them. Anyone who knows the URL can POST a !rip; agree with your chat about that (or set ADMIN_TOKEN, which also gates the dashboard).
  • The per-user 3-second guard is in-memory, so it resets on each cold start. Good enough for chat; not a security boundary.
  • This is plain HTTP, so StreamElements, Fossabot, or any bot with a fetch variable works the same way — point the fetch at the same URLs.