diff --git a/src/core/plugins/index.ts b/src/core/plugins/index.ts index f558ad5..fde8dac 100644 --- a/src/core/plugins/index.ts +++ b/src/core/plugins/index.ts @@ -11,7 +11,6 @@ export const getCorePlugins = (): Record => ({ "bunny.badges": require("./badges"), "bunny.notrack": { ...require("./notrack"), preenabled: true }, "bunny.messagefix": { ...require("./messagefix") }, - "bunny.messagelogger": { ...require("./messagelogger"), preenabled: true }, "bunny.fixembed": { ...require("./fixembed"), preenabled: true }, "bunny.enhancements": { ...require("./shiggyenhancements"),} }); diff --git a/src/core/plugins/messagelogger/index.jsx b/src/core/plugins/messagelogger/index.jsx deleted file mode 100644 index 1da1e16..0000000 --- a/src/core/plugins/messagelogger/index.jsx +++ /dev/null @@ -1,43 +0,0 @@ -import { defineCorePlugin } from ".."; -import fluxDispatchPatch from "./patches/flux_dispatch"; -import selfEditPatch from "./patches/self_edit"; -import actionsheet from "./patches/actionsheet"; - -export const regexEscaper = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); -export let isEnabled = false; - -const deletedMessageArray = new Map(); -let patches = []; - -export default defineCorePlugin({ - manifest: { - id: "bunny.messagelogger", - version: "1.0.0", - type: "plugin", - spec: 3, - main: "", - display: { - name: "Message Logger", - description: "Port of the popular Revenge/Kettu plugin called Antied.", - authors: [{ name: "ShiggyCord Team, Angelw0lf" }], - }, - }, - - start() { - isEnabled = true; - - // Each patch function is expected to return an unpatch function. - patches = [ - fluxDispatchPatch(deletedMessageArray), - actionsheet(), - selfEditPatch(), - ].filter(Boolean); - }, - - stop() { - isEnabled = false; - - patches.forEach((p) => p && p()); - patches = []; - }, -}); diff --git a/src/core/plugins/messagelogger/patches/actionsheet.jsx b/src/core/plugins/messagelogger/patches/actionsheet.jsx deleted file mode 100644 index 3395b62..0000000 --- a/src/core/plugins/messagelogger/patches/actionsheet.jsx +++ /dev/null @@ -1,139 +0,0 @@ -import { before, after } from "@lib/api/patcher"; -import { findAssetId } from "@lib/api/assets"; -import { findInReactTree } from "@lib/utils"; -import { FluxDispatcher, React } from "@metro/common"; -import { showToast } from "@lib/ui/toasts"; -import { findByProps } from "@metro"; -import { regexEscaper, isEnabled } from ".."; - -const ActionSheet = findByProps("openLazy", "hideActionSheet"); -const MessageStore = findByProps("getMessage", "getMessages"); -const ChannelStore = findByProps("getChannel", "getDMFromUserId"); -const ChannelMessages = findByProps("_channelMessages"); -const { ActionSheetRow } = findByProps("ActionSheetRow"); - -/** @param {any} a */ -function someFunc(a) { - // return a?.props?.label == i18n?.Messages?.MESSAGE_ACTION_REPLY - return a?.props?.label?.toLowerCase?.() == "reply"; -} - -export default () => - before("openLazy", ActionSheet, ([component, args, actionMessage]) => { - if (isEnabled) { - try { - const message = actionMessage?.message; - - if (args !== "MessageLongPressActionSheet" || !message) return; - - component.then((/** @type {any} */ instance) => { - const unpatch = after("default", instance, (_, comp) => { - try { - React.useEffect( - () => () => { - unpatch(); - }, - [], - ); - - const buttons = findInReactTree(comp, (c) => c?.find?.(someFunc)); - if (!buttons) return comp; - - const position = Math.max( - buttons.findIndex(someFunc), - buttons.length - 1, - ); - - let originalMessage = null; - - if (message?.channel_id && message?.id) { - originalMessage = MessageStore.getMessage( - message?.channel_id, - message?.id, - ); - - if (!originalMessage) { - const channel = ChannelMessages.get(message?.channel_id); - originalMessage = channel?.get(message?.id); - } - } - - if (!originalMessage) return comp; - - const escapedBuffer = regexEscaper("`[ EDITED ]`\n\n"); - - const separator = new RegExp(escapedBuffer, "gmi"); - const checkIfBufferExist = separator.test(message.content); - - if (checkIfBufferExist) { - const targetPos = position || 1; - - const actionRow = React.createElement( - ActionSheetRow, - { - label: "Remove Edit History", - subLabel: "Added by Message Logger", - icon: React.createElement(ActionSheetRow.Icon, { - source: findAssetId("ic_edit_24px"), - }), - onPress: () => { - try { - const lats = message?.content?.split(separator); - const targetMessage = lats[lats.length - 1]; - - FluxDispatcher.dispatch({ - type: "MESSAGE_UPDATE", - message: { - ...message, - message_reference: - message?.message_reference || - message?.messageReference || - null, - content: `${targetMessage}`, - guild_id: ChannelStore.getChannel( - originalMessage.channel_id, - ).guild_id, - }, - otherPluginBypass: true, - }); - - ActionSheet.hideActionSheet(); - showToast( - "History Removed", - findAssetId("ic_edit_24px"), - ); - } catch (ex) { - showToast( - "[Message Logger] Failed to remove edit history", - ); - console.error( - "[Message Logger] Error while removing history", - ex, - ); - } - }, - }, - null, - ); - - buttons.splice(targetPos, 0, actionRow); - } - } catch (e) { - showToast( - "[Message Logger] Crash on ActionSheet, check debug log for more info", - ); - console.error( - "[Message Logger] Error > ActionSheet:Component Patch\n", - e, - ); - } - }); - }); - } catch (e) { - showToast( - "[Message Logger] Crash on ActionSheet, check debug log for more info", - ); - console.error("[Message Logger] Error > ActionSheet Patch\n", e); - } - } - }); diff --git a/src/core/plugins/messagelogger/patches/flux_dispatch.js b/src/core/plugins/messagelogger/patches/flux_dispatch.js deleted file mode 100644 index 8c28cec..0000000 --- a/src/core/plugins/messagelogger/patches/flux_dispatch.js +++ /dev/null @@ -1,125 +0,0 @@ -import { before } from "@lib/api/patcher"; -import { findByProps } from "@metro"; -import { showToast } from "@lib/ui/toasts"; -import { FluxDispatcher } from "@metro/common"; - -import { isEnabled } from ".."; - -const ChannelStore = findByProps("getChannel", "getDMFromUserId"); -const ChannelMessages = findByProps("_channelMessages"); -const MessageStore = findByProps("getMessage", "getMessages"); - -export default (deletedMessageArray) => - before("dispatch", FluxDispatcher, (args) => { - if (isEnabled) { - try { - const ev = args[0]; - if (!ev || !ev.type) return; - - /* ========================================================= - MESSAGE_DELETE - ==========================================================*/ - if (ev.type === "MESSAGE_DELETE") { - if (ev.otherPluginBypass) return; - - const orig = ChannelMessages.get(ev.channelId)?.get(ev.id); - if (!orig?.author?.id || !orig.author.username) return; - - // ephemeral message dismiss (from bots) - if ((orig?.author?.bot && orig?.flags == 64) || orig.author.bot) - return; - - // empty message check - if ( - !orig.content && - !orig.attachments?.length && - !orig.embeds?.length - ) - return; - - const entry = deletedMessageArray.get(ev.id); - if (entry?.stage === 2) { - if (deletedMessageArray.size >= 100) { - deletedMessageArray = new Map(); - } - return; // Kill message normally - } - if (entry?.stage === 1) { - // first pass - entry.stage = 2; - return entry.message || args; - } - - const guildId = ChannelStore.getChannel( - orig.channel_id || ev.channelId, - )?.guild_id; - - /* reuse the same object shape every time */ - - ev.message = { - ...orig, - content: orig.content, - channel_id: orig.channel_id || ev.channelId, - guild_id: guildId, - message_reference: - orig?.message_reference || orig?.messageReference || null, - flags: 64, - }; - - ev.type = "MESSAGE_UPDATE"; - ev.channelId = orig.channel_id || ev.channelId; - ev.optimistic = false; - ev.sendMessageOptions = {}; - ev.isPushNotification = false; - - deletedMessageArray.set(ev.id, { message: args, stage: 1 }); - - return args; - } - - /* ========================================================= - MESSAGE_UPDATE - ==========================================================*/ - if (ev.type === "MESSAGE_UPDATE") { - if (ev.otherPluginBypass) return; - const msg = ev.message; - - if (!msg || msg.author?.bot) return; - - const chId = msg.channel_id || ev.channelId; - const id = msg.id || ev.id; - - const orig = - MessageStore.getMessage(chId, id) || - ChannelMessages.get(chId)?.get(id); - - if (!orig?.author?.id || !orig.author.username) return; - - if ( - !orig.content && - !orig.attachments?.length && - !orig.embeds?.length - ) - return; - - if (!msg.content || msg.content === orig.content) return; - - let prefix = "`[ EDITED ]`\n\n"; - - ev.message = { - ...msg, - content: `${orig.content} ${prefix}${msg.content}`, - guild_id: ChannelStore.getChannel(chId)?.guild_id ?? msg.guild_id, - edited_timestamp: "invalid_timestamp", - message_reference: - msg?.message_reference || orig?.messageReference || null, - }; - - return args; - } - } catch (e) { - showToast("[Message Logger] FluxDispatcher crash – check logs"); - console.error("[Message Logger] Flux patch\n", e); - } - } - }); diff --git a/src/core/plugins/messagelogger/patches/self_edit.js b/src/core/plugins/messagelogger/patches/self_edit.js deleted file mode 100644 index 93e399d..0000000 --- a/src/core/plugins/messagelogger/patches/self_edit.js +++ /dev/null @@ -1,21 +0,0 @@ -import { before } from "@lib/api/patcher"; -import { findByProps } from "@metro"; -import { regexEscaper, isEnabled } from ".."; - -const Message = findByProps("sendMessage", "startEditMessage"); - -export default () => - before("startEditMessage", Message, (args) => { - if (!isEnabled) return; - - const escaped = regexEscaper("`[ EDITED ]`\n\n"); - const regexPattern = new RegExp(escaped, "gmi"); - - const [, , msg] = args; - if (typeof msg !== "string") return; - - const parts = msg.split(regexPattern); - const final = parts[parts.length - 1] ?? ""; - - args[2] = final; - }); diff --git a/src/core/ui/settings/pages/Plugins/models/vendetta.ts b/src/core/ui/settings/pages/Plugins/models/vendetta.ts index b79b08f..3d9fb59 100644 --- a/src/core/ui/settings/pages/Plugins/models/vendetta.ts +++ b/src/core/ui/settings/pages/Plugins/models/vendetta.ts @@ -1,5 +1,5 @@ import { VdPluginManager, VendettaPlugin } from "@core/vendetta/plugins"; -import { useProxy } from "@core/vendetta/storage"; +import { useProxy, createProxy } from "@core/vendetta/storage"; import { UnifiedPluginModel } from "."; @@ -20,7 +20,8 @@ export default function unifyVdPlugin( isInstalled: () => Boolean(vdPlugin && VdPluginManager.plugins[vdPlugin.id]), usePluginState() { - useProxy(VdPluginManager.plugins[vdPlugin.id]); + const dummyProxy = createProxy({}).proxy; + useProxy(VdPluginManager.plugins[vdPlugin.id] ?? dummyProxy); }, toggle(start: boolean) { start diff --git a/src/core/vendetta/plugins.ts b/src/core/vendetta/plugins.ts index 76fab8e..a18e17e 100644 --- a/src/core/vendetta/plugins.ts +++ b/src/core/vendetta/plugins.ts @@ -48,14 +48,18 @@ const pluginInstance: Record = {}; export const VdPluginManager = { plugins, async pluginFetch(url: string) { - if (url.startsWith(VD_PROXY_PREFIX)) { - url = url - .replace( - "https://bunny-mod.github.io/plugins-proxy", - BUNNY_PROXY_PREFIX, - ) - .replace(VD_PROXY_PREFIX, BUNNY_PROXY_PREFIX); - } + // was causing problems, dumb me with redirections + // :3 + // No redirection: use VD_PROXY_PREFIX as intended + // if (url.startsWith(VD_PROXY_PREFIX)) { + // url = url + // .replace( + // "https://bunny-mod.github.io/plugins-proxy", + // BUNNY_PROXY_PREFIX, + // ) + // .replace(VD_PROXY_PREFIX, BUNNY_PROXY_PREFIX); + // } + // End of pluginFetch function block return await safeFetch(url, { cache: "no-store" }); },