MessageLogger: fixes + ignoreSelf & ignoreBots option (#213)

This commit is contained in:
Ven 2022-11-14 16:22:50 +01:00 committed by GitHub
parent 4642b54260
commit a96f8a89f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 66 additions and 13 deletions

View file

@ -18,7 +18,7 @@
import type { Channel, Message } from "discord-types/general"; import type { Channel, Message } from "discord-types/general";
import Logger from "../utils/logger"; import Logger from "../utils/Logger";
import { MessageStore } from "../webpack/common"; import { MessageStore } from "../webpack/common";
const MessageEventsLogger = new Logger("MessageEvents", "#e5c890"); const MessageEventsLogger = new Logger("MessageEvents", "#e5c890");

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import Logger from "../utils/logger"; import Logger from "../utils/Logger";
import { LazyComponent } from "../utils/misc"; import { LazyComponent } from "../utils/misc";
import { Margins, React } from "../webpack/common"; import { Margins, React } from "../webpack/common";
import { ErrorCard } from "./ErrorCard"; import { ErrorCard } from "./ErrorCard";

View file

@ -22,7 +22,7 @@ import { showNotice } from "../../api/Notices";
import { Settings, useSettings } from "../../api/settings"; import { Settings, useSettings } from "../../api/settings";
import { startDependenciesRecursive, startPlugin, stopPlugin } from "../../plugins"; import { startDependenciesRecursive, startPlugin, stopPlugin } from "../../plugins";
import { ChangeList } from "../../utils/ChangeList"; import { ChangeList } from "../../utils/ChangeList";
import Logger from "../../utils/logger"; import Logger from "../../utils/Logger";
import { classes, LazyComponent, lazyWebpack } from "../../utils/misc"; import { classes, LazyComponent, lazyWebpack } from "../../utils/misc";
import { openModalLazy } from "../../utils/modal"; import { openModalLazy } from "../../utils/modal";
import { Plugin } from "../../utils/types"; import { Plugin } from "../../utils/types";

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import Logger from "../utils/logger"; import Logger from "../utils/Logger";
if (IS_DEV) { if (IS_DEV) {
var traces = {} as Record<string, [number, any[]]>; var traces = {} as Record<string, [number, any[]]>;

View file

@ -21,7 +21,7 @@ import Plugins from "~plugins";
import { registerCommand, unregisterCommand } from "../api/Commands"; import { registerCommand, unregisterCommand } from "../api/Commands";
import { Settings } from "../api/settings"; import { Settings } from "../api/settings";
import { traceFunction } from "../debug/Tracer"; import { traceFunction } from "../debug/Tracer";
import Logger from "../utils/logger"; import Logger from "../utils/Logger";
import { Patch, Plugin } from "../utils/types"; import { Patch, Plugin } from "../utils/types";
const logger = new Logger("PluginManager", "#a6d189"); const logger = new Logger("PluginManager", "#a6d189");

View file

@ -19,9 +19,11 @@
import { Settings } from "../../api/settings"; import { Settings } from "../../api/settings";
import ErrorBoundary from "../../components/ErrorBoundary"; import ErrorBoundary from "../../components/ErrorBoundary";
import { Devs } from "../../utils/constants"; import { Devs } from "../../utils/constants";
import Logger from "../../utils/Logger";
import { lazyWebpack } from "../../utils/misc"; import { lazyWebpack } from "../../utils/misc";
import definePlugin, { OptionType } from "../../utils/types"; import definePlugin, { OptionType } from "../../utils/types";
import { filters } from "../../webpack"; import { filters } from "../../webpack";
import { Parser, UserStore } from "../../webpack/common";
function addDeleteStyleClass() { function addDeleteStyleClass() {
if (Settings.plugins.MessageLogger.deleteStyle === "text") { if (Settings.plugins.MessageLogger.deleteStyle === "text") {
@ -36,7 +38,7 @@ function addDeleteStyleClass() {
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], authors: [Devs.rushii, Devs.Ven],
timestampModule: null as any, timestampModule: null as any,
moment: null as Function | null, moment: null as Function | null,
@ -49,6 +51,10 @@ export default definePlugin({
color: #f04747; color: #f04747;
} }
.messageLogger-deleted [class^="buttons"] {
display: none;
}
.messageLogger-deleted-attachment { .messageLogger-deleted-attachment {
filter: grayscale(1); filter: grayscale(1);
} }
@ -93,7 +99,7 @@ export default definePlugin({
return ( return (
<ErrorBoundary noop> <ErrorBoundary noop>
<div className="messageLogger-edited"> <div className="messageLogger-edited">
{edit.content} {Parser.parse(edit.content)}
<Timestamp <Timestamp
timestamp={edit.timestamp} timestamp={edit.timestamp}
isEdited={true} isEdited={true}
@ -123,9 +129,55 @@ export default definePlugin({
{ label: "Red overlay", value: "overlay" } { label: "Red overlay", value: "overlay" }
], ],
onChange: () => addDeleteStyleClass() 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 // Based on canary 9ab8626bcebceaea6da570b9c586172d02b9c996
patches: [ patches: [
{ {
@ -139,7 +191,7 @@ export default definePlugin({
replace: replace:
"MESSAGE_DELETE:function($1){" + "MESSAGE_DELETE:function($1){" +
" var cache = $2getOrCreate($1.channelId);" + " 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);" + " $2commit(cache);" +
"}," "},"
}, },
@ -149,7 +201,7 @@ export default definePlugin({
replace: replace:
"MESSAGE_DELETE_BULK:function($1){" + "MESSAGE_DELETE_BULK:function($1){" +
" var cache = $2getOrCreate($1.channelId);" + " 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);" + " $2commit(cache);" +
"}," "},"
}, },

View file

@ -21,9 +21,10 @@ export * as Constants from "./constants";
export * from "./debounce"; export * from "./debounce";
export * as Discord from "./discord"; export * as Discord from "./discord";
export { default as IpcEvents } from "./IpcEvents"; export { default as IpcEvents } from "./IpcEvents";
export { default as Logger } from "./logger"; export { default as Logger } from "./Logger";
export * from "./misc"; export * from "./misc";
export * as Modals from "./modal"; export * as Modals from "./modal";
export * from "./onceDefined"; export * from "./onceDefined";
export * from "./proxyLazy"; export * from "./proxyLazy";
export * from "./Queue"; export * from "./Queue";

View file

@ -19,7 +19,7 @@
import gitHash from "~git-hash"; import gitHash from "~git-hash";
import IpcEvents from "./IpcEvents"; import IpcEvents from "./IpcEvents";
import Logger from "./logger"; import Logger from "./Logger";
import { IpcRes } from "./types"; import { IpcRes } from "./types";
export const UpdateLogger = new Logger("Updater", "white"); export const UpdateLogger = new Logger("Updater", "white");

View file

@ -17,7 +17,7 @@
*/ */
import { WEBPACK_CHUNK } from "../utils/constants"; import { WEBPACK_CHUNK } from "../utils/constants";
import Logger from "../utils/logger"; import Logger from "../utils/Logger";
import { _initWebpack } from "."; import { _initWebpack } from ".";
let webpackChunk: any[]; let webpackChunk: any[];

View file

@ -19,7 +19,7 @@
import type { WebpackInstance } from "discord-types/other"; import type { WebpackInstance } from "discord-types/other";
import { traceFunction } from "../debug/Tracer"; import { traceFunction } from "../debug/Tracer";
import Logger from "../utils/logger"; import Logger from "../utils/Logger";
import { proxyLazy } from "../utils/proxyLazy"; import { proxyLazy } from "../utils/proxyLazy";
const logger = new Logger("Webpack"); const logger = new Logger("Webpack");