Friday, September 20, 2024 2:40:06 AM
> settings

Customize


Authenticate

> commands.js
const ESMCommand = require("../esm_command");
module.exports = class ESMCommand_Commands extends ESMCommand {
    constructor(bot) {
        super(bot);

        this.commandParams = {
            all: {
                regex: /--all/i,
                nullable: true
            }
        };

        this.information = {
            category: "system",
            params: "--all (shows all commands)",
            help: "Lists all commands relevant to most users. `!commands --all` to show all commands"
        };

        this.configuration = {
            allowedInTextChannels: {
                modifiable: true,
                default: true
            }
        };
    }

    async fromDiscord() {
        let commands = {},
            helpEmbed = {
                timestamp: new Date(),
                color: this.ESMBot.colors.BLUE,
                title: this.util.isNull(this.params.all) ? "Available Commands" : "All Commands",
                description: this.util.isNull(this.params.all) ? `Use \`!commands --all\` to show all commands\nYou can append \`--help\` to any command to see more information about it.\nFor example: \`!servers --help\`` : "A full list of commands and their usage can be found on my website: http://www.esmbot.com/wiki/commands",
                fields: []
            }

        for (let commandName in this.ESMBot.commands) {
            if (!this.ESMBot.commands.hasOwnProperty(commandName)) continue;
            let command = new this.ESMBot.commands[commandName](this.ESMBot);
            let description = command.information;
            let hasPermissions = command.configuration.hasOwnProperty("permissions") && command.configuration.permissions.modifiable;
            if (this.util.isEmpty(description)) continue;
            if (description.category == null || ["", "administrative", "development"].includes(description.category)) continue;
            if (this.util.isNull(this.params.all) && hasPermissions) continue;
            if (commands.hasOwnProperty(description.category)) {
                commands[description.category].push(`\`${this.ESMBot.config.COMMAND_SYMBOL}${command.name}\``);
            } else {
                commands[description.category] = [
                    `\`${this.ESMBot.config.COMMAND_SYMBOL}${command.name}\``
                ];
            }
        }

        for (let category in commands) {
            if (!commands.hasOwnProperty(category)) continue;
            let embed = {
                name: `${this.util.titleize(category)} Commands`,
                value: commands[category].join(", ")
            };

            helpEmbed.fields.push(embed);
        }

        this.ESMBot.send(this.message.channel, helpEmbed);
    }
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8