[V3 CustomCom] Custom Command Parameters #2051
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2051
Loading…
Reference in a new issue
No description provided.
Delete branch "patch-1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Description of the changes
Allows specifying more parameters for CC's via {0}, {1}, etc. that will be filled by the user invoking the CC. Python-style type hinting and attribute access is also allowed for Discord and builtin types.
The bot will reply with the standard help messages if the cc is incorrectly executed.
Oh, I forgot that I removed some variable definitions on my copy that weren't used since my linter kept bugging me, sorry!
on_message also had some variable name changes so I could better keep track of what variable was doing what.
I'm unsure what the travis-ci failure is - I looked at it but I don't know what it's trying to say.
@aikaterna told me that it was because I didn't style it according to your style guidelines, so I've formatted it accordingly. Thanks, aikaterna!
As a small note - a side effect of how I managed the parsing and help replies for this PR is the fact that CC's now have command event dispatching, like
on_commandandon_command_error. Should CC permissions be included in the future, this may make permissions easier to handle via modifying the fake command's checks attribute before invokation, but as that is outside the scope of the goal of this PR I haven't looked into it.Could I request some documentation of some sort (in command help, or its own doc page) for this? This might confuse newer users or users who aren't code oriented.
I added cog_customcom.rst for documentation. Feel free to give it a read to make sure the documentation makes sense.
I've been messing around with my branch and found that with a few minor changes I can make custom commands work with the Permissions cog.
I've stated before that this is outside the scope of this PR. Combined with that the approach I made, while simple to implement, has a couple downsides. I've created another PR with further details on my own fork:
https://github.com/zephyrkul/Red-DiscordBot/pull/1
I would be willing to merge that PR into this one if the downsides are acceptable. Otherwise I can leave this PR as-is.
Any opinions on the above comment / PR?
I don't see anything necessarily wrong with this implementation, but I would much prefer a string templating based design to conditional formatting. While I can't find a way to break this, that isn't to say it can't be done, or that something upstream couldn't change allowing this to be broken later. With templating, we provide what can be changed, and nothing more.
As for the permissions part, I'd hold off on that. The permissions cog is likely going to be reworked slightly on the backend. However, if you run the global checks on the context object created and it correctly fills in the command (custom-command in this case) name, then permissions will automatically work with it, no extra effort required. The only issue with this, is I'm not certain get_context and how you are parsing does this without registering CCs as command objects on the bot (I have not tested this)
If it does, then it will work out of the box, if it doesn't, I would not worry about this until after the current issues with the permissions cog are resolved, as your fake command objects may need internal modifications to support it not being real and managed by the bot.
First I just want to say this is an excellent pull request. I apologize for not getting to this sooner. I really like that you went the extra mile and added in some docs. I've been playing around with this a lot and like @mikeshardmind , I couldn't find a way to break it. String templating is more or less the go to solution for these types of obstacles, but I'm not 100% convinced that it is absolutely necessary in this case.
I only had three small things requested for change. Just look over my review for more details.
Once these bits are handled I'll give it the green light.
All points addressed.
Non-sequential arguments:
https://gyazo.com/6e61853a692fb78d4bb09d587b6b20a8
Arguments starting at non-zero:
https://gyazo.com/58da58f9f49693fb0cbd340f6bc5c99a
While this one was already documented in cogs_customcom.rst, it was only a little work to "forgive" the user for this transgression so I had it simply correct it and continue parsing.
Helpstring
https://gyazo.com/34aa26b39556cab9048799d88304e41c
Miscellaneous
I added a couple other fixes. When creating / editing a custom command, it will verify that the arguments will parse. (Incorrectly formatting the brace-syntax will still do as author, etc. do.) This fixes a bug that I had known about for a while where random-response custom commands would randomly fail if the arguments did not match.
Wow @zephyrkul this is great! Thank you so much for this PR. Also thanks @Redjumpman for reviewing and spotting those issues. I've done some testing and reading and I'm more than happy with it.