mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-26 15:47:13 +09:00
Merge branch 'main' into translate
This commit is contained in:
21 files changed
+1626
-22
No files matched your search
@@ -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
|
||||
|
||||
@@ -50,14 +50,7 @@ export class DiscordAuthHooks extends lib.AsyncHookCollection {
|
||||
readonly unlinked = this.newHook<[playerName: string, discordUser: DiscordUser]>();
|
||||
}
|
||||
|
||||
const loaded = new WeakMap<Controller, ControllerPlugin>();
|
||||
|
||||
export class ControllerPlugin {
|
||||
/** The plugin loaded on a controller, for other plugins to read links from. */
|
||||
static get(controller: Controller) {
|
||||
return loaded.get(controller);
|
||||
}
|
||||
|
||||
hooks: DiscordAuthHooks;
|
||||
/** Logins which have been through Discord, by session id */
|
||||
sessions = new Map<string, Session>();
|
||||
@@ -118,9 +111,7 @@ export class ControllerPlugin {
|
||||
messages.DiscordAccountRecord.fromJSON.bind(messages.DiscordAccountRecord),
|
||||
));
|
||||
|
||||
const plugin = new ControllerPlugin(controller, context.logger, context.plugin.name, accounts);
|
||||
loaded.set(controller, plugin);
|
||||
return plugin;
|
||||
return new ControllerPlugin(controller, context.logger, context.plugin.name, accounts);
|
||||
}
|
||||
|
||||
async onSave() {
|
||||
|
||||
@@ -295,15 +295,6 @@ t.test("api for other plugins", t2 => {
|
||||
return calls;
|
||||
}
|
||||
|
||||
t2.test("static get() returns the plugin loaded on a controller", async t3 => {
|
||||
const { plugin, controller } = await startPlugin(t3);
|
||||
t3.equal(ControllerPlugin.get(controller), plugin);
|
||||
const other = new Controller(logger, [], new lib.ControllerConfig("controller", {
|
||||
"controller.database_directory": t3.testdir(),
|
||||
}));
|
||||
t3.equal(ControllerPlugin.get(other), undefined);
|
||||
});
|
||||
|
||||
t2.test(".getLink(), .getAccount() and .getAccounts() read links", async t3 => {
|
||||
const { plugin } = await startPlugin(t3);
|
||||
const session = await discordLogin(plugin, alice);
|
||||
|
||||
Reference in new issue
Block a user