generated from nhcarrigan/template
feat: grant Discord roles for game milestones #132
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Overview
Grant players Discord roles automatically as they reach milestones in the game. Roles are awarded via the Discord API using the bot token at key points in the game flow.
Also maintains an
inGuildflag on the Player record (used by #133) via a combination of OAuth-time checks and bot event listeners.Roles
148614482368462849014861446570239591801486144663403495514Implementation
Elysian
inGuildvalue on the Player record.Apotheosis (existing)
Eternal Sovereignty & Deification
inGuild— Bot Event ListenersThe bot should listen for guild member events on the NHCarrigan server (
1354624415861833870) and update the Player record if one exists for that Discord ID:guildMemberAdd→ look up Player by Discord ID; if found, setinGuild: trueguildMemberRemove→ look up Player by Discord ID; if found, setinGuild: falseThis keeps the flag perfectly in sync without any extra API calls on game load or OAuth beyond the initial seed.
Task Checklist
inGuild: Booleanto thePlayerPrisma modelElysianrole during OAuth callback; suppress guild membership errors; seedinGuildfrom resultApotheosisrole grant also suppresses guild membership errorsEternal Sovereigntyrole on first Vampire Mode final ascensionDeificationrole on first Goddess Mode final ascensionguildMemberAdd→ updateinGuild: trueif Player record existsguildMemberRemove→ updateinGuild: falseif Player record exists✨ This issue was created with help from Hikari~ 🌸
Implementation Notes
Gateway / WebSocket
We only need two events (
GUILD_MEMBER_ADDandGUILD_MEMBER_REMOVE), so pulling in discord.js would be overkill. We should handroll a minimal Discord Gateway WebSocket client instead — it's roughly:wss://gateway.discord.gg/?v=10&encoding=jsonHELLOopcode with a heartbeat loopIDENTIFYpayload with the bot token and theGUILD_MEMBERSprivileged intent (1 << 1)GUILD_MEMBER_ADDandGUILD_MEMBER_REMOVEdispatch eventsImportant: The
GUILD_MEMBERSprivileged intent must be enabled on the bot application in the Discord Developer Portal before this will work.Backfill Script
Before deploying this feature, we need a one-shot script to retroactively sync all existing Player records. The script should:
GET /guilds/{guild_id}/members/{discord_id}to check membershipElysianrole and setinGuild: trueinGuild: falseThis script must be run once against production before the feature goes live, to ensure
inGuildis accurate from day one.