aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/index.ts2
-rw-r--r--src/plugins/messageLogger/index.tsx60
2 files changed, 57 insertions, 5 deletions
diff --git a/src/plugins/index.ts b/src/plugins/index.ts
index 268e200..68a76cb 100644
--- a/src/plugins/index.ts
+++ b/src/plugins/index.ts
@@ -21,7 +21,7 @@ import Plugins from "~plugins";
import { registerCommand, unregisterCommand } from "../api/Commands";
import { Settings } from "../api/settings";
import { traceFunction } from "../debug/Tracer";
-import Logger from "../utils/logger";
+import Logger from "../utils/Logger";
import { Patch, Plugin } from "../utils/types";
const logger = new Logger("PluginManager", "#a6d189");
diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx
index 476d092..7b6bf56 100644
--- a/src/plugins/messageLogger/index.tsx
+++ b/src/plugins/messageLogger/index.tsx
@@ -19,9 +19,11 @@
import { Settings } from "../../api/settings";
import ErrorBoundary from "../../components/ErrorBoundary";
import { Devs } from "../../utils/constants";
+import Logger from "../../utils/Logger";
import { lazyWebpack } from "../../utils/misc";
import definePlugin, { OptionType } from "../../utils/types";
import { filters } from "../../webpack";
+import { Parser, UserStore } from "../../webpack/common";
function addDeleteStyleClass() {
if (Settings.plugins.MessageLogger.deleteStyle === "text") {
@@ -36,7 +38,7 @@ function addDeleteStyleClass() {
export default definePlugin({
name: "MessageLogger",
description: "Temporarily logs deleted and edited messages.",
- authors: [Devs.rushii],
+ authors: [Devs.rushii, Devs.Ven],
timestampModule: null as any,
moment: null as Function | null,
@@ -49,6 +51,10 @@ export default definePlugin({
color: #f04747;
}
+ .messageLogger-deleted [class^="buttons"] {
+ display: none;
+ }
+
.messageLogger-deleted-attachment {
filter: grayscale(1);
}
@@ -93,7 +99,7 @@ export default definePlugin({
return (
<ErrorBoundary noop>
<div className="messageLogger-edited">
- {edit.content}
+ {Parser.parse(edit.content)}
<Timestamp
timestamp={edit.timestamp}
isEdited={true}
@@ -123,7 +129,53 @@ export default definePlugin({
{ label: "Red overlay", value: "overlay" }
],
onChange: () => addDeleteStyleClass()
+ },
+ ignoreBots: {
+ type: OptionType.BOOLEAN,
+ description: "Whether to ignore messages by bots",
+ default: false
+ },
+ ignoreSelf: {
+ type: OptionType.BOOLEAN,
+ description: "Whether to ignore messages by yourself",
+ default: false
+ }
+ },
+
+ handleDelete(cache: any, data: { ids: string[], id: string; }, isBulk: boolean) {
+ try {
+ if (cache == null || (!isBulk && !cache.has(data.id))) return cache;
+
+ const { ignoreBots, ignoreSelf } = Settings.plugins.MessageLogger;
+ const myId = UserStore.getCurrentUser().id;
+
+ function mutate(id: string) {
+ const msg = cache.get(id);
+ if (!msg) return;
+
+ const EPHEMERAL = 64;
+ const shouldIgnore = (msg.flags & EPHEMERAL) === EPHEMERAL ||
+ ignoreBots && msg.author?.bot ||
+ ignoreSelf && msg.author?.id === myId;
+
+ if (shouldIgnore) {
+ cache = cache.remove(id);
+ } else {
+ cache = cache.update(id, m => m
+ .set("deleted", true)
+ .set("attachments", m.attachments.map(a => (a.deleted = true, a))));
+ }
+ }
+
+ if (isBulk) {
+ data.ids.forEach(mutate);
+ } else {
+ mutate(data.id);
+ }
+ } catch (e) {
+ new Logger("MessageLogger").error("Error during handleDelete", e);
}
+ return cache;
},
// Based on canary 9ab8626bcebceaea6da570b9c586172d02b9c996
@@ -139,7 +191,7 @@ export default definePlugin({
replace:
"MESSAGE_DELETE:function($1){" +
" var cache = $2getOrCreate($1.channelId);" +
- " cache = cache.update($1.id,m=>m.set('deleted', true).set('attachments', m.attachments.map(a => (a.deleted = true, a))));" +
+ " cache = Vencord.Plugins.plugins.MessageLogger.handleDelete(cache, $1, false);" +
" $2commit(cache);" +
"},"
},
@@ -149,7 +201,7 @@ export default definePlugin({
replace:
"MESSAGE_DELETE_BULK:function($1){" +
" var cache = $2getOrCreate($1.channelId);" +
- " cache = $1.ids.reduce((pv,cv) => pv.update(cv, m => m.set('deleted', true).set('attachments', m.attachments.map(a => (a.deleted = true, a)))), cache);" +
+ " cache = Vencord.Plugins.plugins.MessageLogger.handleDelete(cache, $1, true);" +
" $2commit(cache);" +
"},"
},