Skip to content

Commit b0a4081

Browse files
committed
fix: message content types
1 parent 0aae705 commit b0a4081

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

backend/src/plugins/Logs/types.ts

Lines changed: 11 additions & 3 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 { keys, zBoundedCharacters, zMessageContent, zRegex, zSnowflake } from "../../utils.js";
9+
import { keys, zBoundedCharacters, zEmbedInput, zMessageContent, zRegex, zSnowflake, zStrictMessageContent } from "../../utils.js";
1010
import { MessageBuffer } from "../../utils/MessageBuffer.js";
1111
import {
1212
TemplateSafeCase,
@@ -27,11 +27,19 @@ const DEFAULT_BATCH_TIME = 1000;
2727
const MIN_BATCH_TIME = 250;
2828
const MAX_BATCH_TIME = 5000;
2929

30+
const zStrictLogMessageContent = zStrictMessageContent.extend({
31+
embed: zEmbedInput.optional(),
32+
});
33+
const zLogMessageContent = z.union([
34+
zBoundedCharacters(0, 2000),
35+
zStrictLogMessageContent,
36+
]);
37+
3038
// A bit of a workaround so we can pass LogType keys to z.enum()
31-
const zMessageContentWithDefault = zMessageContent.default("");
39+
const zMessageContentWithDefault = zLogMessageContent.default("");
3240
const logTypes = keys(LogType);
3341
const logTypeProps = logTypes.reduce((map, type) => {
34-
map[type] = zMessageContent.default(DefaultLogMessages[type] || "");
42+
map[type] = zLogMessageContent.default(DefaultLogMessages[type] || "");
3543
return map;
3644
}, {} as Record<keyof typeof LogType, typeof zMessageContentWithDefault>);
3745
const zLogFormats = z.strictObject(logTypeProps);

backend/src/plugins/Logs/util/getLogMessage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
3737
const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || "";
3838
if (format === "" || format == null) return null;
3939

40+
if (typeof format === "object" && format.embed) {
41+
format.embeds = [format.embed];
42+
delete format.embed;
43+
}
44+
4045
// See comment on FORMAT_NO_TIMESTAMP in types.ts
4146
const timestampFormat = opts?.timestamp_format ?? config.timestamp_format;
4247

backend/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export const zEmbedInput = z.object({
266266

267267
export type EmbedWith<T extends keyof APIEmbed> = APIEmbed & Pick<Required<APIEmbed>, T>;
268268

269-
export const zStrictMessageContent = z.object({
269+
export const zStrictMessageContent = z.strictObject({
270270
content: z.string().optional(),
271271
tts: z.boolean().optional(),
272272
embeds: z.array(zEmbedInput).optional(),

0 commit comments

Comments
 (0)