Discord: add PluralKit sender identity resolver (#5838)

* Discord: add PluralKit sender identity resolver

* fix: resolve PluralKit sender identities (#5838) (thanks @thewilloftheshadow)
This commit is contained in:
Shadow
2026-01-31 19:50:06 -06:00
committed by GitHub
parent 66e33abd7b
commit 8e2b17e0c5
15 changed files with 354 additions and 55 deletions

View File

@@ -50,7 +50,7 @@ import {
resolveDiscordGuildEntry,
resolveDiscordUserAllowed,
} from "./allow-list.js";
import { formatDiscordUserTag } from "./format.js";
import { resolveDiscordSenderIdentity } from "./sender-identity.js";
import { resolveDiscordChannelInfo } from "./message-utils.js";
import { resolveDiscordThreadParentInfo } from "./threading.js";
@@ -525,6 +525,7 @@ async function dispatchDiscordCommandInteraction(params: {
if (!user) {
return;
}
const sender = resolveDiscordSenderIdentity({ author: user, pluralkitInfo: null });
const channel = interaction.channel;
const channelType = channel?.type;
const isDirectMessage = channelType === ChannelType.DM;
@@ -539,13 +540,14 @@ async function dispatchDiscordCommandInteraction(params: {
const ownerAllowList = normalizeDiscordAllowList(discordConfig?.dm?.allowFrom ?? [], [
"discord:",
"user:",
"pk:",
]);
const ownerOk =
ownerAllowList && user
? allowListMatches(ownerAllowList, {
id: user.id,
name: user.username,
tag: formatDiscordUserTag(user),
id: sender.id,
name: sender.name,
tag: sender.tag,
})
: false;
const guildInfo = resolveDiscordGuildEntry({
@@ -618,12 +620,12 @@ async function dispatchDiscordCommandInteraction(params: {
if (dmPolicy !== "open") {
const storeAllowFrom = await readChannelAllowFromStore("discord").catch(() => []);
const effectiveAllowFrom = [...(discordConfig?.dm?.allowFrom ?? []), ...storeAllowFrom];
const allowList = normalizeDiscordAllowList(effectiveAllowFrom, ["discord:", "user:"]);
const allowList = normalizeDiscordAllowList(effectiveAllowFrom, ["discord:", "user:", "pk:"]);
const permitted = allowList
? allowListMatches(allowList, {
id: user.id,
name: user.username,
tag: formatDiscordUserTag(user),
id: sender.id,
name: sender.name,
tag: sender.tag,
})
: false;
if (!permitted) {
@@ -633,8 +635,8 @@ async function dispatchDiscordCommandInteraction(params: {
channel: "discord",
id: user.id,
meta: {
tag: formatDiscordUserTag(user),
name: user.username ?? undefined,
tag: sender.tag,
name: sender.name,
},
});
if (created) {
@@ -661,9 +663,9 @@ async function dispatchDiscordCommandInteraction(params: {
const userOk = hasUserAllowlist
? resolveDiscordUserAllowed({
allowList: channelUsers,
userId: user.id,
userName: user.username,
userTag: formatDiscordUserTag(user),
userId: sender.id,
userName: sender.name,
userTag: sender.tag,
})
: false;
const authorizers = useAccessGroups
@@ -768,7 +770,7 @@ async function dispatchDiscordCommandInteraction(params: {
SenderName: user.globalName ?? user.username,
SenderId: user.id,
SenderUsername: user.username,
SenderTag: formatDiscordUserTag(user),
SenderTag: sender.tag,
Provider: "discord" as const,
Surface: "discord" as const,
WasMentioned: true,