2026-02-17 17:25:18 -05:00
|
|
|
import {messageHelper} from "./helpers/messageHelper.js";
|
|
|
|
|
import {enums} from "./enums.js";
|
|
|
|
|
import {memberHelper} from "./helpers/memberHelper.js";
|
|
|
|
|
import {EmbedBuilder} from "@fluxerjs/core";
|
2026-02-17 23:03:19 -05:00
|
|
|
import {importHelper} from "./helpers/importHelper.js";
|
2026-02-14 11:37:24 -05:00
|
|
|
|
2026-02-23 15:10:48 -05:00
|
|
|
const cmds = {
|
|
|
|
|
commandsMap: new Map(),
|
|
|
|
|
aliasesMap: new Map()
|
|
|
|
|
};
|
2026-02-14 11:37:24 -05:00
|
|
|
|
2026-02-23 15:10:48 -05:00
|
|
|
cmds.aliasesMap.set('m', {command: 'member'})
|
2026-02-15 16:48:51 -05:00
|
|
|
|
2026-02-23 15:10:48 -05:00
|
|
|
cmds.commandsMap.set('member', {
|
|
|
|
|
description: enums.help.SHORT_DESC_MEMBER,
|
|
|
|
|
async execute(message, args) {
|
|
|
|
|
await cmds.memberCommand(message, args)
|
2026-02-14 11:37:24 -05:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-23 15:10:48 -05:00
|
|
|
/**
|
|
|
|
|
* Calls the member-related functions.
|
|
|
|
|
*
|
|
|
|
|
* @async
|
|
|
|
|
* @param {Message} message - The message object
|
|
|
|
|
* @param {string[]} args - The parsed arguments
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
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;
|
2026-02-24 14:50:46 -05:00
|
|
|
let reply;
|
|
|
|
|
try {
|
|
|
|
|
reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, attachmentUrl, attachmentExpires)
|
|
|
|
|
}
|
|
|
|
|
catch(e) {
|
|
|
|
|
console.log(e);
|
|
|
|
|
await message.reply(e.message);
|
|
|
|
|
}
|
2026-02-23 15:10:48 -05:00
|
|
|
|
|
|
|
|
if (typeof reply === 'string') {
|
2026-02-23 15:50:21 -05:00
|
|
|
await message.reply(reply);
|
2026-02-23 15:10:48 -05:00
|
|
|
}
|
|
|
|
|
else if (reply instanceof EmbedBuilder) {
|
|
|
|
|
await message.reply({embeds: [reply]})
|
|
|
|
|
}
|
|
|
|
|
else if (typeof reply === 'object') {
|
|
|
|
|
const errorsText = reply.errors.length > 0 ? reply.errors.join('\n- ') : null;
|
2026-02-23 15:50:21 -05:00
|
|
|
return await message.reply({content: `${reply.success} ${errorsText ? `\n\n${enums.err.ERRORS_OCCURRED}\n` + errorsText : ""}`, embeds: [reply.embed]})
|
2026-02-23 15:10:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmds.commandsMap.set('help', {
|
2026-02-14 11:37:24 -05:00
|
|
|
description: enums.help.SHORT_DESC_HELP,
|
|
|
|
|
async execute(message) {
|
2026-02-23 15:20:39 -05:00
|
|
|
const fields = [...cmds.commandsMap.entries()].map(([name, cmd]) => ({
|
2026-02-14 11:37:24 -05:00
|
|
|
name: `${messageHelper.prefix}${name}`,
|
|
|
|
|
value: cmd.description,
|
|
|
|
|
inline: true,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
|
.setTitle('Commands')
|
|
|
|
|
.setDescription(enums.help.PLURALFLUX)
|
|
|
|
|
.addFields(...fields)
|
|
|
|
|
.setFooter({ text: `Prefix: ${messageHelper.prefix}` })
|
|
|
|
|
.setTimestamp();
|
|
|
|
|
|
2026-02-23 15:20:39 -05:00
|
|
|
await message.reply({ embeds: [embed] });
|
2026-02-14 11:37:24 -05:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-23 15:10:48 -05:00
|
|
|
cmds.commandsMap.set('import', {
|
2026-02-15 01:42:12 -05:00
|
|
|
description: enums.help.SHORT_DESC_IMPORT,
|
2026-02-23 15:10:48 -05:00
|
|
|
async execute(message, args) {
|
|
|
|
|
await cmds.importCommand(message, args);
|
2026-02-15 01:29:56 -05:00
|
|
|
}
|
2026-02-15 00:23:30 -05:00
|
|
|
})
|
|
|
|
|
|
2026-02-23 15:10:48 -05:00
|
|
|
/**
|
|
|
|
|
* Calls the import-related functions.
|
|
|
|
|
*
|
|
|
|
|
* @async
|
|
|
|
|
* @param {Message} message - The message object
|
|
|
|
|
* @param {string[]} args - The parsed arguments
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
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 ) {
|
|
|
|
|
return await message.reply(enums.help.IMPORT);
|
|
|
|
|
}
|
2026-02-24 14:50:46 -05:00
|
|
|
try {
|
|
|
|
|
const successfullyAdded = await importHelper.pluralKitImport(message.author.id, attachmentUrl)
|
2026-02-23 15:10:48 -05:00
|
|
|
await message.reply(successfullyAdded);
|
2026-02-24 14:50:46 -05:00
|
|
|
}
|
|
|
|
|
catch(error) {
|
2026-02-23 15:10:48 -05:00
|
|
|
if (error instanceof AggregateError) {
|
|
|
|
|
// errors.message can be a list of successfully added members, or say that none were successful.
|
2026-02-24 14:50:46 -05:00
|
|
|
let errorsText = `${error.message}.\n\n${enums.err.ERRORS_OCCURRED}\n\n${error.errors.join('\n')}`;
|
|
|
|
|
if (errorsText.length > 2000) {
|
2026-02-23 15:10:48 -05:00
|
|
|
const returnedBuffer = messageHelper.returnBufferFromText(errorsText);
|
2026-02-24 14:50:46 -05:00
|
|
|
await message.reply({
|
|
|
|
|
content: returnedBuffer.text, files: [{name: 'text.txt', data: returnedBuffer.file}]
|
2026-02-23 15:10:48 -05:00
|
|
|
})
|
2026-02-24 14:50:46 -05:00
|
|
|
} else {
|
|
|
|
|
await message.reply(errorsText);
|
|
|
|
|
}
|
2026-02-23 15:10:48 -05:00
|
|
|
}
|
|
|
|
|
// If just one error was returned.
|
|
|
|
|
else {
|
2026-02-24 14:50:46 -05:00
|
|
|
console.error(error);
|
2026-02-23 15:10:48 -05:00
|
|
|
return await message.reply(error.message);
|
|
|
|
|
}
|
2026-02-24 14:50:46 -05:00
|
|
|
}
|
2026-02-23 15:10:48 -05:00
|
|
|
}
|
|
|
|
|
|
2026-02-17 17:25:18 -05:00
|
|
|
export const commands = cmds;
|