Skip to content

Commit 21374fa

Browse files
committed
fix: log channel config requiring full format array
1 parent 35f5deb commit 21374fa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

backend/src/plugins/Logs/types.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GuildCases } from "../../data/GuildCases.js";
66
import { GuildLogs } from "../../data/GuildLogs.js";
77
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
88
import { LogType } from "../../data/LogType.js";
9-
import { zBoundedCharacters, zMessageContent, zRegex, zSnowflake } from "../../utils.js";
9+
import { keys, zBoundedCharacters, zMessageContent, zRegex, zSnowflake } from "../../utils.js";
1010
import { MessageBuffer } from "../../utils/MessageBuffer.js";
1111
import {
1212
TemplateSafeCase,
@@ -28,9 +28,12 @@ const MIN_BATCH_TIME = 250;
2828
const MAX_BATCH_TIME = 5000;
2929

3030
// A bit of a workaround so we can pass LogType keys to z.enum()
31-
const logTypes = Object.keys(LogType) as [keyof typeof LogType, ...Array<keyof typeof LogType>];
32-
const zLogFormats = z.record(z.enum(logTypes), zMessageContent);
33-
type TLogFormats = z.infer<typeof zLogFormats>;
31+
const logTypes = keys(LogType);
32+
const logTypeProps = logTypes.reduce((map, type) => {
33+
map[type] = zMessageContent;
34+
return map;
35+
}, {} as Record<keyof typeof LogType, typeof zMessageContent>);
36+
const zLogFormats = z.strictObject(logTypeProps);
3437

3538
const zLogChannel = z.strictObject({
3639
include: z.array(zBoundedCharacters(1, 255)).default([]),
@@ -44,7 +47,7 @@ const zLogChannel = z.strictObject({
4447
excluded_threads: z.array(zSnowflake).nullable().default(null),
4548
exclude_bots: z.boolean().default(false),
4649
excluded_roles: z.array(zSnowflake).nullable().default(null),
47-
format: zLogFormats.default({} as TLogFormats),
50+
format: zLogFormats.partial().default({}),
4851
timestamp_format: z.string().nullable().default(null),
4952
include_embed_timestamp: z.boolean().nullable().default(null),
5053
});

0 commit comments

Comments
 (0)