fix: use member.roles as string[] per Discord API types

This commit is contained in:
Minidoracat
2026-02-06 20:28:29 +00:00
committed by Shadow
parent e1e6e3f477
commit ad508c8c89

View File

@@ -39,6 +39,7 @@ import {
resolveDiscordChannelConfigWithFallback, resolveDiscordChannelConfigWithFallback,
resolveDiscordGuildEntry, resolveDiscordGuildEntry,
resolveDiscordShouldRequireMention, resolveDiscordShouldRequireMention,
resolveDiscordRoleAllowed,
resolveDiscordUserAllowed, resolveDiscordUserAllowed,
resolveGroupDmAllow, resolveGroupDmAllow,
} from "./allow-list.js"; } from "./allow-list.js";
@@ -220,12 +221,14 @@ export async function preflightDiscordMessage(
} }
// Fresh config for bindings lookup; other routing inputs are payload-derived. // Fresh config for bindings lookup; other routing inputs are payload-derived.
const memberRoleIds = params.data.member?.roles?.map((r: { id: string }) => r.id) ?? []; // member.roles is already string[] (Snowflake IDs) per Discord API types
const memberRoleIds: string[] = params.data.member?.roles ?? [];
const route = resolveAgentRoute({ const route = resolveAgentRoute({
cfg: loadConfig(), cfg: loadConfig(),
channel: "discord", channel: "discord",
accountId: params.accountId, accountId: params.accountId,
guildId: params.data.guild_id ?? undefined, guildId: params.data.guild_id ?? undefined,
memberRoleIds,
peer: { peer: {
kind: isDirectMessage ? "direct" : isGroupDm ? "group" : "channel", kind: isDirectMessage ? "direct" : isGroupDm ? "group" : "channel",
id: isDirectMessage ? author.id : message.channelId, id: isDirectMessage ? author.id : message.channelId,
@@ -535,15 +538,30 @@ export async function preflightDiscordMessage(
if (isGuildMessage) { if (isGuildMessage) {
const channelUsers = channelConfig?.users ?? guildInfo?.users; const channelUsers = channelConfig?.users ?? guildInfo?.users;
if (Array.isArray(channelUsers) && channelUsers.length > 0) { const channelRoles = channelConfig?.roles ?? guildInfo?.roles;
const userOk = resolveDiscordUserAllowed({ const hasUserRestriction = Array.isArray(channelUsers) && channelUsers.length > 0;
allowList: channelUsers, const hasRoleRestriction = Array.isArray(channelRoles) && channelRoles.length > 0;
userId: sender.id,
userName: sender.name, if (hasUserRestriction || hasRoleRestriction) {
userTag: sender.tag, // member.roles is already string[] (Snowflake IDs) per Discord API types
}); const memberRoleIds: string[] = params.data.member?.roles ?? [];
if (!userOk) { const userOk = hasUserRestriction
logVerbose(`Blocked discord guild sender ${sender.id} (not in channel users allowlist)`); ? resolveDiscordUserAllowed({
allowList: channelUsers,
userId: sender.id,
userName: sender.name,
userTag: sender.tag,
})
: false;
const roleOk = hasRoleRestriction
? resolveDiscordRoleAllowed({
allowList: channelRoles,
memberRoleIds,
})
: false;
if (!userOk && !roleOk) {
logVerbose(`Blocked discord guild sender ${sender.id} (not in users/roles allowlist)`);
return null; return null;
} }
} }