






















@@ -1,5 +1,5 @@
11import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2-import { ChannelType } from "../internal/discord.js";
2+import { ChannelType, MessageType } from "../internal/discord.js";
33import { createPartialDiscordChannelWithThrowingGetters } from "../test-support/partial-channel.js";
4455const transcribeFirstAudioMock = vi.hoisted(() => vi.fn());
@@ -966,6 +966,95 @@ describe("preflightDiscordMessage", () => {
966966expect(result).not.toBeNull();
967967});
968968969+it("routes ordinary guild text control commands through authorization instead of dropping them", async () => {
970+const channelId = "channel-text-control-command";
971+const guildId = "guild-text-control-command";
972+const message = createDiscordMessage({
973+id: "m-text-control-command",
974+ channelId,
975+content: "/steer keep digging",
976+author: {
977+id: "user-1",
978+bot: false,
979+username: "Alice",
980+},
981+});
982+983+const result = await preflightDiscordMessage({
984+ ...createPreflightArgs({
985+cfg: DEFAULT_PREFLIGHT_CFG,
986+discordConfig: {} as DiscordConfig,
987+data: createGuildEvent({
988+ channelId,
989+ guildId,
990+author: message.author,
991+ message,
992+}),
993+client: createGuildTextClient(channelId),
994+}),
995+allowFrom: ["discord:user-1"],
996+guildEntries: {
997+[guildId]: {
998+channels: {
999+[channelId]: {
1000+enabled: true,
1001+requireMention: true,
1002+},
1003+},
1004+},
1005+},
1006+});
1007+1008+expect(result).not.toBeNull();
1009+expect(result?.baseText).toBe("/steer keep digging");
1010+expect(result?.commandAuthorized).toBe(true);
1011+expect(result?.shouldRequireMention).toBe(true);
1012+expect(result?.shouldBypassMention).toBe(true);
1013+});
1014+1015+it("still drops Discord native command echo messages", async () => {
1016+const channelId = "channel-native-command-echo";
1017+const guildId = "guild-native-command-echo";
1018+const message = createDiscordMessage({
1019+id: "m-native-command-echo",
1020+ channelId,
1021+content: "/steer keep digging",
1022+type: MessageType.ChatInputCommand,
1023+author: {
1024+id: "user-1",
1025+bot: false,
1026+username: "Alice",
1027+},
1028+});
1029+1030+const result = await preflightDiscordMessage({
1031+ ...createPreflightArgs({
1032+cfg: DEFAULT_PREFLIGHT_CFG,
1033+discordConfig: {} as DiscordConfig,
1034+data: createGuildEvent({
1035+ channelId,
1036+ guildId,
1037+author: message.author,
1038+ message,
1039+}),
1040+client: createGuildTextClient(channelId),
1041+}),
1042+allowFrom: ["discord:user-1"],
1043+guildEntries: {
1044+[guildId]: {
1045+channels: {
1046+[channelId]: {
1047+enabled: true,
1048+requireMention: true,
1049+},
1050+},
1051+},
1052+},
1053+});
1054+1055+expect(result).toBeNull();
1056+});
1057+9691058it("does not mask mention gating when bot id is missing but mention patterns can detect", async () => {
9701059const channelId = "channel-missing-bot-id-mention-gate";
9711060const guildId = "guild-missing-bot-id-mention-gate";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。