-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor app command sync and other fixes #666
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_command
Same 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
continue
dd2a89d
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to have 2 app commands of different types (or guilds) with identical names, so this should be modified
@@ -30,7 +31,7 @@ | |||
__all__ = ("InvokableUserCommand", "InvokableMessageCommand", "user_command", "message_command") | |||
|
|||
|
|||
class InvokableUserCommand(InvokableApplicationCommand): | |||
class InvokableUserCommand(InvokableApplicationCommand, UserCommand): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 lint
task pyright