mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-21 16:55:03 +00:00
initial (((idk what im doing)))
This commit is contained in:
parent
7f2731262d
commit
673bd6ea76
3 changed files with 20 additions and 19 deletions
|
@ -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<typeof tLogFormats>;
|
||||
|
||||
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<string, string[]>;
|
||||
batches: Map<string, ParsedMessageType[]>;
|
||||
|
||||
onMessageDeleteFn;
|
||||
onMessageDeleteBulkFn;
|
||||
|
|
|
@ -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<TLogType extends keyof ILogTypeData>(
|
|||
type: TLogType,
|
||||
data: TypedTemplateSafeValueContainer<ILogTypeData[TLogType]>,
|
||||
opts?: Pick<TLogChannel, "format" | "timestamp_format" | "include_embed_timestamp">,
|
||||
): Promise<MessageOptions | null> {
|
||||
): Promise<ParsedMessageType | null> {
|
||||
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<TLogType extends keyof ILogTypeData>(
|
|||
|
||||
const renderLogString = str => renderTemplate(str, values);
|
||||
|
||||
let formatted;
|
||||
let formatted: ParsedMessageType;
|
||||
try {
|
||||
formatted =
|
||||
typeof format === "string" ? await renderLogString(format) : await renderRecursively(format, renderLogString);
|
||||
|
|
|
@ -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<TLogType extends keyof ILogTypeData>(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<TLogType extends keyof ILogTypeData>(
|
|||
|
||||
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<TLogType extends keyof ILogTypeData>(
|
|||
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 } });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue