From 474932161fb6e50e90cbd4e1546255b6a520394e Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 4 May 2023 21:47:08 -0300 Subject: [PATCH] Fix FakeNitro Stickers (#1048) --- src/api/MessageEvents.ts | 20 +++++++++++++++++--- src/plugins/apiMessageEvents.ts | 12 ++++++++---- src/plugins/fakeNitro.tsx | 4 ++-- src/plugins/typingIndicator.tsx | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts index 4bd3bc01..50d8b265 100644 --- a/src/api/MessageEvents.ts +++ b/src/api/MessageEvents.ts @@ -63,9 +63,23 @@ export interface Upload { uniqueId: string; uploadedFilename: string; } + +export interface MessageReplyOptions { + messageReference: Message["messageReference"]; + allowedMentions?: { + parse: Array; + repliedUser: boolean; + }; +} + export interface MessageExtra { - stickerIds?: string[]; + stickers?: string[]; uploads?: Upload[]; + replyOptions: MessageReplyOptions; + content: string; + channel: Channel; + type?: any; + openWarningPopout: (props: any) => any; } export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => Promisable; @@ -74,8 +88,8 @@ export type EditListener = (channelId: string, messageId: string, messageObj: Me const sendListeners = new Set(); const editListeners = new Set(); -export async function _handlePreSend(channelId: string, messageObj: MessageObject, extra: MessageExtra, uploads: Upload[]) { - extra.uploads = uploads; +export async function _handlePreSend(channelId: string, messageObj: MessageObject, extra: MessageExtra, replyOptions: MessageReplyOptions) { + extra.replyOptions = replyOptions; for (const listener of sendListeners) { try { const result = await listener(channelId, messageObj, extra); diff --git a/src/plugins/apiMessageEvents.ts b/src/plugins/apiMessageEvents.ts index 1fe3623d..fa467522 100644 --- a/src/plugins/apiMessageEvents.ts +++ b/src/plugins/apiMessageEvents.ts @@ -36,10 +36,14 @@ export default definePlugin({ { find: ".handleSendMessage=", replacement: { - // checkIsMessageValid().then((function (isValidData) { ... getSendMessageOptionsForReply(data); ... sendMessage(channel.id, msg, void 0, mergeMessageSendOptions(...)) - match: /(?<=uploads:(\i),channel:\i\}\)\.then\(\()function\((\i)\)\{(var \i=\i\.valid.+?\.getSendMessageOptionsForReply\(\i\);)(?=.+?\.sendMessage\((\i)\.id,(\i),void 0,(\i\(.+?)\):)/, - // checkIsMessageValid().then((async function (isValidData) { ...; if (await handlePresend(channel.id, msg, extra)) return; ... - replace: "async function($2){$3 if (await Vencord.Api.MessageEvents._handlePreSend($4.id,$5,$6,$1)) return {shouldClear:true,shouldRefocus:true};" + // props.chatInputType...then((function(isMessageValid)... var parsedMessage = b.c.parse(channel,... var replyOptions = f.g.getSendMessageOptionsForReply(pendingReply); + // Lookbehind: validateMessage)({openWarningPopout:..., type: i.props.chatInputType, content: t, stickers: r, ...}).then((function(isMessageValid) + match: /(props\.chatInputType.+?\.then\(\()(function.+?var (\i)=\i\.\i\.parse\((\i),.+?var (\i)=\i\.\i\.getSendMessageOptionsForReply\(\i\);)(?<=\)\(({.+?})\)\.then.+?)/, + // props.chatInputType...then((async function(isMessageValid)... var replyOptions = f.g.getSendMessageOptionsForReply(pendingReply); if(await Vencord.api...) return { shoudClear:true, shouldRefocus:true }; + replace: (_, rest1, rest2, parsedMessage, channel, replyOptions, extra) => "" + + `${rest1}async ${rest2}` + + `if(await Vencord.Api.MessageEvents._handlePreSend(${channel}.id,${parsedMessage},${extra},${replyOptions}))` + + "return{shoudClear:true,shouldRefocus:true};" } }, { diff --git a/src/plugins/fakeNitro.tsx b/src/plugins/fakeNitro.tsx index b067f2a3..1fb9fc3e 100644 --- a/src/plugins/fakeNitro.tsx +++ b/src/plugins/fakeNitro.tsx @@ -641,7 +641,7 @@ export default definePlugin({ if (!settings.enableStickerBypass) break stickerBypass; - const sticker = StickerStore.getStickerById(extra?.stickerIds?.[0]!); + const sticker = StickerStore.getStickerById(extra.stickers?.[0]!); if (!sticker) break stickerBypass; @@ -663,7 +663,7 @@ export default definePlugin({ link = `https://distok.top/stickers/${packId}/${sticker.id}.gif`; } - delete extra.stickerIds; + extra.stickers!.length = 0; messageObj.content += " " + link + `&name=${encodeURIComponent(sticker.name)}`; } } diff --git a/src/plugins/typingIndicator.tsx b/src/plugins/typingIndicator.tsx index 4b0d1622..8f98d5b3 100644 --- a/src/plugins/typingIndicator.tsx +++ b/src/plugins/typingIndicator.tsx @@ -57,7 +57,7 @@ function TypingIndicator({ channelId }: { channelId: string; }) { if (isChannelMuted) return null; } - const myId = UserStore.getCurrentUser().id; + const myId = UserStore.getCurrentUser()?.id; const typingUsersArray = Object.keys(typingUsers).filter(id => id !== myId && !(RelationshipStore.isBlocked(id) && !settings.store.includeBlockedUsers)); let tooltipText: string;