Wait for exp_discord_auth with plugins.waitFor

Clusterio 2.1.2 loads plugins concurrently and lets them wait for each
other, so exp_discord_sync gets exp_discord_auth in its entrypoint and
attaches the link hooks there instead of looking it up on the first
sync. Without exp_discord_auth it logs an error and does not connect.

DiscordAuth.get() and its WeakMap had no other users and are removed,
the README shows waitFor instead. The sync tests load both plugins
through lib.PluginLoader with sync listed first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-23 16:28:00 +00:00
1 parent 2c55cb796e
commit cf968c02bb
5 files changed
+60 -52

No files matched your search

+3 -3
View File
@@ -56,12 +56,12 @@ ExpDiscordAuth.get_linked(player) -- Prints the Discord account the player is li
## 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.
Controller plugins can read links and react to them. Wait for the plugin from your entrypoint, the class is only needed for its type.
```ts
import { ControllerPlugin as DiscordAuth } from "@expcluster/discord-auth/dist/node/controller.js";
import type { ControllerPlugin as DiscordAuth } from "@expcluster/discord-auth/dist/node/controller.js";
const discordAuth = DiscordAuth.get(controller); // undefined if exp_discord_auth is not loaded
const discordAuth = await plugins.waitFor<DiscordAuth>("exp_discord_auth"); // 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