pycord
pycord copied to clipboard
feat: implement Invokable & BaseContext
Description
Even though app commands and text commands share many features, some are only implemented on one of the two AND a huge chunk of these features get re-implemented each time they get used. Invokables make it easier to share common features between the 2. BaseContext does the same but for contexts. ApplicationCommand
and ext.commands.Command
are now both subclassed from Invokable
. Same thing with ApplicationContext
and ext.commands.Context
with BaseContext
.
This tries to be as least breaking as possible btw. But should probably be tested before merging.
Now that I see it, this is kind of related to #387
Summary
(Possible) breaking/Important changes are highlighted
Additions because of Parity:
-
Remove all uses of
_invoke
:- App Contexts now have the
args
andkwargs
attributes for argument passing. These arguments are prepared in.prepare
and then passed by.invoke
, just like in ext.commands. - Argument parsing has been moved to
._parse_arguments
which is called by.prepare
, just like ext.commands
- App Contexts now have the
- App commands now have access to:
- The
parents
,root_parent
,cog_name
properties - The
.error
decorator. - The
cooldown_after_parsing
attribute & parameter.
- The
-
ApplicationContext
now has thereinvoke
method. - Ported many other
ext.commands.Context
misc attributes related to invocation. - ~~App commands do not run their parent's checks anymore for parity.~~ With #2139 I realized this could be useful with slash commands
Other Additions:
-
BaseContext
provides.source
now as a way to get either message or interaction on their respective contexts.- Contexts now share a bunch of properties
Improvements from Parity:
-
Cooldown functionality was moved to the
discord/commands
folder (ext.commands.cooldown now acts as an alias). -
Moved some command related errors to discord/errors.
- These are also aliased in ext/commands/errors
- Make a more organized error hierarchy.
- Deprecated application command errors
- Helper methods (
wrap_callback
,unwrap_callback
, andhooked_wrapped_callback
) are now not duplicated.
Other Improvements:
-
qualified_name
andfull_parent_name
now use recursion by attributes instead of with a while loop. - Document
ContextMenuCommand
- Remove some of the copy functions in favor of built-in copy function (needs testing)
- Renamed
dispatch_error
to_dispatch_error
(and subsequently_dispatch_error
is now__dispatch_error
). - ~~Renamed
prepare
for command object & help impl. to_prepare
.~~ - ~~Renamed
call_before_hooks
&call_after_hooks
in the command objects to_call_before_hooks
&_call_after_hooks
.~~
Information
- [x] This PR fixes an issue.
- [x] This PR adds something new (e.g. new method or parameters).
- [x] This PR is a breaking change (e.g. methods or parameters removed/renamed).
- [x] If code changes were made then they have been tested.
- [x] I have updated the documentation to reflect the changes.
Merge conflicts 👀
App commands do not their parent's checks anymore for parity.
Lmao "do not their"
One more thing: adding in two status tags doesn't make sense to me In progress is for PRs that are in progress and not ready for review. Awaiting for review is for PRs that are pretty much ready but need review in order to merge (The branch protection)
[docs] Whether or not subclassed objects should show parent's attributes. (very important)
Sorry I noticed one last thing This topic is a bit of a vague one since this can apply past the commands system in Pycord We should debate this topic maybe in the Discord server or in an issue
I want to look further into this PR before it's merged. Particularly, I want to look into the separation of the base library from the ext libraries. For 2.0, we followed the design standard of making the base library completely independent of ext libs, while the ext libs depend on the main lib. As I understand this doesn't change that, but I also want to make sure that no unnecessary features from ext.commands are added to the main lib.
Codecov Report
Merging #1606 (3fd4d08) into master (75bc6fe) will increase coverage by
0.13%
. The diff coverage is30.57%
.
:exclamation: Current head 3fd4d08 differs from pull request most recent head dad7772. Consider uploading reports for the commit dad7772 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #1606 +/- ##
==========================================
+ Coverage 33.23% 33.37% +0.13%
==========================================
Files 95 97 +2
Lines 18423 18678 +255
==========================================
+ Hits 6123 6233 +110
- Misses 12300 12445 +145
Flag | Coverage Δ | |
---|---|---|
pytest | 33.37% <30.57%> (+0.13%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
Impacted Files | Coverage Δ | |
---|---|---|
discord/bot.py | 18.31% <0.00%> (ø) |
|
discord/scheduled_events.py | 31.14% <0.00%> (-0.56%) |
:arrow_down: |
discord/commands/mixins.py | 25.78% <25.78%> (ø) |
|
discord/errors.py | 38.93% <32.60%> (-0.88%) |
:arrow_down: |
discord/commands/cooldowns.py | 34.00% <34.00%> (ø) |
|
discord/commands/context.py | 46.34% <38.88%> (-1.64%) |
:arrow_down: |
discord/commands/core.py | 19.75% <45.45%> (+1.57%) |
:arrow_up: |
discord/cog.py | 35.29% <100.00%> (ø) |
|
discord/commands/__init__.py | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 75bc6fe...dad7772. Read the comment docs.
@Middledot please fix merge conflicts and review these suggestions
Please fix merge conflicts
stale
Codecov Report
Merging #1606 (45c2e96) into master (297053d) will decrease coverage by
0.57%
. The diff coverage is31.63%
.
:exclamation: Current head 45c2e96 differs from pull request most recent head c4154a1. Consider uploading reports for the commit c4154a1 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #1606 +/- ##
==========================================
- Coverage 33.86% 33.29% -0.57%
==========================================
Files 109 99 -10
Lines 22367 19391 -2976
==========================================
- Hits 7575 6457 -1118
+ Misses 14792 12934 -1858
Flag | Coverage Δ | |
---|---|---|
macos-latest-3.10 | 33.28% <31.63%> (-0.57%) |
:arrow_down: |
macos-latest-3.11 | 33.28% <31.63%> (-0.57%) |
:arrow_down: |
macos-latest-3.8 | 33.29% <31.68%> (-0.56%) |
:arrow_down: |
macos-latest-3.9 | 33.29% <31.68%> (-0.56%) |
:arrow_down: |
ubuntu-latest-3.10 | 33.28% <31.63%> (-0.57%) |
:arrow_down: |
ubuntu-latest-3.11 | 33.28% <31.63%> (-0.57%) |
:arrow_down: |
ubuntu-latest-3.8 | 33.29% <31.68%> (-0.56%) |
:arrow_down: |
ubuntu-latest-3.9 | 33.29% <31.68%> (-0.56%) |
:arrow_down: |
windows-latest-3.10 | 33.28% <31.63%> (-0.57%) |
:arrow_down: |
windows-latest-3.11 | 33.28% <31.63%> (-0.57%) |
:arrow_down: |
windows-latest-3.8 | 33.29% <31.68%> (-0.56%) |
:arrow_down: |
windows-latest-3.9 | 33.29% <31.68%> (-0.56%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
Impacted Files | Coverage Δ | |
---|---|---|
discord/bot.py | 18.45% <0.00%> (-7.98%) |
:arrow_down: |
discord/scheduled_events.py | 30.89% <0.00%> (-0.56%) |
:arrow_down: |
discord/commands/mixins.py | 27.22% <27.22%> (ø) |
|
discord/errors.py | 39.06% <32.55%> (-0.75%) |
:arrow_down: |
discord/commands/cooldowns.py | 34.00% <34.00%> (ø) |
|
discord/commands/context.py | 49.16% <38.88%> (-1.18%) |
:arrow_down: |
discord/commands/core.py | 19.75% <47.82%> (-20.55%) |
:arrow_down: |
discord/cog.py | 34.64% <100.00%> (-9.19%) |
:arrow_down: |
discord/commands/__init__.py | 100.00% <100.00%> (ø) |
... and 26 files with indirect coverage changes
Continue to review full report in Codecov by Sentry.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 9926ef5...c4154a1. Read the comment docs.
Yes, I didn't work on this for a few months now. I plan to finish this for v2.5. The last things to do for now are to:
- Test it on actual bots
- Deprecate for removal next version
- Fix the list of changes & finalize the docs (for me)
I wasn't sure about adding an underscore to the prepare and call_*_hooks functions, so I reverted that. Otherwise, this is done and ready for review basically!
Pushing this to v2.6
BaseCommand could be more fitting than Invokable.