mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
logs: allow per-log-channel log formats
This commit is contained in:
parent
8b22ce267d
commit
28de8a592b
3 changed files with 20 additions and 13 deletions
|
@ -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<typeof tLogFormats>;
|
||||
|
||||
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<typeof LogChannel>;
|
||||
|
||||
const LogChannelMap = t.record(t.string, LogChannel);
|
||||
export type TLogChannelMap = t.TypeOf<typeof LogChannelMap>;
|
||||
|
||||
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<typeof ConfigSchema>;
|
||||
|
|
|
@ -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<LogsPluginType>, type: LogType, data: any): Promise<string> {
|
||||
export async function getLogMessage(
|
||||
pluginData: PluginData<LogsPluginType>,
|
||||
type: LogType,
|
||||
data: any,
|
||||
formats?: TLogFormats,
|
||||
): Promise<string> {
|
||||
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 = {
|
||||
|
|
|
@ -57,7 +57,7 @@ export async function log(pluginData: PluginData<LogsPluginType>, 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") {
|
||||
|
|
Loading…
Add table
Reference in a new issue