mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-26 15:47:13 +09:00
Address review of exp_discord_sync
- DiscordRest and DiscordGateway are made in fromContext and passed to the constructor. Both read the token from config, and guildId is a getter over config, so the plugin has no nullable bot state. - DiscordGateway is an EventEmitter and the plugin listens with bound methods (onGatewayReady, onGatewayDispatch, onGatewayFatalClose, onLinkChanged). - Private members start with an underscore. - DiscordGateway has an explicit state (stopped, connecting, identifying, ready, waiting) and _setState throws on a transition not in the table. Errors while handling a gateway message are logged so a failed assert can't take down the controller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf968c02bb
commit
e88cbf990f
4 files changed
+236
-134
No files matched your search
@@ -79,11 +79,11 @@ async function startPlugin(t2, { fakeOptions, mappings = defaultMappings } = {})
|
||||
plugin.mappings.set(new messages.RoleMappingRecord(Number(roleId), ids));
|
||||
}
|
||||
|
||||
plugin.apiBase = fake.apiBase;
|
||||
plugin.gatewayUrl = fake.gatewayUrl;
|
||||
plugin.rest.baseUrl = fake.apiBase;
|
||||
plugin.gateway.url = fake.gatewayUrl;
|
||||
controller.config.set("exp_discord_sync.bot_token", "token");
|
||||
controller.config.set("exp_discord_sync.guild_id", guildId);
|
||||
if (!plugin.gateway) {
|
||||
if (plugin.gateway.state === "stopped") {
|
||||
plugin.connect();
|
||||
}
|
||||
return { plugin, auth, controller, fake };
|
||||
@@ -206,7 +206,7 @@ t.test("syncing", t2 => {
|
||||
setRoles(controller, "Player1", [5]);
|
||||
auth.linkAccount(alice, "Player1");
|
||||
await until(() => rolesOf(fake, alice.id).length === 1);
|
||||
t3.ok(plugin.rest, "rest is kept");
|
||||
t3.equal(plugin.gateway.state, "stopped", "gateway gave up, REST carries on");
|
||||
t3.ok(warnings.some(msg => /missing the Server Members intent/.test(msg)));
|
||||
});
|
||||
|
||||
@@ -241,7 +241,7 @@ t.test("syncing", t2 => {
|
||||
});
|
||||
const [plugin] = loaded.values();
|
||||
t3.equal(plugin.discordAuth, undefined);
|
||||
t3.equal(plugin.gateway, undefined, "does not connect");
|
||||
t3.equal(plugin.gateway.state, "stopped", "does not connect");
|
||||
t3.ok(warnings.some(msg => /exp_discord_auth is not loaded/.test(msg)));
|
||||
});
|
||||
t2.end();
|
||||
|
||||
Reference in new issue
Block a user