generated from alex/base-template
feat: add daily random horse fact on join and at midnight #12
No reviewers
Labels
No labels
dependencies
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
alex/irc-greeter-bot!12
Loading…
Reference in a new issue
No description provided.
Delete branch "pi/issue11-1784878459998"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #11.
Adds a random horse fact to spice up the bot's presence in two situations, as requested:
🐴 …) to that channel.Design notes
Bundled facts, not a fetched API. I searched for a random horse-facts API, but there is no reliable, keyless, horse-specific public endpoint (the candidates either require an API key, are offline, or aren't horse-specific). More importantly, the bot's whole design philosophy is resilience and zero-config. So the facts are a curated, bundled list of 30 verified facts. This keeps the feature always available with no new config vars, no API key, and no new network-failure mode — consistent with how the rest of the bot behaves.
Resilient scheduling. The daily timer is started exactly once at startup and self-reschedules every day, always re-arming relative to the current time (so clock drift / slow callbacks never accumulate). It reads the live
currentClientat fire time, so a reconnect — which replaces that reference — is picked up automatically without ever spawning a second timer. If the bot happens to be disconnected at midnight the fact is simply skipped and never crashes the process.On-join vs greeting kept separate. The bot's own join is a distinct event from greeting newcomers, so it has its own
handleBotJoinhandler. Newcomer greeting behaviour is unchanged.Implementation
Following the existing module conventions (pure logic + I/O separated, dependencies injected for testability):
src/facts.tsHORSE_FACTS,pickRandomFact(randomFn),formatFact(pure, no I/O).src/schedule.tsmsUntilNextMidnight(now)+ injectable self-reschedulingstartDailyMidnight.src/main.tshandleBotJoinglue (on join),broadcastFactglue (daily), wired intomain/createClient.src/*_test.tsNo new configuration is required and no extra runtime permissions are needed (no network, just
setTimeout+ local data).Verification
deno fmt --check✓deno task check✓deno lint✓deno task fallow✓ (the 3 test-only exports use the documentedfallow-ignore-next-line unused-exportsuppression)deno task test✓ — 77 passed (55 → 77)