More rework progress, mostly done up to ModActions
This commit is contained in:
parent
52839cc9f3
commit
57893e7f76
38 changed files with 199 additions and 241 deletions
|
@ -12,15 +12,15 @@ import {
|
|||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { renderTemplate, TemplateParseError } from "../../../templateFormatter";
|
||||
import { logger } from "../../../logger";
|
||||
import moment from "moment-timezone";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageOptions } from "discord.js";
|
||||
|
||||
export async function getLogMessage(
|
||||
pluginData: GuildPluginData<LogsPluginType>,
|
||||
type: LogType,
|
||||
data: any,
|
||||
opts?: Pick<TLogChannel, "format" | "timestamp_format" | "include_embed_timestamp">,
|
||||
): Promise<MessageContent | null> {
|
||||
): Promise<MessageOptions | null> {
|
||||
const config = pluginData.config.get();
|
||||
const format = opts?.format?.[LogType[type]] || config.format[LogType[type]] || "";
|
||||
if (format === "" || format == null) return null;
|
||||
|
|
|
@ -6,6 +6,7 @@ import { createChunkedMessage, get, noop } from "../../../utils";
|
|||
import { getLogMessage } from "./getLogMessage";
|
||||
import { allowTimeout } from "../../../RegExpRunner";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { MessageMentionTypes, TextChannel } from "discord.js";
|
||||
|
||||
const excludedUserProps = ["user", "member", "mod"];
|
||||
const excludedRoleProps = ["message.member.roles", "member.roles"];
|
||||
|
@ -46,8 +47,8 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
for (const value of Object.values(data || {})) {
|
||||
if (value instanceof SavedMessage) {
|
||||
const member = pluginData.guild.members.cache.get(value.user_id);
|
||||
for (const role of member?.roles || []) {
|
||||
if (opts.excluded_roles.includes(role)) {
|
||||
for (const role of member?.roles.cache || []) {
|
||||
if (opts.excluded_roles.includes(role[0])) {
|
||||
continue logChannelLoop;
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: 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") {
|
||||
await channel.createMessage(message).catch(noop);
|
||||
await channel.send(message).catch(noop);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -136,6 +137,7 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
const batched = opts.batched ?? true;
|
||||
const batchTime = opts.batch_time ?? 1000;
|
||||
const cfg = pluginData.config.get();
|
||||
const parse: MessageMentionTypes[] | undefined = cfg.allow_user_mentions ? ["users"] : undefined;
|
||||
|
||||
if (batched) {
|
||||
// If we're batching log messages, gather all log messages within the set batch_time into a single message
|
||||
|
@ -144,14 +146,14 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, type: Log
|
|||
setTimeout(async () => {
|
||||
const batchedMessage = pluginData.state.batches.get(channel.id)!.join("\n");
|
||||
pluginData.state.batches.delete(channel.id);
|
||||
createChunkedMessage(channel, batchedMessage, { users: cfg.allow_user_mentions }).catch(noop);
|
||||
createChunkedMessage(channel, batchedMessage, { parse }).catch(noop);
|
||||
}, batchTime);
|
||||
}
|
||||
|
||||
pluginData.state.batches.get(channel.id)!.push(message);
|
||||
} else {
|
||||
// If we're not batching log messages, just send them immediately
|
||||
await createChunkedMessage(channel, message, { users: cfg.allow_user_mentions }).catch(noop);
|
||||
await createChunkedMessage(channel, message, { parse }).catch(noop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import moment from "moment-timezone";
|
|||
import { GuildPluginData } from "knub";
|
||||
import { FORMAT_NO_TIMESTAMP, LogsPluginType } from "../types";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageAttachment } from "discord.js";
|
||||
|
||||
export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType>, savedMessage: SavedMessage) {
|
||||
const user = await resolveUser(pluginData.client, savedMessage.user_id);
|
||||
|
@ -14,7 +15,7 @@ export async function onMessageDelete(pluginData: GuildPluginData<LogsPluginType
|
|||
if (user) {
|
||||
// Replace attachment URLs with media URLs
|
||||
if (savedMessage.data.attachments) {
|
||||
for (const attachment of savedMessage.data.attachments as Attachment[]) {
|
||||
for (const attachment of savedMessage.data.attachments as MessageAttachment[]) {
|
||||
attachment.url = useMediaUrls(attachment.url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import { SavedMessage } from "../../../data/entities/SavedMessage";
|
|||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars, resolveUser } from "../../../utils";
|
||||
import cloneDeep from "lodash.clonedeep";
|
||||
import { MessageEmbed } from "discord.js";
|
||||
|
||||
export async function onMessageUpdate(
|
||||
pluginData: GuildPluginData<LogsPluginType>,
|
||||
|
@ -14,13 +15,13 @@ export async function onMessageUpdate(
|
|||
// To log a message update, either the message content or a rich embed has to change
|
||||
let logUpdate = false;
|
||||
|
||||
const oldEmbedsToCompare = ((oldSavedMessage.data.embeds || []) as Embed[])
|
||||
const oldEmbedsToCompare = ((oldSavedMessage.data.embeds || []) as MessageEmbed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as Embed).type === "rich");
|
||||
.filter(e => (e as MessageEmbed).type === "rich");
|
||||
|
||||
const newEmbedsToCompare = ((savedMessage.data.embeds || []) as Embed[])
|
||||
const newEmbedsToCompare = ((savedMessage.data.embeds || []) as MessageEmbed[])
|
||||
.map(e => cloneDeep(e))
|
||||
.filter(e => (e as Embed).type === "rich");
|
||||
.filter(e => (e as MessageEmbed).type === "rich");
|
||||
|
||||
for (const embed of [...oldEmbedsToCompare, ...newEmbedsToCompare]) {
|
||||
if (embed.thumbnail) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue