changed commands.js to not have user interaction within the catch

This commit is contained in:
Aster Fialla
2026-02-24 20:02:11 -05:00
parent de674281f9
commit ba2274e5be

View File

@@ -26,25 +26,22 @@ cmds.commandsMap.set('member', {
* @param {string[]} args - The parsed arguments * @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 authorFull = `${message.author.username}#${message.author.discriminator}`
const attachmentUrl = message.attachments.size > 0 ? message.attachments.first().url : null; const attachmentUrl = message.attachments.size > 0 ? message.attachments.first().url : null;
const attachmentExpires = message.attachments.size > 0 ? message.attachments.first().expires_at : null; const attachmentExpires = message.attachments.size > 0 ? message.attachments.first().expires_at : null;
let reply; let reply;
try { try {
reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, attachmentUrl, attachmentExpires) reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, attachmentUrl, attachmentExpires)
} } catch (e) {
catch(e) {
return await message.reply(e.message); return await message.reply(e.message);
} }
if (typeof reply === 'string') { if (typeof reply === 'string') {
await message.reply(reply); await message.reply(reply);
} } else if (reply instanceof EmbedBuilder) {
else if (reply instanceof EmbedBuilder) {
await message.reply({embeds: [reply]}) 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 // 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; const errorsText = reply.errors.length > 0 ? '- ' + reply.errors.join('\n- ') : null;
return await message.reply({ return await message.reply({
@@ -69,10 +66,10 @@ cmds.commandsMap.set('help', {
.setTitle('Commands') .setTitle('Commands')
.setDescription(enums.help.PLURALFLUX) .setDescription(enums.help.PLURALFLUX)
.addFields(...fields) .addFields(...fields)
.setFooter({ text: `Prefix: ${messageHelper.prefix}` }) .setFooter({text: `Prefix: ${messageHelper.prefix}`})
.setTimestamp(); .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 * @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; 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); return await message.reply(enums.help.IMPORT);
} }
let errorsText;
try { try {
const successfullyAdded = await importHelper.pluralKitImport(message.author.id, attachmentUrl) const successfullyAdded = await importHelper.pluralKitImport(message.author.id, attachmentUrl)
await message.reply(successfullyAdded); return await message.reply(successfullyAdded);
} } catch (error) {
catch(error) {
if (error instanceof AggregateError) { if (error instanceof AggregateError) {
// errors.message can be a list of successfully added members, or say that none were successful. // 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')}`; 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);
errorsText = error.message;
}
}
if (errorsText.length > 2000) { if (errorsText.length > 2000) {
const returnedBuffer = messageHelper.returnBufferFromText(errorsText); const returnedBuffer = messageHelper.returnBufferFromText(errorsText);
await message.reply({ await message.reply({
content: returnedBuffer.text, files: [{name: 'text.txt', data: returnedBuffer.file}] content: returnedBuffer.text, files: [{name: 'text.txt', data: returnedBuffer.file}]
}) })
} else { } else {
await message.reply(errorsText); await message.reply(errorsText)
}
}
// If just one error was returned.
else {
console.error(error);
return await message.reply(error.message);
}
} }
} }
export const commands = cmds; export const commands = cmds;