mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:27:40 +00:00
Config: require Discord ID strings (#18220)
This commit is contained in:
@@ -334,7 +334,7 @@ export type AgentComponentContext = {
|
||||
token?: string;
|
||||
guildEntries?: Record<string, DiscordGuildEntryResolved>;
|
||||
/** DM allowlist (from allowFrom config; legacy: dm.allowFrom) */
|
||||
allowFrom?: Array<string | number>;
|
||||
allowFrom?: string[];
|
||||
/** DM policy (default: "pairing") */
|
||||
dmPolicy?: "open" | "pairing" | "allowlist" | "disabled";
|
||||
};
|
||||
|
||||
@@ -21,8 +21,8 @@ export type DiscordGuildEntryResolved = {
|
||||
slug?: string;
|
||||
requireMention?: boolean;
|
||||
reactionNotifications?: "off" | "own" | "all" | "allowlist";
|
||||
users?: Array<string | number>;
|
||||
roles?: Array<string | number>;
|
||||
users?: string[];
|
||||
roles?: string[];
|
||||
channels?: Record<
|
||||
string,
|
||||
{
|
||||
@@ -30,8 +30,8 @@ export type DiscordGuildEntryResolved = {
|
||||
requireMention?: boolean;
|
||||
skills?: string[];
|
||||
enabled?: boolean;
|
||||
users?: Array<string | number>;
|
||||
roles?: Array<string | number>;
|
||||
users?: string[];
|
||||
roles?: string[];
|
||||
systemPrompt?: string;
|
||||
includeThreadStarter?: boolean;
|
||||
autoThread?: boolean;
|
||||
@@ -44,8 +44,8 @@ export type DiscordChannelConfigResolved = {
|
||||
requireMention?: boolean;
|
||||
skills?: string[];
|
||||
enabled?: boolean;
|
||||
users?: Array<string | number>;
|
||||
roles?: Array<string | number>;
|
||||
users?: string[];
|
||||
roles?: string[];
|
||||
systemPrompt?: string;
|
||||
includeThreadStarter?: boolean;
|
||||
autoThread?: boolean;
|
||||
@@ -53,10 +53,7 @@ export type DiscordChannelConfigResolved = {
|
||||
matchSource?: ChannelMatchSource;
|
||||
};
|
||||
|
||||
export function normalizeDiscordAllowList(
|
||||
raw: Array<string | number> | undefined,
|
||||
prefixes: string[],
|
||||
) {
|
||||
export function normalizeDiscordAllowList(raw: string[] | undefined, prefixes: string[]) {
|
||||
if (!raw || raw.length === 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -141,7 +138,7 @@ export function resolveDiscordAllowListMatch(params: {
|
||||
}
|
||||
|
||||
export function resolveDiscordUserAllowed(params: {
|
||||
allowList?: Array<string | number>;
|
||||
allowList?: string[];
|
||||
userId: string;
|
||||
userName?: string;
|
||||
userTag?: string;
|
||||
@@ -158,10 +155,10 @@ export function resolveDiscordUserAllowed(params: {
|
||||
}
|
||||
|
||||
export function resolveDiscordRoleAllowed(params: {
|
||||
allowList?: Array<string | number>;
|
||||
allowList?: string[];
|
||||
memberRoleIds: string[];
|
||||
}) {
|
||||
// Role allowlists accept role IDs only (string or number). Names are ignored.
|
||||
// Role allowlists accept role IDs only. Names are ignored.
|
||||
const allowList = normalizeDiscordAllowList(params.allowList, ["role:"]);
|
||||
if (!allowList) {
|
||||
return true;
|
||||
@@ -173,8 +170,8 @@ export function resolveDiscordRoleAllowed(params: {
|
||||
}
|
||||
|
||||
export function resolveDiscordMemberAllowed(params: {
|
||||
userAllowList?: Array<string | number>;
|
||||
roleAllowList?: Array<string | number>;
|
||||
userAllowList?: string[];
|
||||
roleAllowList?: string[];
|
||||
memberRoleIds: string[];
|
||||
userId: string;
|
||||
userName?: string;
|
||||
@@ -253,7 +250,7 @@ export function resolveDiscordOwnerAllowFrom(params: {
|
||||
|
||||
export function resolveDiscordCommandAuthorized(params: {
|
||||
isDirectMessage: boolean;
|
||||
allowFrom?: Array<string | number>;
|
||||
allowFrom?: string[];
|
||||
guildInfo?: DiscordGuildEntryResolved | null;
|
||||
author: User;
|
||||
}) {
|
||||
@@ -478,7 +475,7 @@ export function isDiscordGroupAllowedByPolicy(params: {
|
||||
}
|
||||
|
||||
export function resolveGroupDmAllow(params: {
|
||||
channels?: Array<string | number>;
|
||||
channels?: string[];
|
||||
channelId: string;
|
||||
channelName?: string;
|
||||
channelSlug: string;
|
||||
@@ -503,7 +500,7 @@ export function shouldEmitDiscordReactionNotification(params: {
|
||||
userId: string;
|
||||
userName?: string;
|
||||
userTag?: string;
|
||||
allowlist?: Array<string | number>;
|
||||
allowlist?: string[];
|
||||
}) {
|
||||
const mode = params.mode ?? "own";
|
||||
if (mode === "off") {
|
||||
|
||||
@@ -721,7 +721,7 @@ export class DiscordExecApprovalHandler {
|
||||
}
|
||||
|
||||
/** Return the list of configured approver IDs. */
|
||||
getApprovers(): Array<string | number> {
|
||||
getApprovers(): string[] {
|
||||
return this.opts.config.approvers ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ export type DiscordMessagePreflightParams = {
|
||||
replyToMode: ReplyToMode;
|
||||
dmEnabled: boolean;
|
||||
groupDmEnabled: boolean;
|
||||
groupDmChannels?: Array<string | number>;
|
||||
allowFrom?: Array<string | number>;
|
||||
groupDmChannels?: string[];
|
||||
allowFrom?: string[];
|
||||
guildEntries?: Record<string, DiscordGuildEntryResolved>;
|
||||
ackReactionScope: DiscordMessagePreflightContext["ackReactionScope"];
|
||||
groupPolicy: DiscordMessagePreflightContext["groupPolicy"];
|
||||
|
||||
@@ -77,7 +77,7 @@ export type MonitorDiscordOpts = {
|
||||
replyToMode?: ReplyToMode;
|
||||
};
|
||||
|
||||
function summarizeAllowList(list?: Array<string | number>) {
|
||||
function summarizeAllowList(list?: string[]) {
|
||||
if (!list || list.length === 0) {
|
||||
return "any";
|
||||
}
|
||||
@@ -352,7 +352,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
continue;
|
||||
}
|
||||
const nextGuild = { ...guildConfig } as Record<string, unknown>;
|
||||
const users = (guildConfig as { users?: Array<string | number> }).users;
|
||||
const users = (guildConfig as { users?: string[] }).users;
|
||||
if (Array.isArray(users) && users.length > 0) {
|
||||
const additions = resolveAllowlistIdAdditions({ existing: users, resolvedMap });
|
||||
nextGuild.users = mergeAllowlist({ existing: users, additions });
|
||||
|
||||
Reference in New Issue
Block a user