diff --git a/src/commands.js b/src/commands.js index 332a8f2..79d0d01 100644 --- a/src/commands.js +++ b/src/commands.js @@ -26,25 +26,22 @@ cmds.commandsMap.set('member', { * @param {string[]} args - The parsed arguments * **/ -cmds.memberCommand = async function(message, args) { +cmds.memberCommand = async function (message, args) { const authorFull = `${message.author.username}#${message.author.discriminator}` const attachmentUrl = message.attachments.size > 0 ? message.attachments.first().url : null; const attachmentExpires = message.attachments.size > 0 ? message.attachments.first().expires_at : null; let reply; try { reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, attachmentUrl, attachmentExpires) - } - catch(e) { + } catch (e) { return await message.reply(e.message); } if (typeof reply === 'string') { await message.reply(reply); - } - else if (reply instanceof EmbedBuilder) { + } else if (reply instanceof EmbedBuilder) { await message.reply({embeds: [reply]}) - } - else if (typeof reply === 'object') { + } else if (typeof reply === 'object') { // The little dash is so that the errors print out in bullet points in Fluxer const errorsText = reply.errors.length > 0 ? '- ' + reply.errors.join('\n- ') : null; return await message.reply({ @@ -69,10 +66,10 @@ cmds.commandsMap.set('help', { .setTitle('Commands') .setDescription(enums.help.PLURALFLUX) .addFields(...fields) - .setFooter({ text: `Prefix: ${messageHelper.prefix}` }) + .setFooter({text: `Prefix: ${messageHelper.prefix}`}) .setTimestamp(); - await message.reply({ embeds: [embed] }); + await message.reply({embeds: [embed]}); }, }) @@ -91,34 +88,35 @@ cmds.commandsMap.set('import', { * @param {string[]} args - The parsed arguments * **/ -cmds.importCommand = async function(message, args) { +cmds.importCommand = async function (message, args) { const attachmentUrl = message.attachments.size > 0 ? message.attachments.first().url : null; - if ((message.content.includes('--help') || (args[0] === '' && args.length === 1)) && !attachmentUrl ) { + if ((message.content.includes('--help') || (args[0] === '' && args.length === 1)) && !attachmentUrl) { return await message.reply(enums.help.IMPORT); } + let errorsText; try { const successfullyAdded = await importHelper.pluralKitImport(message.author.id, attachmentUrl) - await message.reply(successfullyAdded); - } - catch(error) { + return await message.reply(successfullyAdded); + } catch (error) { if (error instanceof AggregateError) { // errors.message can be a list of successfully added members, or say that none were successful. - let errorsText = `${error.message}.\n\n${enums.err.ERRORS_OCCURRED}\n\n${error.errors.join('\n')}`; - if (errorsText.length > 2000) { - const returnedBuffer = messageHelper.returnBufferFromText(errorsText); - await message.reply({ - content: returnedBuffer.text, files: [{name: 'text.txt', data: returnedBuffer.file}] - }) - } else { - await message.reply(errorsText); - } + errorsText = `${error.message}.\n\n${enums.err.ERRORS_OCCURRED}\n\n${error.errors.join('\n')}`; } // If just one error was returned. else { console.error(error); - return await message.reply(error.message); + errorsText = error.message; } } + if (errorsText.length > 2000) { + const returnedBuffer = messageHelper.returnBufferFromText(errorsText); + await message.reply({ + content: returnedBuffer.text, files: [{name: 'text.txt', data: returnedBuffer.file}] + }) + } else { + await message.reply(errorsText) + } + } export const commands = cmds; \ No newline at end of file