messageLogger: ignore messages deleted within the next n milliseconds

This commit is contained in:
Meadowsys 2024-02-22 20:33:19 -08:00
parent 7b96071643
commit b7f301aff8
No known key found for this signature in database
GPG key ID: 9E9BB6D25186E719
2 changed files with 16 additions and 4 deletions

View file

@ -26,7 +26,7 @@ import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { ChannelStore, FluxDispatcher, i18n, Menu, Parser, Timestamp, UserStore } from "@webpack/common"; import { ChannelStore, FluxDispatcher, i18n, Menu, Parser, SnowflakeUtils, Timestamp, UserStore } from "@webpack/common";
import overlayStyle from "./deleteStyleOverlay.css?managed"; import overlayStyle from "./deleteStyleOverlay.css?managed";
import textStyle from "./deleteStyleText.css?managed"; import textStyle from "./deleteStyleText.css?managed";
@ -92,7 +92,7 @@ const patchMessageContextMenu: NavContextMenuPatchCallback = (children, props) =
export default definePlugin({ export default definePlugin({
name: "MessageLogger", name: "MessageLogger",
description: "Temporarily logs deleted and edited messages.", description: "Temporarily logs deleted and edited messages.",
authors: [Devs.rushii, Devs.Ven, Devs.AutumnVN], authors: [Devs.rushii, Devs.Ven, Devs.AutumnVN, Devs.meadowsys],
start() { start() {
addDeleteStyle(); addDeleteStyle();
@ -163,6 +163,11 @@ export default definePlugin({
description: "Comma-separated list of guild IDs to ignore", description: "Comma-separated list of guild IDs to ignore",
default: "" default: ""
}, },
ignoreQuickDelete: {
type: OptionType.NUMBER,
description: "Ignore deleted messages if they were deleted quicker than this many milliseconds",
default: 0
},
}, },
handleDelete(cache: any, data: { ids: string[], id: string; mlDeleted?: boolean; }, isBulk: boolean) { handleDelete(cache: any, data: { ids: string[], id: string; mlDeleted?: boolean; }, isBulk: boolean) {
@ -199,15 +204,18 @@ export default definePlugin({
}, },
shouldIgnore(message: any) { shouldIgnore(message: any) {
const { ignoreBots, ignoreSelf, ignoreUsers, ignoreChannels, ignoreGuilds } = Settings.plugins.MessageLogger; const { ignoreBots, ignoreSelf, ignoreUsers, ignoreChannels, ignoreGuilds, ignoreQuickDelete } = Settings.plugins.MessageLogger;
const myId = UserStore.getCurrentUser().id; const myId = UserStore.getCurrentUser().id;
const timeNow = Date.now();
const timeMessage = SnowflakeUtils.extractTimestamp(message.id);
return ignoreBots && message.author?.bot || return ignoreBots && message.author?.bot ||
ignoreSelf && message.author?.id === myId || ignoreSelf && message.author?.id === myId ||
ignoreUsers.includes(message.author?.id) || ignoreUsers.includes(message.author?.id) ||
ignoreChannels.includes(message.channel_id) || ignoreChannels.includes(message.channel_id) ||
ignoreChannels.includes(ChannelStore.getChannel(message.channel_id)?.parent_id) || ignoreChannels.includes(ChannelStore.getChannel(message.channel_id)?.parent_id) ||
ignoreGuilds.includes(ChannelStore.getChannel(message.channel_id)?.guild_id); ignoreGuilds.includes(ChannelStore.getChannel(message.channel_id)?.guild_id) ||
timeNow - timeMessage <= ignoreQuickDelete;
}, },
// Based on canary 63b8f1b4f2025213c5cf62f0966625bee3d53136 // Based on canary 63b8f1b4f2025213c5cf62f0966625bee3d53136

View file

@ -410,6 +410,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
coolelectronics: { coolelectronics: {
name: "coolelectronics", name: "coolelectronics",
id: 696392247205298207n, id: 696392247205298207n,
},
meadowsys: {
name: "meadowsys",
id: 379800645571575810n
} }
} satisfies Record<string, Dev>); } satisfies Record<string, Dev>);