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

fix: message content types

This commit is contained in:
Dragory 2025-05-31 22:58:35 +00:00
parent 0aae70561c
commit b0a4081a26
No known key found for this signature in database
3 changed files with 17 additions and 4 deletions

View file

@ -6,7 +6,7 @@ import { GuildCases } from "../../data/GuildCases.js";
import { GuildLogs } from "../../data/GuildLogs.js"; import { GuildLogs } from "../../data/GuildLogs.js";
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js"; import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
import { LogType } from "../../data/LogType.js"; import { LogType } from "../../data/LogType.js";
import { keys, zBoundedCharacters, zMessageContent, zRegex, zSnowflake } from "../../utils.js"; import { keys, zBoundedCharacters, zEmbedInput, zMessageContent, zRegex, zSnowflake, zStrictMessageContent } from "../../utils.js";
import { MessageBuffer } from "../../utils/MessageBuffer.js"; import { MessageBuffer } from "../../utils/MessageBuffer.js";
import { import {
TemplateSafeCase, TemplateSafeCase,
@ -27,11 +27,19 @@ const DEFAULT_BATCH_TIME = 1000;
const MIN_BATCH_TIME = 250; const MIN_BATCH_TIME = 250;
const MAX_BATCH_TIME = 5000; 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() // A bit of a workaround so we can pass LogType keys to z.enum()
const zMessageContentWithDefault = zMessageContent.default(""); const zMessageContentWithDefault = zLogMessageContent.default("");
const logTypes = keys(LogType); const logTypes = keys(LogType);
const logTypeProps = logTypes.reduce((map, type) => { const logTypeProps = logTypes.reduce((map, type) => {
map[type] = zMessageContent.default(DefaultLogMessages[type] || ""); map[type] = zLogMessageContent.default(DefaultLogMessages[type] || "");
return map; return map;
}, {} as Record<keyof typeof LogType, typeof zMessageContentWithDefault>); }, {} as Record<keyof typeof LogType, typeof zMessageContentWithDefault>);
const zLogFormats = z.strictObject(logTypeProps); const zLogFormats = z.strictObject(logTypeProps);

View file

@ -37,6 +37,11 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || ""; const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || "";
if (format === "" || format == null) return null; 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 // See comment on FORMAT_NO_TIMESTAMP in types.ts
const timestampFormat = opts?.timestamp_format ?? config.timestamp_format; const timestampFormat = opts?.timestamp_format ?? config.timestamp_format;

View file

@ -266,7 +266,7 @@ export const zEmbedInput = z.object({
export type EmbedWith<T extends keyof APIEmbed> = APIEmbed & Pick<Required<APIEmbed>, T>; export type EmbedWith<T extends keyof APIEmbed> = APIEmbed & Pick<Required<APIEmbed>, T>;
export const zStrictMessageContent = z.object({ export const zStrictMessageContent = z.strictObject({
content: z.string().optional(), content: z.string().optional(),
tts: z.boolean().optional(), tts: z.boolean().optional(),
embeds: z.array(zEmbedInput).optional(), embeds: z.array(zEmbedInput).optional(),