Skip to content

Commit c8cc9f7

Browse files
committed
chore: make fixupEmbeds take WebhookEvent instead of plain record
1 parent d569f8d commit c8cc9f7

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/discord/formatter.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { emojify as githubEmojify } from "@lambdalisue/github-emoji";
2+
import { WebhookEvent } from "@octokit/webhooks-types";
23

34
// Empirically determined GitHub embed description limit in the Discord API.
45
// Anything above this will be ellipsized :/
@@ -21,7 +22,9 @@ const TRANSFORMS: ((s: string) => string)[] = [
2122
ellipsizeText,
2223
];
2324

24-
export default function fixupEmbeds(data: Record<string, any>): void {
25+
export default function fixupEmbeds(data: WebhookEvent): WebhookEvent {
26+
// upcast because properly typing union keys is a nightmare (or just impossible?)
27+
const dataRecord = data as Record<string, any>;
2528
for (
2629
const field of [
2730
// issue
@@ -38,10 +41,12 @@ export default function fixupEmbeds(data: Record<string, any>): void {
3841
"answer",
3942
]
4043
) {
41-
if (data[field]?.body) {
44+
if (dataRecord[field]?.body) {
4245
for (const transform of TRANSFORMS) {
43-
data[field].body = transform(data[field].body);
46+
dataRecord[field].body = transform(dataRecord[field].body);
4447
}
4548
}
4649
}
50+
51+
return data;
4752
}

src/handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export default async function handle(
2828
];
2929
}
3030

31-
// mutate `json` in-place (fixing codeblocks etc.)
32-
fixupEmbeds(json);
31+
// mutates `json` in-place (fixing codeblocks etc.)
32+
json = fixupEmbeds(json);
3333

3434
return await sendWebhook(id, token, headers, json);
3535
}

0 commit comments

Comments
 (0)