Discord: add per-button component allowlist

This commit is contained in:
Shadow
2026-02-16 15:14:36 -06:00
parent fc8290af42
commit c593709d25
6 changed files with 126 additions and 3 deletions

View File

@@ -52,6 +52,8 @@ export type DiscordComponentButtonSpec = {
animated?: boolean;
};
disabled?: boolean;
/** Optional allowlist of users who can interact with this button (ids or names). */
allowedUsers?: string[];
};
export type DiscordComponentSelectOption = {
@@ -161,6 +163,7 @@ export type DiscordComponentEntry = {
agentId?: string;
accountId?: string;
reusable?: boolean;
allowedUsers?: string[];
messageId?: string;
createdAt?: number;
expiresAt?: number;
@@ -236,6 +239,19 @@ function readOptionalString(value: unknown): string | undefined {
return trimmed ? trimmed : undefined;
}
function readOptionalStringArray(value: unknown, label: string): string[] | undefined {
if (value === undefined) {
return undefined;
}
if (!Array.isArray(value)) {
throw new Error(`${label} must be an array`);
}
if (value.length === 0) {
return undefined;
}
return value.map((entry, index) => readString(entry, `${label}[${index}]`));
}
function readOptionalNumber(value: unknown): number | undefined {
if (typeof value !== "number" || !Number.isFinite(value)) {
return undefined;
@@ -360,6 +376,7 @@ function parseButtonSpec(raw: unknown, label: string): DiscordComponentButtonSpe
}
: undefined,
disabled: typeof obj.disabled === "boolean" ? obj.disabled : undefined,
allowedUsers: readOptionalStringArray(obj.allowedUsers, `${label}.allowedUsers`),
};
}
@@ -698,6 +715,7 @@ function createButtonComponent(params: {
kind: params.modalId ? "modal-trigger" : "button",
label: params.spec.label,
modalId: params.modalId,
allowedUsers: params.spec.allowedUsers,
},
};
}