Expose Discord links to other controller plugins (#525)

exp_discord_auth gains a static get(controller) like exp_roles and exp_groups, getLink/getAccount/getAccounts lookups that return copies, and linked/unlinked AsyncHooks. Moving a player to another Discord account fires unlinked for the old account, then linked for the new one.

This is what exp_discord_sync needs to give linked players their Discord roles.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BastiaanandClaude Opus 5.5 authored and GitHub committed 2026-11-19 13:28:05 +00:00
1 parent cade0cc4d4
commit b513b7a637
3 files changed
+132 -2

No files matched your search

+18
View File
@@ -53,3 +53,21 @@ ExpDiscordAuth.link(player, code)
ExpDiscordAuth.unlink(player)
ExpDiscordAuth.get_linked(player) -- Prints the Discord account the player is linked to
```
## Other plugins
Controller plugins can read links and react to them. Import the plugin class from the controller entrypoint and look it up with the controller.
```ts
import { ControllerPlugin as DiscordAuth } from "@expcluster/discord-auth/dist/node/controller.js";
const discordAuth = DiscordAuth.get(controller); // undefined if exp_discord_auth is not loaded
discordAuth.getLink("Player1"); // { id, name } of the Discord account, or undefined
discordAuth.getAccount(discordId); // { id, name, playerNames }, or undefined
discordAuth.getAccounts(); // every linked Discord account
discordAuth.hooks.linked.attach("my_plugin", (playerName, discordUser) => { /* ... */ });
discordAuth.hooks.unlinked.attach("my_plugin", (playerName, discordUser) => { /* ... */ });
```
Moving a player to another Discord account calls `unlinked` for the old account and then `linked` for the new one. A Factorio account is linked to at most one Discord account. Add `@expcluster/discord-auth` as a dependency and a `references` entry for its `tsconfig.node.json`.