Skip to content
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

Proposal: Add support for decorator-based CommandModule command declaration #137

Open
richteer opened this issue Mar 6, 2019 · 1 comment
Labels

Comments

@richteer
Copy link
Contributor

richteer commented Mar 6, 2019

I see a lot of other python frameworks use decorators to define commands, routes, etc. I think it would be a good extension to include that in our framework as well, and may simplify some of the boilerplate for module developers.

Something like the following would be nice:

class TestModule(CommandModule):

    @command("test")
    def test_(self, msg=msg):
        self.reply(msg, body="Test!")

Here, the pair ("test", self.test_) would be automatically added to the module's self.commands dict, without needing to declare it in self.init() first.

Ideally, this should work with chaining other decorators, like hasPermission and AsArgs, as the command dec should not touch the parameters at all.

@richteer
Copy link
Contributor Author

richteer commented Mar 6, 2019

Note: this is tricky. Just attempted to implement this, and of course decorators are evaluated at "parse-time". We'd need to make sure these don't add themselves to a class-wide commands dict. Module instances should be able to have their own commands dict.

@richteer richteer added the QoL label Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant