Skip to content

Commit

Permalink
[1.5.10] Minor Fixes to Link Embeds in Decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
SammCheese committed Oct 25, 2022
1 parent a972967 commit 9c99700
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 72 deletions.
37 changes: 19 additions & 18 deletions components/Functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down Expand Up @@ -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)
}
Expand Down
102 changes: 49 additions & 53 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand All @@ -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
Expand All @@ -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', {
Expand All @@ -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)
})
Expand All @@ -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() {
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -220,42 +217,41 @@ 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
});
}
}
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');
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 9c99700

Please sign in to comment.