From eedc30fabc3033537d8152973aa071d258bce2cf Mon Sep 17 00:00:00 2001 From: V3ntus <29584664+V3ntus@users.noreply.github.com> Date: Tue, 29 Mar 2022 15:03:51 -0500 Subject: [PATCH 1/4] fix: prevent kwargs modification during `for` loop iteration --- interactions/api/models/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/api/models/misc.py b/interactions/api/models/misc.py index 903e77438..d6385a8ef 100644 --- a/interactions/api/models/misc.py +++ b/interactions/api/models/misc.py @@ -36,7 +36,7 @@ def __init__(self, **kwargs): # for key in kwargs: # setattr(self, key, kwargs[key]) - for key in kwargs: + for key in list(kwargs): if key in self.__slots__ if hasattr(self, "__slots__") else True: # else case if the mixin is used outside of this library and/or SDK. setattr(self, key, kwargs[key]) From 7556d31f8620f57d5a63dd40aa97f377491aa329 Mon Sep 17 00:00:00 2001 From: V3ntus <29584664+V3ntus@users.noreply.github.com> Date: Sat, 23 Apr 2022 12:47:16 -0500 Subject: [PATCH 2/4] fix: proper empty choices parsing for autocomplete --- interactions/client/context.py | 51 ++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/interactions/client/context.py b/interactions/client/context.py index 2c287c014..d8bac9cdd 100644 --- a/interactions/client/context.py +++ b/interactions/client/context.py @@ -518,32 +518,35 @@ async def populate(self, choices: Union[Choice, List[Choice]]) -> List[Choice]: """ async def func(): - if choices: - _choices: list = [] - if all(isinstance(choice, Choice) for choice in choices): - _choices = [choice._json for choice in choices] - elif all( - isinstance(choice, dict) and all(isinstance(x, str) for x in choice) - for choice in choices - ): - _choices = list(choices) - elif isinstance(choices, Choice): - _choices = [choices._json] - else: - raise InteractionException( - 6, message="Autocomplete choice items must be of type Choice" - ) - - await self.client.create_interaction_response( - token=self.token, - application_id=int(self.id), - data={ - "type": InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT.value, - "data": {"choices": _choices}, - }, + log.debug("Populating choices...") + _choices: Union[list, None] = [] + + if not choices or (isinstance(choices, list) and len(choices) == 0): + _choices = None + elif isinstance(choices, Choice): + _choices.append(choices._json) + elif isinstance(choices, list) and all(isinstance(choice, Choice) for choice in choices): + _choices = [choice._json for choice in choices] + elif all( + isinstance(choice, dict) and all(isinstance(x, str) for x in choice) + for choice in choices + ): + _choices = list(choices) + else: + raise InteractionException( + 6, message="Autocomplete choice items must be of type Choice" ) - return _choices + await self.client.create_interaction_response( + token=self.token, + application_id=int(self.id), + data={ + "type": InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT.value, + "data": {"choices": _choices}, + }, + ) + + return _choices return await func() From 15fedb936f70c0a9d07e3fd0e3ff67648c1aa427 Mon Sep 17 00:00:00 2001 From: V3ntus <29584664+V3ntus@users.noreply.github.com> Date: Sat, 23 Apr 2022 12:49:58 -0500 Subject: [PATCH 3/4] pre-commit: black refactor --- interactions/client/context.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interactions/client/context.py b/interactions/client/context.py index d8bac9cdd..2e6476570 100644 --- a/interactions/client/context.py +++ b/interactions/client/context.py @@ -525,7 +525,9 @@ async def func(): _choices = None elif isinstance(choices, Choice): _choices.append(choices._json) - elif isinstance(choices, list) and all(isinstance(choice, Choice) for choice in choices): + elif isinstance(choices, list) and all( + isinstance(choice, Choice) for choice in choices + ): _choices = [choice._json for choice in choices] elif all( isinstance(choice, dict) and all(isinstance(x, str) for x in choice) From a1a6efa85833f264863fd4ce596ef2ba59c566b7 Mon Sep 17 00:00:00 2001 From: V3ntus <29584664+V3ntus@users.noreply.github.com> Date: Sat, 23 Apr 2022 12:51:29 -0500 Subject: [PATCH 4/4] oops: remove extra debug logging --- interactions/client/context.py | 1 - 1 file changed, 1 deletion(-) diff --git a/interactions/client/context.py b/interactions/client/context.py index 2e6476570..3e9677efb 100644 --- a/interactions/client/context.py +++ b/interactions/client/context.py @@ -518,7 +518,6 @@ async def populate(self, choices: Union[Choice, List[Choice]]) -> List[Choice]: """ async def func(): - log.debug("Populating choices...") _choices: Union[list, None] = [] if not choices or (isinstance(choices, list) and len(choices) == 0):