Link actor with a discord user #72
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?
Make a command to link an actor with a discord user, so that each discord user that is a player on the campaign has assigned one character
Now let me look at the service-links service, the bot's deploy-commands and config, and check locale keys usage:
I have the full picture now. Let me check the actor route briefly, then implement. The design:
Actor.discordUserId— the Discord player holding a character, unique per campaign (one character per player).POST /api/discord/bot/guild/:guildId/actors/assignand.../actors/unassign(bot-secret gated, like the rest of the router)./dragonroll assign <character>(any player claims a free character for themselves; admins move held ones) and/dragonroll unassign [character], plus visibility in/charactersand/dragonroll status.Now the backend routes in
discord.js:Now the backend bot endpoints for assigning/unassigning actors:
Now the bot's API client:
Now the slash command definitions:
The
guildOnly(wrapper on line 32 needs its closing paren at the end of the chain:I accidentally removed a blank line; let me restore it and insert the assign/unassign dispatch in the same edit:
Now add the
handleActorAssignmentfunction and the status field. First the status addition:The diff is clean. Now update the documentation —
discord-bot/README.mdand theActorline inAGENTS.md:Now the tests. Following the repo convention of loading routers into
node:vmwith stubbed models:Now let me run the test suite:
All 262 tests pass. Let me double-check a few integration points — the actor update route (to ensure
discordUserIdisn't mangled by Foundry sync or the sheet update):The field is untouched by sheet updates and Foundry sync. Final review of the full diff:
The full test suite passes (262/262). Everything is in place. Summary of the change for issue #72:
What was implemented
Feature: each Discord player of a linked campaign can be assigned one character, through the bot.
Backend
backend/src/models/Actor.js— newdiscordUserIdfield (the player holding the character,nullwhen free) with a partial unique index on(campaign, discordUserId), so a player holds at most one character per campaign. Sheet updates and Foundry sync never touch the field.backend/src/routes/discord.js— two new bot-secret-gated routes, following the existing/bot/guild/:guildId/...conventions (envelope,{status,msg}, guild-link → campaign ownership checks):POST /bot/guild/:guildId/actors/assign— takes a character of the guild's campaign for a Discord user; a second assign moves the player (their previous character is freed). A character already held by somebody else answersdiscord.errors.actor-heldunless the bot says the asker is a server administrator (admin).POST /bot/guild/:guildId/actors/unassign— frees the caller's own character, or anybody's withactorId+admin.GET /bot/guild/:guildId/actorsalready returns the whole actor documents, so it now carries each character'sdiscordUserIdfor the bot's listings.Discord bot
/dragonroll assign <character>(name autocomplete) — any player claims a free character for themselves; a server administrator can also take one held by somebody else. Claims a second one frees the first, with a confirmation naming both./dragonroll unassign [character]— without the option you give up your own character; naming somebody else's is administrator-only./charactersnow shows the player linked to each character (🎮 @player, never a ping), and/dragonroll statusshows "Your character".discord-bot/README.md;AGENTS.md'sActormodel line now listsdiscordUserId.Tests
tests/discord-actor-links.test.js(14 tests) loadsroutes/discord.jsintonode:vmwith stubbed models, likemap-tokens.test.js: one-player-one-character, the held-character guard, admin moves/frees, guild-link guards, and the bot's command/autocomplete/route wiring. Rannode --test tests/: 262 pass, 0 fail — I did not run the bot or backend live (needs Discord/Mongo credentials), only syntax checks and the suite.Implementation is ready for review: #78