fix(channels): clarify message target syntax

This commit is contained in:
Peter Steinberger
2026-04-27 13:17:57 +01:00
parent 6fe9285f64
commit 4bd356d03a
8 changed files with 63 additions and 47 deletions

View File

@@ -26,18 +26,13 @@ export async function parseAndResolveRecipient(
}
const resolvedCfg = requireRuntimeConfig(cfg, "Discord recipient resolution");
const accountInfo = resolveDiscordAccount({ cfg: resolvedCfg, accountId });
const trimmed = raw.trim();
const resolvedParseOptions = {
...parseOptions,
ambiguousMessage: `Ambiguous Discord recipient "${trimmed}". Use "user:${trimmed}" for DMs or "channel:${trimmed}" for channel messages.`,
};
const resolved = await parseAndResolveDiscordTarget(
raw,
{
cfg: resolvedCfg,
accountId: accountInfo.accountId,
},
resolvedParseOptions,
parseOptions,
);
return { kind: resolved.kind, id: resolved.id };
}

View File

@@ -41,7 +41,7 @@ export function parseDiscordTarget(
}
throw new Error(
options.ambiguousMessage ??
`Ambiguous Discord recipient "${trimmed}". Use "user:${trimmed}" for DMs or "channel:${trimmed}" for channel messages.`,
`Ambiguous Discord recipient "${trimmed}". For DMs use "user:${trimmed}" or "<@${trimmed}>"; for channels use "channel:${trimmed}".`,
);
}
return buildMessagingTarget("channel", trimmed, trimmed);

View File

@@ -62,6 +62,12 @@ describe("parseDiscordTarget", () => {
);
}
});
it("guides ambiguous numeric recipients with all supported explicit formats", () => {
expect(() => parseDiscordTarget("123456789")).toThrow(
'Ambiguous Discord recipient "123456789". For DMs use "user:123456789" or "<@123456789>"; for channels use "channel:123456789".',
);
});
});
describe("resolveDiscordChannelId", () => {