Fix crash when a user sends an attachment

Also added an eslint rule to catch similar errors caused by shadowed
variables in the future.
cshd
Dragory 2020-08-17 11:26:06 +03:00
parent a69e9dd0a2
commit 883d8adf93
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
2 changed files with 8 additions and 7 deletions

View File

@ -20,6 +20,7 @@
"!!": true "!!": true
} }
}], }],
"quotes": ["error", "double"] "quotes": ["error", "double"],
"no-shadow": "error"
} }
} }

View File

@ -258,8 +258,8 @@ class Thread {
let messageContent = msg.content || ""; let messageContent = msg.content || "";
// Prepare attachments // Prepare attachments
const attachments = []; const attachmentLinks = [];
const smallAttachments = []; const smallAttachmentLinks = [];
const attachmentFiles = []; const attachmentFiles = [];
for (const attachment of msg.attachments) { for (const attachment of msg.attachments) {
@ -269,10 +269,10 @@ class Thread {
if (config.relaySmallAttachmentsAsAttachments && attachment.size <= config.smallAttachmentLimit) { if (config.relaySmallAttachmentsAsAttachments && attachment.size <= config.smallAttachmentLimit) {
const file = await attachments.attachmentToDiscordFileObject(attachment); const file = await attachments.attachmentToDiscordFileObject(attachment);
attachmentFiles.push(file); attachmentFiles.push(file);
smallAttachments.push(savedAttachment.url); smallAttachmentLinks.push(savedAttachment.url);
} }
attachments.push(savedAttachment.url); attachmentLinks.push(savedAttachment.url);
} }
// Handle special embeds (listening party invites etc.) // Handle special embeds (listening party invites etc.)
@ -311,8 +311,8 @@ class Thread {
is_anonymous: 0, is_anonymous: 0,
dm_message_id: msg.id, dm_message_id: msg.id,
dm_channel_id: msg.channel.id, dm_channel_id: msg.channel.id,
attachments, attachments: attachmentLinks,
small_attachments: smallAttachments, small_attachments: smallAttachmentLinks,
}); });
threadMessage = await this._addThreadMessageToDB(threadMessage.getSQLProps()); threadMessage = await this._addThreadMessageToDB(threadMessage.getSQLProps());