hearthbeat
intro
every tuesday the realms go down for maintenance, and every so often they go down when they aren't supposed to. either way, the question in discord is the same: are servers up yet?
hearthbeat, the discord bot, answers that. it checks realm status through blizzard's api every minute and posts when something changes.
the name combines the hearthstone, the item every wow player uses to teleport home, with a heartbeat, since the bot keeps checking the servers' pulse.
what it posts
- region-wide changes: when the share of realms that are down crosses a threshold (half by default), it posts one message instead of hundreds, even if they went down in waves, and names any realms you're watching
- all realms up: when the last realm that was down comes back
- watched realms: a realm on your watch list going down or coming back, with a note if there's a login queue
- maintenance warnings: an hour and 15 minutes before the weekly maintenance window
- status unavailable: when blizzard's api fails three polls in a row. it posts once, then stays quiet until a poll succeeds
the bot's own discord status shows the count, like "Watching 83/83 US realms up". /status gives a region summary, or details for one realm: population, queue, and which realms it's connected to.
avatar and banner
the bot's avatar and banner change with the region, the same way its status dot does:






the avatar is minecraft's creaking heart, which already has three states of its own, and the banner is a pixel heart monitor drawn to match it.
discord rate-limits profile edits, so both images change in a single request, and the bot remembers the state it last set. a restart doesn't spend an edit on a profile that's already right:
const want = s.down === 0 ? 'active' : s.up === 0 ? 'inactive' : 'dormant';
profile ??= await readFile(PROFILE_STATE, 'utf8').catch(() => null);
if (profile === want || profileBusy) return;how it works
polling
blizzard groups realms into connected realms that share a status. the api has a search endpoint that returns every connected realm in a region, up to a thousand per page, so a full poll is one or two requests.
each poll is compared to the last one. realms that changed status are sorted into went down and came up, and whether the share of the region that is down crosses the threshold decides whether it's one region-wide alert or individual ones for watched realms:
// Region-wide events (maintenance / big outage): one message instead of hundreds
const nowRegionDown = s.down / total >= cfg.massThreshold;
const massDown = nowRegionDown && !regionDown;
const massUp = !nowRegionDown && regionDown;
if (massDown) await post(alerts.massDown(wentDown, s), true);
if (massUp) await post(alerts.massUp(cameUp, s), true);
// Region fully recovered after a mass event that trickled back in
if (!massUp && cameUp.length && s.down === 0) await post(alerts.allUp(s), true);a single failed api request is common, so it takes three failures in a row before the bot posts anything.
maintenance
blizzard has no api for maintenance, so the warnings follow the usual schedule: tuesday at 7am pacific for us realms. the bot reads the clock in the maintenance time zone, so daylight saving time is handled without extra code, and each warning is tracked by week so it only posts once.
the time until maintenance is counted in minutes since the start of the week, wrapped around so it's never negative:
const nowMin = WEEKDAYS[parts.weekday] * 1440 + Number(parts.hour) * 60 + Number(parts.minute);
const target = cfg.maintDay * 1440 + cfg.maintHour * 60;
return (target - nowMin + 10080) % 10080; // minutes in a weekrunning on a raspberry pi
the bot runs on my raspberry pi. it's one node process with two dependencies, so the pi has plenty of room for it.
an install script sets it up as a systemd service. it checks the node version, makes sure the config exists, installs dependencies, and writes the service file. the service starts on boot and restarts itself if it crashes.
a second script handles updates. it installs a systemd timer that checks github every minute, and when main has new commits, it resets the checkout to match, reinstalls dependencies, and restarts the bot. a push reaches the pi within about a minute, without me logging into it.
the updater handles two failure cases:
- the update script lives outside the repo, so an update can't rewrite the script while it's running
- it records the last commit that finished deploying, not just the last one it fetched, so a failed install gets retried on the next run
the core of the update script:
as_user git fetch --quiet origin main
target="$(as_user git rev-parse origin/main)"
# Compare against the last commit that finished deploying, so a failed install is retried
deployed="$(cat .git/hearthbeat-deployed 2>/dev/null || true)"
[[ "$target" == "$deployed" ]] && exit 0
# Mirror GitHub exactly: local edits to tracked files are discarded, .env is untouched
as_user git reset --hard --quiet "$target"
as_user npm ci --omit=dev
systemctl restart hearthbeat
echo "$target" > .git/hearthbeat-deployedstack
built with: node, discord.js
data: blizzard's game data api
hosting: raspberry pi, systemd