mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-23 01:25:02 +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 { tMessageContent, tNullable } from "../../utils";
|
||||||
import { TRegex } from "../../validatorUtils";
|
import { TRegex } from "../../validatorUtils";
|
||||||
import { LogType } from "../../data/LogType";
|
import { LogType } from "../../data/LogType";
|
||||||
import { GuildMember } from "discord.js";
|
|
||||||
import {
|
import {
|
||||||
TemplateSafeCase,
|
TemplateSafeCase,
|
||||||
TemplateSafeChannel,
|
TemplateSafeChannel,
|
||||||
|
@ -23,15 +22,13 @@ import {
|
||||||
TemplateSafeUnknownUser,
|
TemplateSafeUnknownUser,
|
||||||
TemplateSafeUser,
|
TemplateSafeUser,
|
||||||
} from "../../utils/templateSafeObjects";
|
} from "../../utils/templateSafeObjects";
|
||||||
import {
|
import { MessageOptions } from "child_process";
|
||||||
TemplateSafeValue,
|
|
||||||
TemplateSafeValueContainer,
|
|
||||||
TypedTemplateSafeValueContainer,
|
|
||||||
} from "../../templateFormatter";
|
|
||||||
|
|
||||||
export const tLogFormats = t.record(t.string, t.union([t.string, tMessageContent]));
|
export const tLogFormats = t.record(t.string, t.union([t.string, tMessageContent]));
|
||||||
export type TLogFormats = t.TypeOf<typeof tLogFormats>;
|
export type TLogFormats = t.TypeOf<typeof tLogFormats>;
|
||||||
|
|
||||||
|
export type ParsedMessageType = MessageOptions | string;
|
||||||
|
|
||||||
const LogChannel = t.partial({
|
const LogChannel = t.partial({
|
||||||
include: t.array(t.string),
|
include: t.array(t.string),
|
||||||
exclude: t.array(t.string),
|
exclude: t.array(t.string),
|
||||||
|
@ -85,7 +82,7 @@ export interface LogsPluginType extends BasePluginType {
|
||||||
|
|
||||||
logListener;
|
logListener;
|
||||||
|
|
||||||
batches: Map<string, string[]>;
|
batches: Map<string, ParsedMessageType[]>;
|
||||||
|
|
||||||
onMessageDeleteFn;
|
onMessageDeleteFn;
|
||||||
onMessageDeleteBulkFn;
|
onMessageDeleteBulkFn;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { MessageOptions } from "discord.js";
|
import { Message, MessageOptions } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
|
@ -19,7 +19,7 @@ import {
|
||||||
verboseUserName,
|
verboseUserName,
|
||||||
} from "../../../utils";
|
} from "../../../utils";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
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 {
|
import {
|
||||||
getTemplateSafeMemberLevel,
|
getTemplateSafeMemberLevel,
|
||||||
TemplateSafeMember,
|
TemplateSafeMember,
|
||||||
|
@ -32,7 +32,7 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
|
||||||
type: TLogType,
|
type: TLogType,
|
||||||
data: TypedTemplateSafeValueContainer<ILogTypeData[TLogType]>,
|
data: TypedTemplateSafeValueContainer<ILogTypeData[TLogType]>,
|
||||||
opts?: Pick<TLogChannel, "format" | "timestamp_format" | "include_embed_timestamp">,
|
opts?: Pick<TLogChannel, "format" | "timestamp_format" | "include_embed_timestamp">,
|
||||||
): Promise<MessageOptions | null> {
|
): Promise<ParsedMessageType | null> {
|
||||||
const config = pluginData.config.get();
|
const config = pluginData.config.get();
|
||||||
const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || "";
|
const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || "";
|
||||||
if (format === "" || format == null) return null;
|
if (format === "" || format == null) return null;
|
||||||
|
@ -116,7 +116,7 @@ export async function getLogMessage<TLogType extends keyof ILogTypeData>(
|
||||||
|
|
||||||
const renderLogString = str => renderTemplate(str, values);
|
const renderLogString = str => renderTemplate(str, values);
|
||||||
|
|
||||||
let formatted;
|
let formatted: ParsedMessageType;
|
||||||
try {
|
try {
|
||||||
formatted =
|
formatted =
|
||||||
typeof format === "string" ? await renderLogString(format) : await renderRecursively(format, renderLogString);
|
typeof format === "string" ? await renderLogString(format) : await renderRecursively(format, renderLogString);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import { MessageMentionTypes, Snowflake, TextChannel } from "discord.js";
|
import { MessageMentionTypes, Snowflake, TextChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
|
||||||
import { allowTimeout } from "../../../RegExpRunner";
|
import { allowTimeout } from "../../../RegExpRunner";
|
||||||
import { createChunkedMessage, get, noop } from "../../../utils";
|
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 { getLogMessage } from "./getLogMessage";
|
||||||
import { TemplateSafeValueContainer, TypedTemplateSafeValueContainer } from "../../../templateFormatter";
|
import { TypedTemplateSafeValueContainer } from "../../../templateFormatter";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
|
|
||||||
const excludedUserProps = ["user", "member", "mod"];
|
const excludedUserProps = ["user", "member", "mod"];
|
||||||
|
@ -79,8 +78,8 @@ export async function log<TLogType extends keyof ILogTypeData>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// its resolving to "any" without this, idk why
|
||||||
const message = await getLogMessage(pluginData, type, data, {
|
const message: ParsedMessageType | string | null = await getLogMessage(pluginData, type, data, {
|
||||||
format: opts.format,
|
format: opts.format,
|
||||||
include_embed_timestamp: opts.include_embed_timestamp,
|
include_embed_timestamp: opts.include_embed_timestamp,
|
||||||
timestamp_format: opts.timestamp_format,
|
timestamp_format: opts.timestamp_format,
|
||||||
|
@ -88,10 +87,10 @@ export async function log<TLogType extends keyof ILogTypeData>(
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
// For non-string log messages (i.e. embeds) batching or chunking is not possible, so send them immediately
|
// 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);
|
await channel.send(message).catch(noop);
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Default to batched unless explicitly disabled
|
// Default to batched unless explicitly disabled
|
||||||
const batched = opts.batched ?? true;
|
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);
|
pluginData.state.batches.get(channel.id)!.push(message);
|
||||||
} else {
|
} else {
|
||||||
// If we're not batching log messages, just send them immediately
|
// 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