From 082ac62edaa9eabf56b6e84e0b06bae64dc9844c Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Thu, 23 Mar 2023 07:45:39 -0300 Subject: [PATCH] feat(FakeNitro): Transform fake emojis into real ones (#669) --- src/plugins/{fakeNitro.ts => fakeNitro.tsx} | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) rename src/plugins/{fakeNitro.ts => fakeNitro.tsx} (87%) diff --git a/src/plugins/fakeNitro.ts b/src/plugins/fakeNitro.tsx similarity index 87% rename from src/plugins/fakeNitro.ts rename to src/plugins/fakeNitro.tsx index 71757b5..5e8c381 100644 --- a/src/plugins/fakeNitro.ts +++ b/src/plugins/fakeNitro.tsx @@ -185,6 +185,36 @@ export default definePlugin({ match: /(function \i\(\i\){var (\i)=\i\.backgroundGradientPresetId.+?)(\i\.\i\.updateAsync.+?theme=(.+?);.+?\),\i\))/, replace: (_, rest, backgroundGradientPresetId, originalCall, theme) => `${rest}$self.handleGradientThemeSelect(${backgroundGradientPresetId},${theme},()=>${originalCall});` } + }, + { + find: 'jumboable?"jumbo":"default"', + predicate: () => Settings.plugins.FakeNitro.transformEmojis === true, + replacement: { + match: /jumboable\?"jumbo":"default",emojiId.+?}}\)},(?<=(\i)=function\(\i\){var \i=\i\.node.+?)/, + replace: (m, component) => `${m}fakeNitroEmojiComponentExport=($self.EmojiComponent=${component},void 0),` + } + }, + { + find: '["strong","em","u","text","inlineCode","s","spoiler"]', + predicate: () => Settings.plugins.FakeNitro.transformEmojis === true, + replacement: [ + { + match: /1!==(\i)\.length\|\|1!==\i\.length/, + replace: (m, content) => `${m}||${content}[0].target?.startsWith("https://cdn.discordapp.com/emojis/")` + }, + { + match: /(?=return{hasSpoilerEmbeds:\i,content:(\i)})/, + replace: (_, content) => `${content}=$self.patchFakeNitroEmojis(${content});` + } + ] + }, + { + find: "renderEmbeds=function", + predicate: () => Settings.plugins.FakeNitro.transformEmojis === true, + replacement: { + match: /renderEmbeds=function\(\i\){.+?embeds\.map\(\(function\((\i)\){/, + replace: (m, embed) => `${m}if(${embed}.url?.startsWith("https://cdn.discordapp.com/emojis/"))return null;` + } } ], @@ -201,6 +231,12 @@ export default definePlugin({ default: 48, markers: [32, 48, 64, 128, 160, 256, 512], }, + transformEmojis: { + description: "Whether to transform fake emojis into real ones", + type: OptionType.BOOLEAN, + default: true, + restartNeeded: true, + }, enableStickerBypass: { description: "Allow sending fake stickers", type: OptionType.BOOLEAN, @@ -295,6 +331,39 @@ export default definePlugin({ }); }, + EmojiComponent: null as any, + + patchFakeNitroEmojis(content: Array) { + if (!this.EmojiComponent) return content; + + const newContent: Array = []; + + for (const element of content) { + if (element.props?.trusted == null) { + newContent.push(element); + continue; + } + + const fakeNitroMatch = element.props.href.match(/https:\/\/cdn\.discordapp\.com\/emojis\/(\d+?)\.(png|webp|gif).+?(?=\s|$)/); + if (!fakeNitroMatch) { + newContent.push(element); + continue; + } + + newContent.push(( + + )); + } + + return newContent; + }, + hasPermissionToUseExternalEmojis(channelId: string) { const channel = ChannelStore.getChannel(channelId);