errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.12k stars 614 forks source link

Add configurable aliases for commands and sub-commands #1534

Closed LemmaEOF closed 2 years ago

LemmaEOF commented 2 years ago

Closes #1279.

This pull request adds a new field to the config for defining aliases to commands and sub-commands. These are helpful for users to add shortcuts for often-used actions. Aliases are checked after standard commands, to avoid overriding commands added from plugins. Correction suggestions incorporate aliases as well.

The COMMAND_ALIASES field in the config takes a dictionary of aliases to standard commands. {"h": "help", "pinfo": "plugin info"} would make it so running !h would return the result for !help, and running !pinfo Help would return the result for !plugin info Help.

Tests for Python 3.9 are currently failing on my machine, but this is likely an issue with my Python configuration as the Python 3.8 tests pass without issue. I'm going to verify the tests tomorrow on another computer.

sijis commented 2 years ago

@LemmaEOF Thank you for this. Would you be able to include an example and include some tests around this?

LemmaEOF commented 2 years ago

Sounds good! I'll add them in as soon as I can.

LemmaEOF commented 2 years ago

Alright, test added! I put an example in the PR description, since I think that's what you meant. If it's not, please let me know and I can put it elsewhere instead! All the tests pass on Python 3.9 on my other machine (except for the ones that involve downloading the Hello World plugin due to annoying windows file lock stuff)

sijis commented 2 years ago

I like the idea of including this into core. I wondering if it makes better sense to keep this functionality as a plugin (https://github.com/rroemhild/err-alias), which does the same thing and can be dynamically edited without reloading the bot.

LemmaEOF commented 2 years ago

Oh right yeah, bot config is only loaded at launch. I'll see if I've got time to look into other ways to load aliases soon; I'm out of action for a little while due to some IRL stuff.