diff --git a/backend/src/plugins/Logs/types.ts b/backend/src/plugins/Logs/types.ts index fd51da08..2eb8043a 100644 --- a/backend/src/plugins/Logs/types.ts +++ b/backend/src/plugins/Logs/types.ts @@ -5,7 +5,10 @@ import { GuildLogs } from "src/data/GuildLogs"; import { GuildSavedMessages } from "src/data/GuildSavedMessages"; import { GuildArchives } from "src/data/GuildArchives"; import { GuildCases } from "src/data/GuildCases"; -import { tMessageContent } from "../../utils"; +import { tMessageContent, tNullable } from "../../utils"; + +export const tLogFormats = t.record(t.string, t.union([t.string, tMessageContent])); +export type TLogFormats = t.TypeOf; const LogChannel = t.partial({ include: t.array(t.string), @@ -15,22 +18,21 @@ const LogChannel = t.partial({ excluded_users: t.array(t.string), excluded_message_regexes: t.array(TSafeRegex), excluded_channels: t.array(t.string), + format: tNullable(tLogFormats), }); export type TLogChannel = t.TypeOf; const LogChannelMap = t.record(t.string, LogChannel); export type TLogChannelMap = t.TypeOf; -const tLogFormats = t.intersection([ - t.record(t.string, t.union([t.string, tMessageContent])), - t.type({ - timestamp: t.string, - }), -]); - export const ConfigSchema = t.type({ channels: LogChannelMap, - format: tLogFormats, + format: t.intersection([ + tLogFormats, + t.type({ + timestamp: t.string, + }), + ]), ping_user: t.boolean, }); export type TConfigSchema = t.TypeOf; diff --git a/backend/src/plugins/Logs/util/getLogMessage.ts b/backend/src/plugins/Logs/util/getLogMessage.ts index b84b9df7..d926db79 100644 --- a/backend/src/plugins/Logs/util/getLogMessage.ts +++ b/backend/src/plugins/Logs/util/getLogMessage.ts @@ -1,5 +1,5 @@ import { PluginData } from "knub"; -import { LogsPluginType } from "../types"; +import { LogsPluginType, TLogFormats } from "../types"; import { LogType } from "src/data/LogType"; import { verboseUserMention, @@ -14,9 +14,14 @@ import { renderTemplate, TemplateParseError } from "src/templateFormatter"; import { logger } from "src/logger"; import moment from "moment-timezone"; -export async function getLogMessage(pluginData: PluginData, type: LogType, data: any): Promise { +export async function getLogMessage( + pluginData: PluginData, + type: LogType, + data: any, + formats?: TLogFormats, +): Promise { const config = pluginData.config.get(); - const format = config.format[LogType[type]] || ""; + const format = (formats && formats[LogType[type]]) || config.format[LogType[type]] || ""; if (format === "") return; const values = { diff --git a/backend/src/plugins/Logs/util/log.ts b/backend/src/plugins/Logs/util/log.ts index 169c4ad6..37d779d0 100644 --- a/backend/src/plugins/Logs/util/log.ts +++ b/backend/src/plugins/Logs/util/log.ts @@ -57,7 +57,7 @@ export async function log(pluginData: PluginData, type: LogType, } } - const message = await getLogMessage(pluginData, type, data); + const message = await getLogMessage(pluginData, type, data, opts.format); if (message) { // For non-string log messages (i.e. embeds) batching or chunking is not possible, so send them immediately if (typeof message !== "string") {