-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User-configurable command prefix #193
base: master
Are you sure you want to change the base?
Conversation
Hey, thanks for the PR, thinking through the problems here, and the in-depth explanation of the code. Overall it seems pretty reasonable, but it feels awkward to have a mismatch between the default command trigger ( I wonder if maybe a better option for the syntax is to take the arguments as a new decorator (e.g. And a minor difference to note would be that the first command passed to the What do you think? As a slightly related aside: A longer-term solution that I've considered in the past is to actually make Cardinal a bit syntax-aware, and respond to invalid syntax for commands itself. This would help reduce some of the boilerplate when parsing a command inside a plugin. I'm not exactly sure what the decorator would look like there. |
I definitely agree that the trigger appearing differently in help message is less than ideal. In hindsight, I really wonder what I was thinking when I went with that decision. Creating a separate
Having said all that, I definitely agree that having it implemented as a decorator is the right way to go about doing it. I just couldn't make it work. PEBKAC and all that. The changes are subpar as they stand now and I'm okay with it being rejected. Also, I think some of the source code ambiguity can be removed by picking the right name for the new decorator. @command(["cmd", "command"])
@syntax("arg1 arg2") # potential to confuse arg1 for the name of the command to use
@help("A command that does something really funny")
def command(self, ...): compared to @command(["cmd", "command"])
@arguments("arg1 arg2")
@help("A command that does something really funny")
def command(self, ...): but it could take on any other names as well.
I would have to understand Cardinal's core better (and Python, really) before I can offer useful commentary on this one. Sorry. |
@dkim286 The As a note for myself, I'm considering a backwards compatibility layer that parses existing |
60c8c97
to
74ba8f0
Compare
Attempting to solve issue #189
Here's how the prefix is passed between the modules and where it's being kept, in a (more or less) step-by-step list:
cardinal.py
attempts to loadcmd_prefix
from the config file, if it exists. Defaults to.
if it doesn't exist.CardinalBotFactory
containscmd_prefix
as an instance variable.CardinalBot
reads the prefix from the factory, then passes the prefix toPluginManager
(https://github.com/dkim286/Cardinal/blob/c0786e728a139f0b77e59e0b9fef6d9cf776888d/cardinal/bot.py#L124-L128).PluginManager
uses the prefix to build itsCOMMAND_REGEX
instance variable (https://github.com/dkim286/Cardinal/blob/c0786e728a139f0b77e59e0b9fef6d9cf776888d/cardinal/plugins.py#L61-L63)_instantiate_plugin()
function checks if a module accepts acmd_prefix
argument (https://github.com/dkim286/Cardinal/blob/c0786e728a139f0b77e59e0b9fef6d9cf776888d/cardinal/plugins.py#L189-L203).cmd_prefix
from the plugin manager is aware of the custom prefix (e.g.help
: https://github.com/dkim286/Cardinal/blob/c0786e728a139f0b77e59e0b9fef6d9cf776888d/plugins/help/plugin.py#L11-L12).Unfortunately, this does mean that the syntax help for each command had to be changed slightly. I went with the
@
symbol. For example,help
plugin's command:The "placeholder" token is replaced from within the
help
plugin with a string replace function (https://github.com/dkim286/Cardinal/blob/c0786e728a139f0b77e59e0b9fef6d9cf776888d/plugins/help/plugin.py#L87-L93):I went ahead and changed all the plugins' syntax help messages to use the
@
symbol.It does seem to work for most commands. I have not tested this with the
ticker
module, as I don't have an API for it.Screenshot of the bot in action, default configuration:
Screenshot of the bot in action, configured to use
!
for prefix: