Skip to content

Commit

Permalink
Merge remote-tracking branch 'forky/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed Apr 9, 2022
2 parents f18a18a + f7588bd commit f7ed6bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion SimpleDiscordCrypt.meta.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ==UserScript==
// @name SimpleDiscordCrypt Extended
// @version 1.7.1.0
// @version 1.7.1.1
// ==/UserScript==
55 changes: 28 additions & 27 deletions SimpleDiscordCrypt.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name SimpleDiscordCrypt Extended
// @namespace https://github.com/Ceiridge/SimpleDiscordCrypt-Extended
// @version 1.7.1.0
// @version 1.7.1.1
// @description I hope people won't start calling this SDC ^_^
// @author An0, leogx9r, Ceiridge
// @license LGPLv3 - https://www.gnu.org/licenses/lgpl-3.0.txt
Expand Down Expand Up @@ -3624,8 +3624,8 @@ async function encryptFilename(key, filename) {
return encryptedFilename;
}

function fixPendingReply(messageExtras) {
const messageReference = messageExtras?.messageReference;
function fixPendingReply(messageOptions) {
const messageReference = messageOptions?.messageReference;

if(messageReference != null && Discord.getMessage != null && Discord.createPendingReply != null) {
const referencedMessage = Discord.getMessage(messageReference.channel_id, messageReference.message_id);
Expand All @@ -3635,41 +3635,44 @@ function fixPendingReply(messageExtras) {
Discord.createPendingReply({
message: referencedMessage,
channel: referencedChannel,
shouldMention: messageExtras.allowedMentions?.replied_user != false,
shouldMention: messageOptions.allowedMentions?.replied_user != false,
showMentionToggle: true
});
}
}
}

async function handleUpload(channelId, file, draftType, message, spoiler, filename) {
async function handleUpload(params) {
let { channelId, file, message, hasSpoiler, filename } = params;

let key = await handleSend(channelId, message, true);
if(key == null) return arguments;
if(key == null) return;

if(spoiler) {
arguments[4] = false;
if(hasSpoiler) {
params.hasSpoiler = false;
if(!filename.startsWith('SPOILER_')) filename = 'SPOILER_' + filename;
}

try {
let encryptedFilename = await encryptFilename(key, filename);
let fileBuffer = await Utils.ReadFile(file);
let encryptedBuffer = await Utils.AesEncrypt(key, fileBuffer);
arguments[1] = new File([encryptedBuffer], encryptedFilename);
arguments[5] = encryptedFilename;
params.file = new File([encryptedBuffer], encryptedFilename);
params.filename = encryptedFilename;
}
catch(e) {
arguments[1] = null;
params.file = null;
}
return arguments;
}

async function handleUploadFiles(channelId, editableFiles, draftType, message, extras) {
let key = await handleSend(channelId, message, true);
if(key == null) return arguments;
async function handleUploadFiles(params) {
let { channelId, uploads, parsedMessage } = params;

let key = await handleSend(channelId, parsedMessage, true);
if(key == null) return;

try {
for (let editableFile of editableFiles) {
for (let editableFile of uploads) {
let filename = editableFile.filename;
if(editableFile.spoiler) {
editableFile.spoiler = false;
Expand All @@ -3688,10 +3691,8 @@ async function handleUploadFiles(channelId, editableFiles, draftType, message, e
}
catch(err) {
Utils.Error(err);
arguments[1] = [];
params.uploads = [];
}

return arguments;
}

async function handleInstantUploads(channelId, fileList, draftType) {
Expand All @@ -3707,7 +3708,7 @@ async function handleInstantUploads(channelId, fileList, draftType) {
let encryptedBuffer = await Utils.AesEncrypt(key, fileBuffer);
let encryptedFile = new File([encryptedBuffer], encryptedFilename);

Discord.original_upload(channelId, encryptedFile, draftType, message, false, encryptedFilename);
Discord.original_upload({ channelId, file: encryptedFile, draftType, message, hasSpoiler: false, filename: encryptedFilename });
}
}
catch(err) {
Expand Down Expand Up @@ -3781,23 +3782,23 @@ function Load()

Discord.detour_dispatch = HandleDispatch;

Discord.detour_upload = function(){(async () => {
Discord.detour_upload = function(params){(async () => {

let argumentsOverride = await handleUpload.apply(null, arguments);
await handleUpload(params);

Discord.original_upload.apply(this, argumentsOverride);
Discord.original_upload.apply(this, arguments);
})()};

Discord.detour_instantBatchUpload = function() {
handleInstantUploads.apply(this, arguments);
};

Discord.detour_uploadFiles = function(){(async () => {
Discord.detour_uploadFiles = function(params){(async () => {

let argumentsOverride = await handleUploadFiles.apply(null, arguments);
await handleUploadFiles(params);

fixPendingReply(arguments[4]);
Discord.original_uploadFiles.apply(this, argumentsOverride);
fixPendingReply(params.options);
Discord.original_uploadFiles.apply(this, arguments);
})()};

if(Discord.detour_EMBED != null) Discord.detour_EMBED = function(path, t) {
Expand Down

0 comments on commit f7ed6bb

Please sign in to comment.