63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('node:path');
|
|
const { SlashCommandBuilder } = require('discord.js');
|
|
|
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
|
const log = new DebugBuilder("server", "help");
|
|
|
|
const { EmmeliaEmbedBuilder } = require("../libUtils");
|
|
|
|
const commandsPath = path.resolve(__dirname, '../commands'); // Resolves from either working dir or __dirname
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('help')
|
|
.setDescription('Display this help message'),
|
|
example: "help",
|
|
isPrivileged: false,
|
|
async execute(interaction) {
|
|
try{
|
|
generalCommandText = "";
|
|
paidCommandText = "";
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
|
|
if (!command.isPrivileged){ // TODO - Need to add middleware for admins
|
|
if (!command.requiresTokens){
|
|
if (generalCommandText.length > 1 && generalCommandText.slice(-2) != `\n`){
|
|
generalCommandText += `\n\n`;
|
|
}
|
|
|
|
generalCommandText += `**/${command.data.name}** - *${command.data.description}*`;
|
|
|
|
if (command.example) generalCommandText += `\n\t\t***Usage:*** \`/${command.example}\``
|
|
}
|
|
else{
|
|
if (paidCommandText.length > 1 && paidCommandText.slice(-2) != `\n`){
|
|
paidCommandText += `\n\n`;
|
|
}
|
|
|
|
paidCommandText += `**/${command.data.name}** - *${command.data.description}*`;
|
|
|
|
if (command.example) paidCommandText += `\n\t\t***Usage:*** \`/${command.example}\``
|
|
}
|
|
}
|
|
}
|
|
|
|
const helpEmbed = new EmmeliaEmbedBuilder()
|
|
.setColor(0x0099FF)
|
|
.setTitle(`Help`)
|
|
.addFields(
|
|
{ name: 'General Commands', value: `${generalCommandText}` },
|
|
{ name: 'Paid Commands', value: `${paidCommandText}` }
|
|
)
|
|
await interaction.reply({ embeds: [helpEmbed], ephemeral: true });
|
|
}catch(err){
|
|
log.ERROR(err)
|
|
//await interaction.reply(err.toString());
|
|
}
|
|
}
|
|
}; |