!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.
Go to nightbot.tv → Commands → Custom → Add Command, and create:
| Command | Message (this is the important field) | Userlevel | Cooldown |
|---|---|---|---|
!rip | $(urlfetch https://rip-counter.val.run/rip) | Everyone | 3s global |
!deaths | $(urlfetch https://rip-counter.val.run/deaths) | Everyone | 10s global |
!clear | $(urlfetch https://rip-counter.val.run/clear) | Moderator | 5s global |
Paste the $(urlfetch …) part into Message — not Command. Nothing else needs configuring; no API keys, no env vars required.
Cooldowns matter.
!ripfires 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.
!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!
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":"…"}}
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.
main.tsx— routes:/rip,/deaths,/clear,/admin/undo,/admin/reset,/(dashboard)db.ts—counters+ripstables and all querieschat.ts— Nightbot header parsing, mod check, chat-message formattingcomponents/Dashboard.tsx— the dashboard pagecomponents/Layout.tsx— shared HTML shell
- 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 setADMIN_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.