Link Discord from the user page and document the setup

The user page gets a Link Discord button. It asks the controller for a
one-time ticket bound to the logged in user, then goes through the
authorize route with it. The callback links the Discord account to that
user directly, without the in-game code, and goes back to the user page.
The link flow always shows the Discord consent screen.

The README covers registering the redirect URL and the config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 13:34:14 +00:00
1 parent 8e9f780cc2
commit e4fda18276
6 files changed
+261 -30

No files matched your search

+35
View File
@@ -64,6 +64,14 @@ function selfOrPermission(permission: lib.PermissionName) {
};
}
/** Only the user themselves, no permission lets someone link another user to their Discord. */
function selfOnly(user: lib.IUser, message: lib.MessageRequest) {
const playerName = (message.data as { player_name: string }).player_name;
if (user.name.toLowerCase() !== playerName.toLowerCase()) {
throw new lib.PermissionError("You can only link your own account");
}
}
const LinkResponse = lib.plainJson(Type.Union([
Type.Null(),
Type.Object({
@@ -157,3 +165,30 @@ export class DiscordLinkGetRequest {
return new this(json.player_name);
}
}
/** Start linking the Discord account from the user page, responds with a ticket for the authorize route. */
export class DiscordLinkStartRequest {
declare ["constructor"]: typeof DiscordLinkStartRequest;
static plugin = "exp_discord" as const;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = selfOnly;
static Response = lib.plainJson(Type.String());
constructor(
public playerName: string,
) {}
static jsonSchema = Type.Object({
player_name: Type.String(),
});
toJSON() {
return { player_name: this.playerName };
}
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.player_name);
}
}