Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

refactor!: command sync #112

Closed
wants to merge 8 commits into from
Closed

refactor!: command sync #112

wants to merge 8 commits into from

Conversation

VincentRPS
Copy link
Member

Summary

This PR refactors and moves the previous logic of ApplicationCommand.instantiate to state.sync_command to make command syncing and parsing easier.

I have not tested this yet.

Checklist

  • This PR has breaking changes
  • This PR fixes an issue
  • This is not a code change
  • If code changes were made they have been tested
  • I have properly changed the docs to appeal to this change

@VincentRPS VincentRPS added enhancement Improves a part of the library python Pull requests that update Python code labels Dec 26, 2022
@VincentRPS VincentRPS added this to the 3.0.0 milestone Dec 26, 2022
@VincentRPS VincentRPS self-assigned this Dec 26, 2022
Copy link
Collaborator

@EmmmaTech EmmmaTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can tell that you also ran formatting tools (black, isort, whatever else you're using) with this PR and it affected files that aren't relevant to this PR.

pycord/state/core.py Outdated Show resolved Hide resolved
pycord/state/core.py Show resolved Hide resolved
tasks.extend(self._process_global_command_for(command))
await asyncio.gather(*tasks)

async def _process_global_command_for(self, command: Command) -> list[Coroutine]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is command type hinted as Command if this is for application commands?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

people could make their own application command class without subclassing app command itself.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they shouldn't? The subclass wouldn't be an application command, it would just be a janky normal command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they shouldn't? The subclass wouldn't be an application command, it would just be a janky normal command.

ApplicationCommand isn't a base class, so using it would mean having to do some jank stuff to override functions and everything. It would be much easier for the user to just sub class Command which is a base class

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a logical perspective, it doesn't make sense. Whenever a user makes their own "custom application command" class, it's not going to even have the ApplicationCommand class as a parent. That means that the "custom application command" class isn't a custom application command class, it's a custom command class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need to be a custom application command, these just sync up commands which act like them

pycord/state/core.py Outdated Show resolved Hide resolved
pycord/state/core.py Show resolved Hide resolved
self.user.id, command.guild_id, True
)

for app_cmd in guild_commands:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this logic. Why is it looping through every application command found in a guild and performing operations on those application commands? Aren't we supposed to focus on the one application command this function was provided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this mainly: checks if a command named like that already exists in this guild, and if so edits instead of creating, and deletes commands which the bot shouldn't have.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the user could disable the behavior of deleting unknown application commands. Otherwise it would ruin bot setups where application commands are split between multiple different instances of the bot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the user could disable the behavior of deleting unknown application commands. Otherwise it would ruin bot setups where application commands are split between multiple different instances of the bot.

How? v3 supports that, and in any world this instance going up means that it's new and probably needs app commands globally refreshed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the user could disable the behavior of deleting unknown application commands. Otherwise it would ruin bot setups where application commands are split between multiple different instances of the bot.

How? v3 supports that, and in any world this instance going up means that it's new and probably needs app commands globally refreshed.

Have you heard of booleans, the client, and the state? The client's initializer should have a parameter that can enable or disable deleting unknown application commands. Then pass that to the state and you're done. I don't see what the problem is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I wasn't asking how to do it, I was asking how it would ruin instance-based bot setups

pycord/state/core.py Outdated Show resolved Hide resolved
pycord/state/core.py Show resolved Hide resolved
pycord/state/core.py Show resolved Hide resolved
@EmmmaTech EmmmaTech changed the title refactor: command sync refactor!: command sync Dec 26, 2022
Copy link
Collaborator

@baronkobama baronkobama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Altogether, the entirety of my review is reverting the out of scope changes made. While most of these changes should be made, let's put them in a separate formatting/code cleanup PR.

examples/interactions/commands/application_commands.py Outdated Show resolved Hide resolved
examples/interactions/commands/application_commands.py Outdated Show resolved Hide resolved
examples/interactions/commands/application_commands.py Outdated Show resolved Hide resolved
examples/interactions/commands/application_commands.py Outdated Show resolved Hide resolved
pycord/ext/gears/gear.py Outdated Show resolved Hide resolved
pycord/ext/gears/gear.py Outdated Show resolved Hide resolved
pycord/ext/gears/gear.py Outdated Show resolved Hide resolved
pycord/interaction.py Outdated Show resolved Hide resolved
pycord/ui/house.py Outdated Show resolved Hide resolved
pycord/ui/house.py Outdated Show resolved Hide resolved
VincentRPS and others added 5 commits December 31, 2022 16:21
Co-authored-by: baronkobama <baronkobama@gmail.com>
Signed-off-by: VincentRPS <vincentbusiness55@gmail.com>
Co-authored-by: baronkobama <baronkobama@gmail.com>
Signed-off-by: VincentRPS <vincentbusiness55@gmail.com>
Co-authored-by: Emre Terzioglu <50607143+EmreTech@users.noreply.github.com>
Signed-off-by: VincentRPS <vincentbusiness55@gmail.com>
pycord/state/core.py Outdated Show resolved Hide resolved
pycord/state/core.py Outdated Show resolved Hide resolved
return

if self._created is True:
await self.http.delete_global_application_command(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. Why does this delete the global command and not recreate it? After calling this HTTP function, the method just returns.

else:
return

if not created:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is created ever False anyways? All of the pathways the code takes where created is still False all return prematurely without this code being ran.

)

for app_cmd in guild_commands:
if app_cmd['name'] not in self._application_command_names:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute _application_command_names doesn't exist.

VincentRPS and others added 2 commits February 22, 2023 21:44
Co-authored-by: Emre Terzioglu <50607143+EmreTech@users.noreply.github.com>
Signed-off-by: VincentRPS <vincentbusiness55@gmail.com>
Co-authored-by: Emre Terzioglu <50607143+EmreTech@users.noreply.github.com>
Signed-off-by: VincentRPS <vincentbusiness55@gmail.com>
@pullapprove4
Copy link

pullapprove4 bot commented Jul 27, 2023

Please add a changelog entry

@VincentRPS VincentRPS closed this Aug 18, 2023
@VincentRPS VincentRPS deleted the sync branch September 30, 2023 09:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Improves a part of the library python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants