Skip to content

Commit 597a0ba

Browse files
authored
fix(discord): bound PluralKit and voice-message JSON reads
1 parent ecf054a commit 597a0ba

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

extensions/discord/src/pluralkit.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type MockResponse = {
77
ok: boolean;
88
text: () => Promise<string>;
99
json: () => Promise<unknown>;
10+
body: null;
11+
arrayBuffer: () => Promise<Buffer>;
1012
};
1113

1214
const buildResponse = (params: { status: number; body?: unknown }): MockResponse => {
@@ -17,6 +19,8 @@ const buildResponse = (params: { status: number; body?: unknown }): MockResponse
1719
ok: params.status >= 200 && params.status < 300,
1820
text: async () => textPayload,
1921
json: async () => body ?? {},
22+
body: null,
23+
arrayBuffer: async () => Buffer.from(textPayload),
2024
};
2125
};
2226

extensions/discord/src/pluralkit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Discord plugin module implements pluralkit behavior.
22
import { resolveFetch } from "openclaw/plugin-sdk/fetch-runtime";
3-
import { readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
3+
import { readProviderJsonResponse, readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
44

55
const PLURALKIT_API_BASE = "https://api.pluralkit.me/v2";
66
const PLURALKIT_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
@@ -59,5 +59,5 @@ export async function fetchPluralKitMessageInfo(params: {
5959
const detail = text.trim() ? `: ${text.trim()}` : "";
6060
throw new Error(`PluralKit API failed (${res.status})${detail}`);
6161
}
62-
return (await res.json()) as PluralKitMessageInfo;
62+
return await readProviderJsonResponse<PluralKitMessageInfo>(res, "PluralKit message");
6363
}

extensions/discord/src/voice-message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import { MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS } from "openclaw/plugin-sdk/media-runtime";
2323
import { unlinkIfExists } from "openclaw/plugin-sdk/media-runtime";
2424
import { parseStrictFiniteNumber } from "openclaw/plugin-sdk/number-runtime";
25-
import { readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
25+
import { readProviderJsonResponse, readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
2626
import type { RetryRunner } from "openclaw/plugin-sdk/retry-runtime";
2727
import { writeExternalFileWithinRoot } from "openclaw/plugin-sdk/security-runtime";
2828
import { fetchWithSsrFGuard, type SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
@@ -351,7 +351,7 @@ async function requestVoiceUploadUrl(params: {
351351
if (!res.ok) {
352352
throw await createVoiceRequestError(res, "Upload URL request failed");
353353
}
354-
return (await res.json()) as UploadUrlResponse;
354+
return await readProviderJsonResponse<UploadUrlResponse>(res, "discord.voice.upload-url");
355355
} finally {
356356
await release();
357357
}

0 commit comments

Comments
 (0)