mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-16 19:15:03 +00:00
fix: message content types
This commit is contained in:
parent
0aae70561c
commit
b0a4081a26
3 changed files with 17 additions and 4 deletions
|
@ -6,7 +6,7 @@ import { GuildCases } from "../../data/GuildCases.js";
|
|||
import { GuildLogs } from "../../data/GuildLogs.js";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages.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 {
|
||||
TemplateSafeCase,
|
||||
|
@ -27,11 +27,19 @@ 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 = zMessageContent.default("");
|
||||
const zMessageContentWithDefault = zLogMessageContent.default("");
|
||||
const logTypes = keys(LogType);
|
||||
const logTypeProps = logTypes.reduce((map, type) => {
|
||||
map[type] = zMessageContent.default(DefaultLogMessages[type] || "");
|
||||
map[type] = zLogMessageContent.default(DefaultLogMessages[type] || "");
|
||||
return map;
|
||||
}, {} as Record<keyof typeof LogType, typeof zMessageContentWithDefault>);
|
||||
const zLogFormats = z.strictObject(logTypeProps);
|
||||
|
|
|
@ -37,6 +37,11 @@ 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;
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ export const zEmbedInput = z.object({
|
|||
|
||||
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(),
|
||||
tts: z.boolean().optional(),
|
||||
embeds: z.array(zEmbedInput).optional(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue