3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-16 02:55:03 +00:00

fix: better fix for embed/embeds

This commit is contained in:
Dragory 2025-05-31 23:09:09 +00:00
parent ab57916a52
commit ff3c02bcec
No known key found for this signature in database
3 changed files with 9 additions and 15 deletions

View file

@ -27,19 +27,11 @@ const DEFAULT_BATCH_TIME = 1000;
const MIN_BATCH_TIME = 250;
const MAX_BATCH_TIME = 5000;
const zStrictLogMessageContent = zStrictMessageContent.extend({
embed: zEmbedInput.optional(),
});
const zLogMessageContent = z.union([
zBoundedCharacters(0, 2000),
zStrictLogMessageContent,
]);
// A bit of a workaround so we can pass LogType keys to z.enum()
const zMessageContentWithDefault = zLogMessageContent.default("");
const zMessageContentWithDefault = zMessageContent.default("");
const logTypes = keys(LogType);
const logTypeProps = logTypes.reduce((map, type) => {
map[type] = zLogMessageContent.default(DefaultLogMessages[type] || "");
map[type] = zMessageContent.default(DefaultLogMessages[type] || "");
return map;
}, {} as Record<keyof typeof LogType, typeof zMessageContentWithDefault>);
const zLogFormats = z.strictObject(logTypeProps);

View file

@ -37,11 +37,6 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || "";
if (format === "" || format == null) return null;
if (typeof format === "object" && format.embed) {
format.embeds = [format.embed];
delete format.embed;
}
// See comment on FORMAT_NO_TIMESTAMP in types.ts
const timestampFormat = opts?.timestamp_format ?? config.timestamp_format;

View file

@ -270,6 +270,13 @@ export const zStrictMessageContent = z.strictObject({
content: z.string().optional(),
tts: z.boolean().optional(),
embeds: z.array(zEmbedInput).optional(),
embed: zEmbedInput.optional(),
}).transform((data) => {
if (data.embed) {
data.embeds = [data.embed];
delete data.embed;
}
return data as StrictMessageContent;
});
export type ZStrictMessageContent = z.infer<typeof zStrictMessageContent>;