Skip to content
This repository was 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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 0 additions & 90 deletions pycord/commands/application/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,96 +527,6 @@ def _parse_arguments(self) -> None:
for option in self.options:
self._options.append(option.to_dict())

async def instantiate(self) -> None:
if self.guild_id:
guild_commands: list[
ApplicationCommandData
] = await self._state.http.get_guild_application_commands(
self._state.user.id, self.guild_id, True
)

for app_cmd in guild_commands:
if app_cmd['name'] not in self._state._application_command_names:
await self._state.http.delete_guild_application_command(
self._state.user.id, self.guild_id, app_cmd['id']
)
continue

if app_cmd['name'] == self.name and self._state.update_commands:
if app_cmd['type'] != self.type:
continue

if self._created is True:
await self._state.http.delete_guild_application_command(
self._state.user.id, self.guild_id, app_cmd['id']
)
continue

self.id = app_cmd['id']

await self._state.http.edit_guild_application_command(
self._state.user.id,
Snowflake(app_cmd['id']),
guild_id=self.guild_id,
name=self.name,
name_localizations=self.name_localizations,
description=self.description,
description_localizations=self.description_localizations,
type=self.type,
options=self._options,
)
self._created = True

if not self._created:
res = await self._state.http.create_guild_application_command(
self._state.user.id,
guild_id=self.guild_id,
name=self.name,
name_localizations=self.name_localizations,
description=self.description,
description_localizations=self.description_localizations,
type=self.type,
options=self._options,
)
self.id = res['id']

return

for app_cmd in self._state.application_commands:
if app_cmd['name'] == self.name and self._state.update_commands:
if app_cmd['type'] != self.type:
continue

if self._created is True:
await self._state.http.delete_global_application_command(
self._state.user.id, app_cmd['id']
)

await self._state.http.edit_global_application_command(
self._state.user.id,
Snowflake(app_cmd['id']),
name=self.name,
name_localizations=self.name_localizations,
description=self.description,
description_localizations=self.description_localizations,
type=self.type,
options=self._options,
)
self._created = True
self.id = app_cmd['id']

if not self._created:
res = await self._state.http.create_global_application_command(
self._state.user.id,
name=self.name,
name_localizations=self.name_localizations,
description=self.description,
description_localizations=self.description_localizations,
type=self.type,
options=self._options,
)
self.id = res['id']

def _process_options(
self, interaction: Interaction, options: list[InteractionOption]
) -> dict[str, Any]:
Expand Down
4 changes: 2 additions & 2 deletions pycord/ext/gears/gear.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# SOFTWARE
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Type, TypeVar, Generic
from typing import TYPE_CHECKING, Any, Generic, Type, TypeVar

from ...commands import Command, Group
from ...types import AsyncFunc
Expand All @@ -35,7 +35,7 @@
class BaseContext(SimpleNamespace):
...

ContextT = TypeVar("ContextT", bound=BaseContext)
ContextT = TypeVar('ContextT', bound=BaseContext)


class Gear(Generic[ContextT]):
Expand Down
Loading