fix: Command Auto Syncing#2990
fix: Command Auto Syncing#2990Icebluewolf wants to merge 5 commits intoPycord-Development:masterfrom
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/2990/head:pr-2990
git checkout pr-2990This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/2990/head |
|
@Icebluewolf Feel free to mark this as ready for review once you think it is ready, note the linter failing in the gh actions |
|
Do you think that #1745 could be addressed here as well ? |
|
I updated the gist in the description to include a test file I do expect to do some cleanup tasks as well |
| # We can suggest the user to upsert, edit, delete, or bulk upsert the commands | ||
|
|
||
| def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool: | ||
| cmd = cmd.to_dict() |
There was a problem hiding this comment.
Don't reassign a different type to the same variable
| _log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class DefaultComparison: |
There was a problem hiding this comment.
It's a bit silly but I think this should return True if both are equivalent and False in the opposite case. From what I can understand it does the opposite right now which I found a bit confusing at first.
| return super().check(local, remote) | ||
|
|
||
|
|
||
| NestedComparison: TypeAlias = dict[str, Union["NestedComparison", DefaultComparison]] |
There was a problem hiding this comment.
Use | syntax instead of Union
| return False | ||
|
|
||
|
|
||
| option_default_values = ([], MISSING) |
There was a problem hiding this comment.
Should be capitalized (constant from what I could see)
| ) | ||
|
|
||
|
|
||
| choices_default_values = ([], MISSING) |
| (MISSING, {0, 1}), lambda x, y: set(x) != set(y) | ||
| ), | ||
| # Discord States That This Defaults To "your app's configured contexts" | ||
| "contexts": DefaultSetComparison( |
There was a problem hiding this comment.
Could we fetch our app info and then fill it based on that ? See @Lumabots 's appinfo PR. Or would that not work ?
Summary
This is very much a draft and needs lots of testing. I just want to put it somewhere public so that I can get eyes on it.
This is something I am not quite sure how to cleanly fix at the moment.
I also need to check what the behavior is for undocumented fields in the payload from discord that may be added in the future. I believe the best option is to ignore those fields.
This gist (https://gist.github.com/Icebluewolf/1842ea5f7234ba40e5df18191bb135a0) contains 2 files. The first is where I developed the fix so that I did not have to make real API calls and is here for reference if someone wants to do the same. The second is unit tests for the new system. Both are very rough and messy sorry 🙃. This change needs to be tested extensively, so if someone sees test cases I missed or more test cases that should be added please let me know.
This PR attempts to fix the long running issue with the application command auto-syncing system. Currently the system is over eager and preforms upserts on commands that do not need to be updated. The main culprit is incorrect default value checking. This PR implements a more robust and easily extendable comparison system for commands.
Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.