[V3 CustomCom] Custom Command Parameters #2051

Merged
Zephyrkul merged 20 commits from patch-1 into V3/develop 2018-09-06 16:14:03 +02:00
Zephyrkul commented 2018-08-25 05:24:17 +02:00 (Migrated from github.com)

Type

  • New feature

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.

[p]cc add simple greet Hi, {0.mention:Member}!
...
[p]greet zephyrkul
Hi, @zephyrkul!

The bot will reply with the standard help messages if the cc is incorrectly executed.

[p]greet me
Member "me" not found

### Type - [x] New feature ### 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. > [p]cc add simple greet Hi, {0.mention:Member}! > ... > [p]greet zephyrkul > Hi, @zephyrkul! The bot will reply with the standard help messages if the cc is incorrectly executed. > [p]greet me > Member "me" not found
palmtree5 (Migrated from github.com) reviewed 2018-08-25 05:24:17 +02:00
tekulvw (Migrated from github.com) reviewed 2018-08-25 05:24:17 +02:00
Zephyrkul commented 2018-08-25 05:27:35 +02:00 (Migrated from github.com)

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.

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.
Zephyrkul commented 2018-08-25 05:41:24 +02:00 (Migrated from github.com)

I'm unsure what the travis-ci failure is - I looked at it but I don't know what it's trying to say.

I'm unsure what the travis-ci failure is - I looked at it but I don't know what it's trying to say.
Zephyrkul commented 2018-08-25 05:47:06 +02:00 (Migrated from github.com)

@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!

@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!
Zephyrkul commented 2018-08-25 08:30:17 +02:00 (Migrated from github.com)

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_command and on_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.

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_command` and `on_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.
Kowlin commented 2018-08-26 21:41:40 +02:00 (Migrated from github.com)

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.

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.
Zephyrkul commented 2018-08-26 23:25:16 +02:00 (Migrated from github.com)

I added cog_customcom.rst for documentation. Feel free to give it a read to make sure the documentation makes sense.

I added [cog_customcom.rst](https://github.com/zephyrkul/Red-DiscordBot/blob/patch-1/docs/cog_customcom.rst) for documentation. Feel free to give it a read to make sure the documentation makes sense.
Zephyrkul commented 2018-08-27 19:27:26 +02:00 (Migrated from github.com)

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.

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.
Zephyrkul commented 2018-08-31 23:53:42 +02:00 (Migrated from github.com)

Any opinions on the above comment / PR?

Any opinions on the above comment / PR?
mikeshardmind commented 2018-09-01 01:08:15 +02:00 (Migrated from github.com)

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.

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.
mikeshardmind commented 2018-09-01 01:15:23 +02:00 (Migrated from github.com)

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.

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.
Redjumpman commented 2018-09-02 21:59:17 +02:00 (Migrated from github.com)

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.

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.
Redjumpman (Migrated from github.com) reviewed 2018-09-02 21:59:38 +02:00
Redjumpman (Migrated from github.com) left a comment
No description provided.
I encountered some behavior that might be troublesome for new users. If you put the numbering out of order or start with `1` instead of `0`, it will give a help message that doesn't really address what is happening. Here are some screenshots of what I am talking about: **Using 10 first and 0 last:** https://gyazo.com/a77a2df8a9b48b57daeba5f1ae2e1500 **Starting at 1 instead of 0:** https://gyazo.com/26b66081737a5bee2f3486f152ccbed7 Not sure if there is a good solution to that, but at the very list maybe slip in an added note that you need to start at 0, and the numbers must be sequential. As programmers we are used to things starting at 0, but it might not be natural to gen-pop. Lastly, I hate to pimp out your PR for this, especially since I know it isn't your fault, but would you care to freshen up the doc string for `cc add` ? https://gyazo.com/fce4b7d3f15ff4f06cfc720d168e5709
Zephyrkul commented 2018-09-03 07:43:41 +02:00 (Migrated from github.com)

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.

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.
Tobotimus (Migrated from github.com) approved these changes 2018-09-06 16:12:50 +02:00
Tobotimus (Migrated from github.com) left a comment

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.

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.
Sign in to join this conversation.
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 milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2051
No description provided.