From 9c99700ba13f41e1dbcb1101cb4e4957280536e5 Mon Sep 17 00:00:00 2001 From: SammCheese Date: Tue, 25 Oct 2022 06:23:18 +0200 Subject: [PATCH] [1.5.10] Minor Fixes to Link Embeds in Decryption --- components/Functions.js | 37 ++++++++------- index.js | 102 +++++++++++++++++++--------------------- manifest.json | 2 +- 3 files changed, 69 insertions(+), 72 deletions(-) diff --git a/components/Functions.js b/components/Functions.js index 4ccb5dd..4d0a08a 100644 --- a/components/Functions.js +++ b/components/Functions.js @@ -26,12 +26,12 @@ exports.getSetting = (setting, defaultValue) => { exports.fetchEmbed = async (url) => { const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), 15000); + const timeout = setTimeout(() => controller.abort(), 7000); const options = { signal: controller.signal, method: "POST", - mode: 'cors', + headers: { 'Content-Type': 'application/json' }, @@ -91,26 +91,27 @@ exports.doEmbed = async (messageId, ChannelId, content, url) => { }; if (url) { - try { - attachment = await this.fetchEmbed(url); - console.log(attachment) - attachment.footer = { - text: "Made with ❤️ by c0dine and Sammy!" - } - } catch (e) { - if (url.match(/[=|\.](jpeg|jpg|gif|png|webp)/) && !attachment) { - const res = await this.fetchEmbedOld(url); - embed.image = { - url, - width: res.width, - height: res.height - } + attachment = await this.fetchEmbed(url); + if (!attachment && url.match(/[=|\.](jpeg|jpg|gif|png|webp)/)) { + const res = await this.fetchEmbedOld(url); + embed.image = { + url, + width: res.width, + height: res.height } } } - message.embeds.push(embed) - if (attachment) message.embeds.push(attachment); + // Add the initial Decryption Embed + message.embeds.push(embed); + + if (attachment) { + attachment.footer = { + text: "Made with ❤️ by c0dine and Sammy!" + }; + message.embeds.push(attachment); + } + message.embeds = message.embeds.map(embed => this.cleanupEmbed(embed)); this.updateMessage(message) } diff --git a/index.js b/index.js index cb5ba8b..5fd4522 100644 --- a/index.js +++ b/index.js @@ -2,21 +2,24 @@ const { Plugin } = require('powercord/entities'); const { open: openModal } = require('powercord/modal'); const { inject, uninject } = require('powercord/injector'); -const { getModule, React, messages } = require('powercord/webpack'); const { findInReactTree } = require('powercord/util'); +const { getModule, React, messages } = require('powercord/webpack'); + +// Functions +const f = require('./components/Functions'); // React Elements const Settings = require("./Settings/Settings"); -const chatbarButton = require('./assets/Icons/ChatbarButton'); -const f = require('./components/Functions'); -const ToolbarButton = require('./assets/Icons/ToolbarButton'); const { Lock } = require('./assets/Icons/MessageIcon'); const CloseButton = require("./assets/Icons/CloseButton"); +const ToolbarButton = require('./assets/Icons/ToolbarButton'); +const chatbarButton = require('./assets/Icons/ChatbarButton'); const { ModalComposerEncrypt, ModalComposerDecrypt } = require('./components/ModalComposer'); // Globals let activeHotkey = false; +// Modules const { MenuItem } = getModule(['MenuItem'], false); const { ComponentDispatch } = getModule(["ComponentDispatch"], false) @@ -44,7 +47,7 @@ module.exports = class InvisbleChatRewrite extends Plugin { powercord.api.settings.registerSettings("invichat", { label: "Invisible Chat", category: this.entityID, - render: Settings, + render: Settings }); document.addEventListener('keydown', keypress); @@ -53,14 +56,14 @@ module.exports = class InvisbleChatRewrite extends Plugin { this.__injectDecryptButton(); this.__injectSendingMessages(); - this.settings.get("useInvisibleAttachmentButton", false) ? - this.__injectAttachmentButton(): + this.settings.get('useInvisibleAttachmentButton', false) ? + this.__injectAttachmentButton() : this.__injectChatBarIcon(); } async __handleSettingsChange(setting, value) { switch (setting) { - case "useInvisibleAttachmentButton": + case 'useInvisibleAttachmentButton': if (value) { this.__injectAttachmentButton(); uninject('invisible-chatbutton'); @@ -74,7 +77,7 @@ module.exports = class InvisbleChatRewrite extends Plugin { async __injectAttachmentButton() { const ChannelAttachMenu = await getModule( - m => m.default?.displayName === "ChannelAttachMenu", + m => m.default?.displayName === 'ChannelAttachMenu', ); // No point in trying to inject if the module is not found @@ -87,7 +90,7 @@ module.exports = class InvisbleChatRewrite extends Plugin { label: React.createElement( 'div', { - className: 'optionLabel-1o-h-l', + className: 'optionLabel-1o-h-l' }, null, React.createElement('div', { @@ -98,19 +101,19 @@ module.exports = class InvisbleChatRewrite extends Plugin { verticalAlign: 'middle', width: '24px', height: '24px', - lineHeight: '24px', - }, + lineHeight: '24px' + } }), React.createElement( 'div', { - className: 'optionName-1ebPjH', + className: 'optionName-1ebPjH' }, null, - 'Encrypt Message', - ), + 'Encrypt Message' + ) ), - id: "invisible-attachbutton", + id: 'invisible-attachbutton', showIconFirst: true, action: () => openModal(ModalComposerEncrypt) }) @@ -124,24 +127,22 @@ module.exports = class InvisbleChatRewrite extends Plugin { if (typeof ChannelTextAreaButtons === 'undefined') return; inject('invisible-chatbutton', ChannelTextAreaButtons, 'type', (args, res) => { - // Create the Button Element const button = React.createElement('div', { className: 'send-invisible-message', - onClick: () => { - openModal(ModalComposerEncrypt); - } - }, React.createElement(chatbarButton) + onClick: () => openModal(ModalComposerEncrypt) + }, React.createElement(chatbarButton) ); + + try { + res.props.children.unshift(button) + } catch { + + } - try { - // Add the Button to the Chatbar - res.props.children.unshift(button); - } catch { } return res; - } - ) - ChannelTextAreaButtons.type.displayName = "ChannelTextAreaButtons"; + }); + ChannelTextAreaButtons.type.displayName = 'ChannelTextAreaButtons'; } async __injectDecryptButton() { @@ -166,35 +167,33 @@ module.exports = class InvisbleChatRewrite extends Plugin { React.createElement('div', { onClick: () => { // Try every password saved and decrypt, else open Password Prompt - f.iteratePasswords(this.settings.get("userPasswords", []), ModalComposerDecrypt, { + f.iteratePasswords(this.settings.get('userPasswords', []), ModalComposerDecrypt, { author: msg.author.id, content: match.input, channel: msg.channel_id, message: msg.id }) } - }, - [React.createElement(ToolbarButton)]) - ) + }, [React.createElement(ToolbarButton)])); return res; - }) + }); + MiniPopover.default.displayName = 'MiniPopover'; } async __injectIndicator() { const d = (m) => { const def = m.__powercordOriginal_default ?? m.default; - return typeof def == 'function' ? def : null; + return typeof def === 'function' ? def : null; }; - const MessageContent = await getModule((m) => { - return d(m)?.toString().includes('MessageContent'); - }); + + const MessageContent = await getModule(m => d(m)?.toString().includes('MessageContent')); // Error handling for if the module is not found if (!MessageContent) return; inject('invisible-messageContent', MessageContent, 'default', (_, res) => { - const msg = findInReactTree(res, (n) => n && n.message)?.message; + const msg = findInReactTree(res, n => n && n.message)?.message; if (!msg) return res; @@ -206,12 +205,10 @@ module.exports = class InvisbleChatRewrite extends Plugin { // If not, STOP. if (!match) return res; - res.props.children.props.children[3].props.children.push( - React.createElement(Lock) - ); + res.props.children.props.children[3].props.children.push(React.createElement(Lock)); // Look through the footers for our default footer, add a Discard Button if we find it - if (msg.embeds.find(e => e.footer && e.footer.text.includes("c0dine and Sammy"))) { + if (msg.embeds.find(e => e.footer && e.footer.text.includes('c0dine and Sammy'))) { res.props.children.props.children[3].props.children.push( React.createElement('span', {}, React.createElement(CloseButton, { message: msg @@ -220,25 +217,24 @@ module.exports = class InvisbleChatRewrite extends Plugin { } return res; - } - ); + }); } async __injectSendingMessages() { inject('invisible-catchMessage', messages, 'sendMessage', async (args, res) => { if (activeHotkey) { try { - const content = args[1].content; - const cover = content.match(/(.{0,2000})\*.{0,2000}\*/)[1] - const hidden = content.match(/\*.{0,2000}\*/)[0].replaceAll('*', '') + const { content } = args[1]; + const cover = content.match(/(.{0,2000})\*.{0,2000}\*/)[1]; + const hidden = content.match(/\*.{0,2000}\*/)[0].replaceAll('*', ''); const pw = this.settings.get('defaultPassword', 'password'); const enc = f.encrypt(hidden, pw, cover); args[1].content = await enc; } catch (e) { - // DO NOT SEND THE MESSAGE UNDER ANY CIRCUMSTANCE - args[1].content = ""; + // DO NOT SEND THE UNENCRYPTED MESSAGE UNDER ANY CIRCUMSTANCE + args[1].content = ''; return ComponentDispatch.dispatch('SHAKE_APP', { duration: 500, intensity: 2 @@ -246,16 +242,16 @@ module.exports = class InvisbleChatRewrite extends Plugin { } } return args; - }, true) + }, true); } pluginWillUnload() { uninject('invisible-chatbutton'); - uninject('invisible-catchMessage'); - uninject('invisible-messageContent'); uninject('invichat-minipopover'); uninject('invisible-attachbutton'); - powercord.api.settings.unregisterSettings("invichat"); + uninject('invisible-catchMessage'); + uninject('invisible-messageContent'); document.removeEventListener('keydown', keypress) + powercord.api.settings.unregisterSettings('invichat'); } } diff --git a/manifest.json b/manifest.json index dd9a3e1..5df3441 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Invisible Chat", - "version": "1.5.9", + "version": "1.5.10", "description": "Allows you to send invisible messages to a specified user encrypted in an unusual way", "author": "c0dine & Samm-Cheese", "license": "MIT"