diff --git a/plugins/split-messages/src/index.ts b/plugins/split-messages/src/index.ts index 72f21dc..c3b5d86 100644 --- a/plugins/split-messages/src/index.ts +++ b/plugins/split-messages/src/index.ts @@ -1,5 +1,5 @@ import { findByProps, findByStoreName } from "@vendetta/metro"; -import { before } from "@vendetta/patcher"; +import { before, instead } from "@vendetta/patcher"; import { storage } from "@vendetta/plugin"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { showToast } from "@vendetta/ui/toasts"; @@ -10,21 +10,21 @@ function sleep(ms: number): Promise { return new Promise((r) => setTimeout(r, ms)); } -let unpatch: (() => boolean) | undefined; +let unpatchMaxLength: (() => boolean) | undefined; +let unpatchSend: (() => boolean) | undefined; export default { onLoad() { storage.splitOnWords ??= false; - const Constants = findByProps("MAX_MESSAGE_LENGTH"); + const MaxLengthModule = findByProps("getMaxMessageLength"); const MessageActions = findByProps("sendMessage", "editMessage"); const UserStore = findByStoreName("UserStore"); const ChannelStore = findByStoreName("ChannelStore"); - Constants.MAX_MESSAGE_LENGTH = 2 ** 30; - Constants.MAX_MESSAGE_LENGTH_PREMIUM = 2 ** 30; + unpatchMaxLength = instead("getMaxMessageLength", MaxLengthModule, () => 2 ** 30); - unpatch = before("sendMessage", MessageActions, (args: any[]) => { + unpatchSend = before("sendMessage", MessageActions, (args: any[]) => { const [channelId, message] = args; const content: string = message?.content ?? ""; const maxLength = UserStore.getCurrentUser()?.premiumType === 2 ? 4000 : 2000; @@ -60,10 +60,8 @@ export default { }); }, onUnload() { - unpatch?.(); - const Constants = findByProps("MAX_MESSAGE_LENGTH"); - Constants.MAX_MESSAGE_LENGTH = 2000; - Constants.MAX_MESSAGE_LENGTH_PREMIUM = 4000; + unpatchMaxLength?.(); + unpatchSend?.(); }, settings: Settings, };