GoonCord/src/core/plugins/nodelete/index.ts

77 lines
2.1 KiB
TypeScript
Raw Normal View History

2026-04-02 19:35:57 +02:00
// src/core/plugins/NoDelete/index.ts
2026-04-02 19:30:06 +02:00
import { defineCorePlugin } from "..";
2026-04-02 19:35:57 +02:00
import { findByStoreName } from "@metro";
import { before } from "@lib/api/patcher";
import { logger } from "@lib/utils/logger";
import { FluxDispatcher } from "@metro/common";
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
type PatchCleanupFn = () => void;
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
let patches: PatchCleanupFn[] = [];
let MessageStore: any = null;
let deleteable: string[] = [];
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
function patchDispatcher(): PatchCleanupFn {
return before("dispatch", FluxDispatcher, (args: any[]) => {
try {
if (!MessageStore) MessageStore = findByStoreName("MessageStore");
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
const event = args[0];
if (!event || event?.type !== "MESSAGE_DELETE") return;
if (!event?.id || !event?.channelId) return;
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
if (deleteable.includes(event.id)) {
deleteable.splice(deleteable.indexOf(event.id), 1);
return;
}
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
deleteable.push(event.id);
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
args[0] = {
type: "MESSAGE_EDIT_FAILED_AUTOMOD",
messageData: {
type: 1,
message: {
channelId: event.channelId,
messageId: event.id,
},
},
errorResponseBody: {
code: 200000,
message: "[deleted]",
},
};
} catch (e) {
logger.error("NoDelete: dispatcher patch failed", e);
}
});
}
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
export default defineCorePlugin({
manifest: {
id: "bunny.nodelete",
version: "1.0.0",
type: "plugin",
spec: 3,
main: "",
display: {
name: "NoDelete",
description: "Prevents messages from being deleted from your view",
authors: [{ name: "meqativ" }],
},
},
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
start() {
patches = [patchDispatcher()].filter(Boolean);
logger.log("NoDelete: Enabled");
},
2026-04-02 19:29:07 +02:00
2026-04-02 19:35:57 +02:00
stop() {
patches.forEach((p) => p?.());
patches = [];
deleteable = [];
MessageStore = null;
logger.log("NoDelete: Disabled");
},
});