refactor app command sync and other fixes - #666
Conversation
7540d25 to
2df688b
Compare
a87bd19 to
4ae21f8
Compare
083284f to
360fcee
Compare
4ae21f8 to
3d1a96d
Compare
|
Not sure what happened here, merging #667 resulted in GitHub automatically closing this PR, instead of changing the base branch to master like it should've:
This worked fine in #616 - in any case, GitHub doesn't allow reopening this PR, looks like you may have to recreate it, sorry :/ |
|
... should be fixed except for merge conflicts, thanks to https://github.com/github/docs/discussions/18311. |
EQUENOS
left a comment
There was a problem hiding this comment.
Great job! Here're some comments:
| if disnake.utils.get( | ||
| self._all_app_commands, | ||
| name=slash_command.name, | ||
| type=slash_command.type, | ||
| guild_id=guild_id, | ||
| ): | ||
| raise CommandRegistrationError(slash_command.name, guild_id=guild_id) | ||
| self._all_app_commands[ | ||
| AppCommandMetadata(slash_command.name, guild_id, slash_command.type) | ||
| ] = slash_command |
There was a problem hiding this comment.
What if we construct a named tuple here and use it as a key to check the existence? Like so:
command_metadata = AppCommandMetadata(slash_command.name, guild_id, slash_command.type)
if command_metadata in self._all_app_commands:
raise CommandRegistrationError(slash_command.name, guild_id=guild_id)
self._all_app_commands[command_metadata] = slash_commandSame for similar samples below
| command: InvokableSlashCommand = self._all_app_commands.pop(meta, None) # type: ignore | ||
| if command is None: | ||
| return None | ||
| return command |
There was a problem hiding this comment.
| command: InvokableSlashCommand = self._all_app_commands.pop(meta, None) # type: ignore | |
| if command is None: | |
| return None | |
| return command | |
| return self._all_app_commands.pop(meta, None) # type: ignore |
| command: InvokableUserCommand = self._all_app_commands.pop(meta, None) # type: ignore | ||
| if command is None: | ||
| return None | ||
| return command |
There was a problem hiding this comment.
Same suggestion as above. Same for similar samples
|
|
||
| all_commands = self._all_app_commands | ||
| for api_command in self._connection._global_application_commands.values(): | ||
| cmdmeta = disnake.utils.get(all_commands, name=api_command.name, guild_id=None) |
There was a problem hiding this comment.
Again, we can speed this up by constructing meta first and then checking if it's in the dict:
cmdmeta = AppCommandMetadata(api_command.name, api_command.type, None)
cmd = all_commands.get(cmdmeta)
if cmd is None:
continuedd2a89d to
09fcf9b
Compare
18e5271 to
d83abf8
Compare
|
@onerandomusername Could you resolve the conflicts in this PR? |
resolves disnake#260
6266281 to
7eda7e4
Compare
This reverts commit 237ac58.
b041cdf to
3f94527
Compare
3f94527 to
7115195
Compare
| res = await self._connection.bulk_overwrite_global_commands(application_commands) | ||
|
|
||
| for api_command in res: | ||
| cmd = utils.get(application_commands, name=api_command.name) |
There was a problem hiding this comment.
It's possible to have 2 app commands of different types (or guilds) with identical names, so this should be modified
|
|
||
|
|
||
| class InvokableUserCommand(InvokableApplicationCommand): | ||
| class InvokableUserCommand(InvokableApplicationCommand, UserCommand): |
There was a problem hiding this comment.
What's the point of subclassing UserCommand? The chain of super() calls never reaches it (see InvokableApplicationCommand.__init__) and it doesn't seem to make any typing improvements
|
Since this has become somewhat outdated, and given the number of merge conflicts that have cropped up, I believe this can be closed in favour of #1107 - nonetheless, thanks for the work on this PR c: |
Summary
Refactors app command sync and lays the groundwork to implement GH-665 (but doesn't do it as of now)
Checklist
I have not extensively tested or caught most cases, but a review (even in this condition) would be appreciated
task linttask pyright