Skip to content

Commit

Permalink
fix: Fix option/choice order sync, redo _pos calculation. (#882)
Browse files Browse the repository at this point in the history
* fix: Fix option/choice order sync, redo _pos calculation.

* fix: Tweak variable reference.
  • Loading branch information
FayeDel committed Jun 25, 2022
1 parent de13a9e commit e8568df
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions interactions/client/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
_token: str = "" # noqa
_cache: Optional[Cache] = None


__all__ = (
"Client",
"Extension",
Expand Down Expand Up @@ -247,6 +246,11 @@ def __check_options(command, data):
return False, command
else:
continue

for i, __name in enumerate(_option_choice_names):
if _data_choice_names[i] != __name:
return False, command

elif option_attr == "required":
if (
option.get(option_attr) == None # noqa: E711
Expand All @@ -266,6 +270,11 @@ def __check_options(command, data):
return False, command
else:
continue

for i, __name in enumerate(_command_option_names):
if _data_option_names[i] != __name:
return False, command

return True, command

for command in pool:
Expand Down Expand Up @@ -508,8 +517,18 @@ async def __sync(self) -> None: # sourcery no-metrics
)
if not clean:
self.__guild_commands[_guild_id]["clean"] = False
_pos = self.__guild_commands[_guild_id]["commands"].index(_command)
self.__guild_commands[_guild_id]["commands"][_pos] = _guild_command
# _pos = self.__guild_commands[_guild_id]["commands"].index(_command)
# self.__guild_commands[_guild_id]["commands"][_pos] = _guild_command

for _pos, _dict in enumerate(
self.__guild_commands[_guild_id]["commands"]
):
if _dict["name"] == _command["name"]:
self.__guild_commands[_guild_id]["commands"][
_pos
] = _guild_command
break

if __check_guild_commands[_guild_id]:
del __check_guild_commands[_guild_id][
__check_guild_commands[_guild_id].index(_guild_command["name"])
Expand All @@ -522,8 +541,14 @@ async def __sync(self) -> None: # sourcery no-metrics

if not clean:
self.__global_commands["clean"] = False
_pos = self.__global_commands["commands"].index(_command)
self.__global_commands["commands"][_pos] = coro._command_data
# _pos = self.__global_commands["commands"].index(_command)
# self.__global_commands["commands"][_pos] = coro._command_data

for _pos, _dict in enumerate(self.__global_commands["commands"]):
if _dict["name"] == _command["name"]:
self.__global_commands["commands"][_pos] = coro._command_data
break

if __check_global_commands:
del __check_global_commands[
__check_global_commands.index(coro._command_data["name"])
Expand Down Expand Up @@ -1459,7 +1484,6 @@ async def __raw_guild_create(self, guild) -> dict:


class AutocompleteManager:

__slots__ = (
"client",
"command_name",
Expand Down

0 comments on commit e8568df

Please sign in to comment.