Remove messagelogger which was causing sometimes crashes
This commit is contained in:
parent
f1778fe101
commit
818e119cf5
6 changed files with 1 additions and 330 deletions
|
|
@ -77,7 +77,7 @@ const config = {
|
|||
constModules: {
|
||||
globals: {
|
||||
"bunny-build-info": {
|
||||
version: `"1.1.8-2"`,
|
||||
version: `"1.1.9-1"`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ export const getCorePlugins = (): Record<string, CorePlugin> => ({
|
|||
"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"),}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 = [];
|
||||
},
|
||||
});
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -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;
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue