diff --git a/src/plugins/encryptcord/index.tsx b/src/plugins/encryptcord/index.tsx index bd440e0b4..a308f7b82 100644 --- a/src/plugins/encryptcord/index.tsx +++ b/src/plugins/encryptcord/index.tsx @@ -78,13 +78,13 @@ const ChatBarIcon: ChatBarButton = ({ isMainChat }) => { tooltip={enabled ? "Send Unencrypted Messages" : "Send Encrypted Messages"} onClick={async () => { if (await DataStore.get('encryptcordGroup') == false || (await DataStore.get('encryptcordChannelId') != getCurrentChannel().id)) { - await sendTempMessage(getCurrentChannel().id, `${await DataStore.get("encryptcordPublicKey")}`, "join", false); - sendBotMessage(getCurrentChannel().id, { content: "*Checking for any groups in this channel...*" }); + await sendTempMessage(getCurrentChannel().id, "", `join\`\`\`\n${await DataStore.get("encryptcordPublicKey")}\`\`\``, false); + sendBotMessage(getCurrentChannel().id, { content: `*Checking for any groups in this channel...*\n> If none is found, a new one will be created ` }); await sleep(5000); if (await DataStore.get('encryptcordGroup') == true && (await DataStore.get('encryptcordChannelId') != getCurrentChannel().id)) { sendBotMessage(getCurrentChannel().id, { content: "*Leaving current group...*" }); await leave("", { channel: { id: await DataStore.get('encryptcordChannelId') } }); - } else { + } else if (await DataStore.get('encryptcordGroup') == true) { return; }; await startGroup("", { channel: { id: getCurrentChannel().id } }); @@ -168,7 +168,7 @@ export default definePlugin({ if (!message.content) return; const encryptcordGroupMembers = await DataStore.get('encryptcordGroupMembers'); if (!Object.keys(encryptcordGroupMembers).some(key => key == message.author.id)) { - switch (message.content.toLowerCase()) { + switch (message.content.toLowerCase().split("```")[0]) { case "groupdata": const response = await fetch(message.attachments[0].url); const groupdata = await response.json(); @@ -179,8 +179,7 @@ export default definePlugin({ if (!await DataStore.get("encryptcordGroup")) return; const sender = await UserUtils.getUser(message.author.id).catch(() => null); if (!sender) return; - const joinresponse = await fetch(message.attachments[0].url); - const userKey = await joinresponse.text(); + const userKey = message.content.split("```")[1]; await handleJoin(sender.id, userKey, encryptcordGroupMembers); break; default: diff --git a/src/plugins/encryptcord/rsa-utils.tsx b/src/plugins/encryptcord/rsa-utils.tsx index 9616fcf98..80e3ca35f 100644 --- a/src/plugins/encryptcord/rsa-utils.tsx +++ b/src/plugins/encryptcord/rsa-utils.tsx @@ -80,7 +80,7 @@ const base64ToArrayBuffer = (base64String) => { export const formatPemKey = (keyData, type) => { const base64Key = arrayBufferToBase64(keyData); - return `-----BEGIN ${type.toUpperCase()} KEY-----\n` + base64Key + `\n----- END ${type.toUpperCase()} KEY----- `; + return `-----BEGIN ${type.toUpperCase()} KEY-----\n` + base64Key + `\n-----END ${type.toUpperCase()} KEY----- `; }; const importPemPublicKey = async (pemKey) => { @@ -89,7 +89,7 @@ const importPemPublicKey = async (pemKey) => { const keyBody = trimmedPemKey .replace("-----BEGIN PUBLIC KEY-----", "") - .replace("----- END PUBLIC KEY-----", ""); + .replace("-----END PUBLIC KEY-----", ""); const binaryDer = atob(keyBody);