Skip to content

Commit 86ceabd

Browse files
committed
fix(discord): classify announcement threads during channel resolution
1 parent dccef04 commit 86ceabd

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎extensions/discord/src/actions/runtime.messaging.shared.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ChannelMessageActionContext } from "openclaw/plugin-sdk/channel-co
44
// Discord plugin module implements runtime.messaging.shared behavior.
55
import { resolveOpenProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/runtime-group-policy";
66
import { mergeDiscordAccountConfig, resolveDefaultDiscordAccountId } from "../accounts.js";
7+
import { isDiscordThreadChannelType } from "../channel-type.js";
78
import { createDiscordRuntimeAccountContext } from "../client.js";
89
import {
910
isDiscordGroupAllowedByPolicy,
@@ -192,8 +193,7 @@ function readDiscordChannelType(value: unknown): number | undefined {
192193
}
193194

194195
function isDiscordThreadChannel(value: unknown): boolean {
195-
const type = readDiscordChannelType(value);
196-
return type === 10 || type === 11 || type === 12;
196+
return isDiscordThreadChannelType(readDiscordChannelType(value));
197197
}
198198

199199
function isDiscordReadAncestryAllowed(params: {

‎extensions/discord/src/resolve-channels.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Discord tests cover resolve channels plugin behavior.
2+
import { ChannelType } from "discord-api-types/v10";
23
import { withFetchPreconnect } from "openclaw/plugin-sdk/test-env";
34
import { describe, expect, it } from "vitest";
45
import { resolveDiscordChannelAllowlist } from "./resolve-channels.js";
@@ -67,14 +68,19 @@ describe("resolveDiscordChannelAllowlist", () => {
6768
expect(res[0]?.guildId).toBe("111");
6869
}
6970

70-
it("resolves guild/channel by name", async () => {
71+
it.each([
72+
["announcement", ChannelType.AnnouncementThread],
73+
["public", ChannelType.PublicThread],
74+
["private", ChannelType.PrivateThread],
75+
])("prefers a matching guild channel over a %s thread", async (_kind, threadType) => {
7176
const fetcher = withFetchPreconnect(async (input: RequestInfo | URL) => {
7277
const url = urlToString(input);
7378
if (url.endsWith("/users/@me/guilds")) {
7479
return jsonResponse([{ id: "g1", name: "My Guild" }]);
7580
}
7681
if (url.endsWith("/guilds/g1/channels")) {
7782
return jsonResponse([
83+
{ id: "thread-1", name: "general", guild_id: "g1", type: threadType },
7884
{ id: "c1", name: "general", guild_id: "g1", type: 0 },
7985
{ id: "c2", name: "random", guild_id: "g1", type: 0 },
8086
]);

‎extensions/discord/src/resolve-channels.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Discord plugin module implements resolve channels behavior.
22
import { DISCORD_DIRECTORY_LOOKUP_TIMEOUT_MS, DiscordApiError, fetchDiscord } from "./api.js";
3+
import { isDiscordThreadChannelType } from "./channel-type.js";
34
import { listGuilds } from "./guilds.js";
45
import { normalizeDiscordSlug } from "./monitor/allow-list.js";
56
import {
@@ -145,7 +146,7 @@ function preferActiveMatch(candidates: DiscordChannelSummary[]): DiscordChannelS
145146
return undefined;
146147
}
147148
const scored = candidates.map((channel) => {
148-
const isThread = channel.type === 11 || channel.type === 12;
149+
const isThread = isDiscordThreadChannelType(channel.type);
149150
const archived = Boolean(channel.archived);
150151
const score = (archived ? 0 : 2) + (isThread ? 0 : 1);
151152
return { channel, score };

0 commit comments

Comments
 (0)