diff --git a/backend/src/plugins/Logs/types.ts b/backend/src/plugins/Logs/types.ts index c952349d..02a25fd0 100644 --- a/backend/src/plugins/Logs/types.ts +++ b/backend/src/plugins/Logs/types.ts @@ -9,7 +9,6 @@ import { RegExpRunner } from "../../RegExpRunner"; import { tMessageContent, tNullable } from "../../utils"; import { TRegex } from "../../validatorUtils"; import { LogType } from "../../data/LogType"; -import { GuildMember } from "discord.js"; import { TemplateSafeCase, TemplateSafeChannel, @@ -23,15 +22,13 @@ import { TemplateSafeUnknownUser, TemplateSafeUser, } from "../../utils/templateSafeObjects"; -import { - TemplateSafeValue, - TemplateSafeValueContainer, - TypedTemplateSafeValueContainer, -} from "../../templateFormatter"; +import { MessageOptions } from "child_process"; export const tLogFormats = t.record(t.string, t.union([t.string, tMessageContent])); export type TLogFormats = t.TypeOf; +export type ParsedMessageType = MessageOptions | string; + const LogChannel = t.partial({ include: t.array(t.string), exclude: t.array(t.string), @@ -85,7 +82,7 @@ export interface LogsPluginType extends BasePluginType { logListener; - batches: Map; + batches: Map; onMessageDeleteFn; onMessageDeleteBulkFn; diff --git a/backend/src/plugins/Logs/util/getLogMessage.ts b/backend/src/plugins/Logs/util/getLogMessage.ts index 81714486..34237f95 100644 --- a/backend/src/plugins/Logs/util/getLogMessage.ts +++ b/backend/src/plugins/Logs/util/getLogMessage.ts @@ -1,4 +1,4 @@ -import { MessageOptions } from "discord.js"; +import { Message, MessageOptions } from "discord.js"; import { GuildPluginData } from "knub"; import { SavedMessage } from "../../../data/entities/SavedMessage"; import { LogType } from "../../../data/LogType"; @@ -19,7 +19,7 @@ import { verboseUserName, } from "../../../utils"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; -import { FORMAT_NO_TIMESTAMP, ILogTypeData, LogsPluginType, TLogChannel } from "../types"; +import { FORMAT_NO_TIMESTAMP, ILogTypeData, LogsPluginType, ParsedMessageType, TLogChannel } from "../types"; import { getTemplateSafeMemberLevel, TemplateSafeMember, @@ -32,7 +32,7 @@ export async function getLogMessage( type: TLogType, data: TypedTemplateSafeValueContainer, opts?: Pick, -): Promise { +): Promise { const config = pluginData.config.get(); const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || ""; if (format === "" || format == null) return null; @@ -116,7 +116,7 @@ export async function getLogMessage( const renderLogString = str => renderTemplate(str, values); - let formatted; + let formatted: ParsedMessageType; try { formatted = typeof format === "string" ? await renderLogString(format) : await renderRecursively(format, renderLogString); diff --git a/backend/src/plugins/Logs/util/log.ts b/backend/src/plugins/Logs/util/log.ts index 45205882..9781e450 100644 --- a/backend/src/plugins/Logs/util/log.ts +++ b/backend/src/plugins/Logs/util/log.ts @@ -1,11 +1,10 @@ import { MessageMentionTypes, Snowflake, TextChannel } from "discord.js"; import { GuildPluginData } from "knub"; -import { SavedMessage } from "../../../data/entities/SavedMessage"; import { allowTimeout } from "../../../RegExpRunner"; import { createChunkedMessage, get, noop } from "../../../utils"; -import { ILogTypeData, LogsPluginType, LogTypeData, TLogChannelMap } from "../types"; +import { ILogTypeData, LogsPluginType, ParsedMessageType, TLogChannelMap } from "../types"; import { getLogMessage } from "./getLogMessage"; -import { TemplateSafeValueContainer, TypedTemplateSafeValueContainer } from "../../../templateFormatter"; +import { TypedTemplateSafeValueContainer } from "../../../templateFormatter"; import { LogType } from "../../../data/LogType"; const excludedUserProps = ["user", "member", "mod"]; @@ -79,8 +78,8 @@ export async function log( } } } - - const message = await getLogMessage(pluginData, type, data, { + // its resolving to "any" without this, idk why + const message: ParsedMessageType | string | null = await getLogMessage(pluginData, type, data, { format: opts.format, include_embed_timestamp: opts.include_embed_timestamp, timestamp_format: opts.timestamp_format, @@ -88,10 +87,10 @@ export async function log( if (message) { // For non-string log messages (i.e. embeds) batching or chunking is not possible, so send them immediately - if (typeof message !== "string") { + /*if (typeof message !== "string") { await channel.send(message).catch(noop); return; - } + }*/ // Default to batched unless explicitly disabled const batched = opts.batched ?? true; @@ -113,7 +112,12 @@ export async function log( pluginData.state.batches.get(channel.id)!.push(message); } else { // If we're not batching log messages, just send them immediately - await createChunkedMessage(channel, message, { parse }).catch(noop); + if (typeof message === "string") { + await createChunkedMessage(channel, message, { parse }).catch(noop); + } else { + // why is TS being weird here with the type? + await channel.send({ embeds: message.embeds, allowedMentions: { parse } }); + } } } }