MosswartOverlord/go-services/discord-go/classify.go
Erik 8d4c6ff68f feat(go-services): discord-go — Go port of discord-rare-monitor
Consumes the Python tracker's /ws/live firehose (subscribed to rare+chat),
classifies rares common/great, posts embeds + relays allegiance chat.

- classify.go: the 74-name common-rares set, extracted verbatim from the Python
  COMMON_RARES_PATTERN (not hand-transcribed). go test runs at build time; a
  server-side dump-rares vs the Python regex confirms the sets are IDENTICAL.
- poster.go: a `poster` interface with a real discordgo impl (REST sends by
  channel id; gold/blue embeds, location/time fields, icon attachment) and a
  dry-run log impl.
- ws.go: coder/websocket client to /ws/live with subscribe, ping keepalive,
  exponential-backoff reconnect; rare/chat dispatch incl. vortex-warning + the
  MONITOR_CHARACTER filter.
- SAFE BY DEFAULT: dry-run unless a token AND DRY_RUN=0 are set, so it can never
  double-post to production. Deployed via the compose override
  (discord-rare-monitor-go), running dry-run against the same live firehose.

Validated on the server: connects, subscribes, relays a real chat in dry-run;
classifier parity 74/74 vs the Python regex.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 10:06:59 +02:00

93 lines
3.2 KiB
Go

package main
// Rare classification — a faithful port of discord_rare_monitor.py's
// COMMON_RARES_PATTERN (an anchored exact-match regex of common-rare names).
// Because the regex is fully anchored with no wildcards, an exact-match set is
// equivalent. This list was extracted verbatim from the Python source, not
// hand-transcribed. classify_test.go asserts every entry maps to "common".
//
// classify returns "common" for an exact match, "great" otherwise — identical
// to classify_rare().
func classify(rareName string) string {
if commonRares[rareName] {
return "common"
}
return "great"
}
var commonRares = map[string]bool{
"Alchemist's Crystal": true,
"Scholar's Crystal": true,
"Smithy's Crystal": true,
"Hunter's Crystal": true,
"Observer's Crystal": true,
"Thorsten's Crystal": true,
"Elysa's Crystal": true,
"Chef's Crystal": true,
"Enchanter's Crystal": true,
"Oswald's Crystal": true,
"Deceiver's Crystal": true,
"Fletcher's Crystal": true,
"Physician's Crystal": true,
"Artificer's Crystal": true,
"Tinker's Crystal": true,
"Vaulter's Crystal": true,
"Monarch's Crystal": true,
"Life Giver's Crystal": true,
"Thief's Crystal": true,
"Adherent's Crystal": true,
"Resister's Crystal": true,
"Imbuer's Crystal": true,
"Converter's Crystal": true,
"Evader's Crystal": true,
"Dodger's Crystal": true,
"Zefir's Crystal": true,
"Ben Ten's Crystal": true,
"Corruptor's Crystal": true,
"Artist's Crystal": true,
"T'ing's Crystal": true,
"Warrior's Crystal": true,
"Brawler's Crystal": true,
"Hieromancer's Crystal": true,
"Rogue's Crystal": true,
"Berzerker's Crystal": true,
"Knight's Crystal": true,
"Lugian's Pearl": true,
"Ursuin's Pearl": true,
"Wayfarer's Pearl": true,
"Sprinter's Pearl": true,
"Magus's Pearl": true,
"Lich's Pearl": true,
"Warrior's Jewel": true,
"Melee's Jewel": true,
"Mage's Jewel": true,
"Duelist's Jewel": true,
"Archer's Jewel": true,
"Tusker's Jewel": true,
"Olthoi's Jewel": true,
"Inferno's Jewel": true,
"Gelid's Jewel": true,
"Astyrrian's Jewel": true,
"Executor's Jewel": true,
"Pearl of Blood Drinking": true,
"Pearl of Heart Seeking": true,
"Pearl of Defending": true,
"Pearl of Swift Killing": true,
"Pearl of Spirit Drinking": true,
"Pearl of Hermetic Linking": true,
"Pearl of Blade Baning": true,
"Pearl of Pierce Baning": true,
"Pearl of Bludgeon Baning": true,
"Pearl of Acid Baning": true,
"Pearl of Flame Baning": true,
"Pearl of Frost Baning": true,
"Pearl of Lightning Baning": true,
"Pearl of Impenetrability": true,
"Refreshing Elixir": true,
"Invigorating Elixir": true,
"Miraculous Elixir": true,
"Medicated Health Kit": true,
"Medicated Stamina Kit": true,
"Medicated Mana Kit": true,
"Casino Exquisite Keyring": true,
}