za419 / CadenceBot

A Discord bot for Cadence Radio
MIT License
2 stars 1 forks source link

Allow aliasing of the core commands #77

Closed za419 closed 3 years ago

za419 commented 3 years ago

Have an array of configured commandAliases to allow a command to take on multiple names, and pre-process incoming messages to expand aliases to canonical form.

Proposed example config (in JS because JSON irritates me slightly more):

commandAliases=[
    {
        target: "play",
        prefix: false,
        alias: "cadence play"
    },
    {
        target: "search",
        prefix: true,
        alias: "cadence search"
    }
]

Proposed expander for proposed config:

function aliasTranslation(content) {
    for (const alias of config.commandAliases) {
        if (alias.prefix) {
            if (content.startsWith(alias.alias) {
                return config.commands[alias.target]+content.substring(alias.alias.length);
            }
        }
        else if (content === alias.alias) {
            return config.commands[alias.target];
        }
    }
    return content;
}

This does not cover adding these aliases to helptexts (this will be covered by #78), or aliasing custom commands (#79), or aliasing admin-only commands (I'm not scoping this at this time, because admin commands are run rarely and are ok being verbose. Besides, it should be very intentional that the admin is intending to do what they're specifically doing when they do something dangerous/having affect on others, and it should be verbose to others that can see the channel what exactly the admin has done.)