Skip to content

Commit ff3c02b

Browse files
committed
fix: better fix for embed/embeds
1 parent ab57916 commit ff3c02b

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

backend/src/plugins/Logs/types.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,11 @@ 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-
3830
// A bit of a workaround so we can pass LogType keys to z.enum()
39-
const zMessageContentWithDefault = zLogMessageContent.default("");
31+
const zMessageContentWithDefault = zMessageContent.default("");
4032
const logTypes = keys(LogType);
4133
const logTypeProps = logTypes.reduce((map, type) => {
42-
map[type] = zLogMessageContent.default(DefaultLogMessages[type] || "");
34+
map[type] = zMessageContent.default(DefaultLogMessages[type] || "");
4335
return map;
4436
}, {} as Record<keyof typeof LogType, typeof zMessageContentWithDefault>);
4537
const zLogFormats = z.strictObject(logTypeProps);

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ 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-
4540
// See comment on FORMAT_NO_TIMESTAMP in types.ts
4641
const timestampFormat = opts?.timestamp_format ?? config.timestamp_format;
4742

backend/src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ export const zStrictMessageContent = z.strictObject({
270270
content: z.string().optional(),
271271
tts: z.boolean().optional(),
272272
embeds: z.array(zEmbedInput).optional(),
273+
embed: zEmbedInput.optional(),
274+
}).transform((data) => {
275+
if (data.embed) {
276+
data.embeds = [data.embed];
277+
delete data.embed;
278+
}
279+
return data as StrictMessageContent;
273280
});
274281

275282
export type ZStrictMessageContent = z.infer<typeof zStrictMessageContent>;

0 commit comments

Comments
 (0)