Add exp_discord_sync to give linked players Discord roles

New controller plugin that maps clusterio roles to Discord roles and gives them to players linked through exp_discord_auth. The mapping is edited in a Discord Roles section on the role page, which needs the new exp_discord_sync.mapping.update permission. The guild's roles fill a dropdown, and typing a role ID still works when the bot can't list them.

Discord is reached with Node's fetch and WebSocket, no library. REST requests go one at a time and wait out 429 and exhausted rate limits. A minimal gateway connection with the Server Members intent gives roles on guild join. It identifies again instead of resuming, and every READY syncs all linked accounts, which covers startup and joins missed while disconnected. Without the intent the gateway is dropped and syncing carries on over REST.

Syncs run on link, unlink, clusterio role change, guild join, mapping change and connect. Only mapped Discord roles are ever added or removed.

exp_discord_auth may load after this plugin, so it is looked up and its hooks attached when the first sync runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-23 16:25:53 +00:00
1 parent c1490c0709
commit 2c55cb796e
18 files changed
+1494

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
import * as lib from "@clusterio/lib";
import * as messages from "./messages.js";
declare module "@clusterio/lib" {
export interface ControllerConfigFields {
"exp_discord_sync.bot_token": string | null;
"exp_discord_sync.guild_id": string | null;
}
export interface Permissions {
"exp_discord_sync.mapping.update": never;
}
}
export const plugin: lib.PluginDeclaration = {
name: "exp_discord_sync",
title: "ExpGaming - Discord Sync",
description: "Clusterio plugin giving players linked with exp_discord_auth the Discord roles mapped to their clusterio roles",
messages: [
messages.RoleMappingUpdatedEvent,
messages.RoleMappingUpdateRequest,
messages.GuildRoleListRequest,
],
permissions: [
{
name: "exp_discord_sync.mapping.update",
title: "Update Discord Roles",
description: "Change which Discord roles are given to players holding a role.",
grantByDefault: false,
},
],
controllerEntrypoint: "./dist/node/controller.js",
controllerConfigFields: {
"exp_discord_sync.bot_token": {
title: "Bot Token",
description: "Token of the Discord bot which gives the roles.",
type: "string",
credential: ["controller"],
optional: true,
},
"exp_discord_sync.guild_id": {
title: "Guild ID",
description: "ID of the Discord server to give roles in.",
type: "string",
optional: true,
},
},
webEntrypoint: "./web",
};