diff options
author | Nuckyz <61953774+Nuckyz@users.noreply.github.com> | 2023-03-23 07:45:39 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-23 10:45:39 +0000 |
commit | 082ac62edaa9eabf56b6e84e0b06bae64dc9844c (patch) | |
tree | 224cd5cc53be2c3e0dabbe8af023fda2009a777c | |
parent | 7923a790e6c90847337d888bb906ab8222193248 (diff) | |
download | Vencord-082ac62edaa9eabf56b6e84e0b06bae64dc9844c.tar.gz Vencord-082ac62edaa9eabf56b6e84e0b06bae64dc9844c.tar.bz2 Vencord-082ac62edaa9eabf56b6e84e0b06bae64dc9844c.zip |
feat(FakeNitro): Transform fake emojis into real ones (#669)
-rw-r--r-- | src/plugins/fakeNitro.tsx (renamed from src/plugins/fakeNitro.ts) | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/plugins/fakeNitro.ts b/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<any>) { + if (!this.EmojiComponent) return content; + + const newContent: Array<any> = []; + + 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(( + <this.EmojiComponent node={{ + type: "customEmoji", + jumboable: content.length === 1, + animated: fakeNitroMatch[2] === "gif", + name: ":FakeNitroEmoji:", + emojiId: fakeNitroMatch[1] + }} /> + )); + } + + return newContent; + }, + hasPermissionToUseExternalEmojis(channelId: string) { const channel = ChannelStore.getChannel(channelId); |