Skip to content

Commit 35f475d

Browse files
refactor: add missed http clients and some optimizing (#1189)
* refactor: add missed http clients and some optimizing * ci: correct from checks. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 55ffe96 commit 35f475d

File tree

3 files changed

+30
-39
lines changed

3 files changed

+30
-39
lines changed

interactions/api/gateway/ratelimit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
log = logging.getLogger("gateway.ratelimit")
88

9+
__all__ = ("WSRateLimit",)
10+
911

1012
class WSRateLimit:
1113
"""

interactions/api/models/gw.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class ApplicationCommandPermission(DictSerializerMixin):
132132
133133
.. code-block:: python
134134
135-
interactions.Permission(
135+
interactions.ApplicationCommandPermission(
136136
id=1234567890,
137137
type=interactions.PermissionType.USER,
138138
permission=True,
@@ -147,9 +147,6 @@ class ApplicationCommandPermission(DictSerializerMixin):
147147
type: PermissionType = field(converter=PermissionType)
148148
permission: bool = field()
149149

150-
def __attrs_post_init__(self):
151-
self._json["type"] = self.type.value
152-
153150

154151
@define()
155152
class ApplicationCommandPermissions(ClientSerializerMixin, IDMixin):
@@ -219,7 +216,7 @@ class GuildBan(ClientSerializerMixin):
219216
"""
220217

221218
guild_id: Snowflake = field(converter=Snowflake)
222-
user: User = field(converter=User)
219+
user: User = field(converter=User, add_client=True)
223220

224221

225222
@define()
@@ -232,7 +229,7 @@ class GuildEmojis(ClientSerializerMixin):
232229
"""
233230

234231
guild_id: Snowflake = field(converter=Snowflake)
235-
emojis: List[Emoji] = field(converter=convert_list(Emoji))
232+
emojis: List[Emoji] = field(converter=convert_list(Emoji), add_client=True)
236233

237234

238235
@define()
@@ -334,9 +331,8 @@ class GuildRole(ClientSerializerMixin):
334331
"""
335332

336333
guild_id: Snowflake = field(converter=Snowflake)
337-
role: Optional[Role] = field(converter=Role, default=None)
334+
role: Optional[Role] = field(converter=Role, add_client=True, default=None)
338335
role_id: Optional[Snowflake] = field(converter=Snowflake, default=None)
339-
guild_hashes = field() # TODO: investigate what this is.
340336

341337

342338
@define()

interactions/client/context.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -649,39 +649,32 @@ async def populate(self, choices: Union[Choice, List[Choice]]) -> List[Choice]:
649649
:rtype: List[Choice]
650650
"""
651651

652-
async def func():
653-
_choices: Union[list, None] = []
654-
655-
if not choices or (isinstance(choices, list) and len(choices) == 0):
656-
_choices = None
657-
elif isinstance(choices, Choice):
658-
_choices.append(choices._json)
659-
elif isinstance(choices, list) and all(
660-
isinstance(choice, Choice) for choice in choices
661-
):
662-
_choices = [choice._json for choice in choices]
663-
elif all(
664-
isinstance(choice, dict) and all(isinstance(x, str) for x in choice)
665-
for choice in choices
666-
):
667-
_choices = list(choices)
668-
else:
669-
raise LibraryException(
670-
6, message="Autocomplete choice items must be of type Choice"
671-
)
672-
673-
await self._client.create_interaction_response(
674-
token=self.token,
675-
application_id=int(self.id),
676-
data={
677-
"type": InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT.value,
678-
"data": {"choices": _choices},
679-
},
680-
)
652+
_choices: Union[list, None] = []
653+
654+
if not choices or (isinstance(choices, list) and len(choices) == 0):
655+
_choices = None
656+
elif isinstance(choices, Choice):
657+
_choices.append(choices._json)
658+
elif isinstance(choices, list) and all(isinstance(choice, Choice) for choice in choices):
659+
_choices = [choice._json for choice in choices]
660+
elif all(
661+
isinstance(choice, dict) and all(isinstance(x, str) for x in choice)
662+
for choice in choices
663+
):
664+
_choices = list(choices)
665+
else:
666+
raise LibraryException(6, message="Autocomplete choice items must be of type Choice")
681667

682-
return _choices
668+
await self._client.create_interaction_response(
669+
token=self.token,
670+
application_id=int(self.id),
671+
data={
672+
"type": InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT.value,
673+
"data": {"choices": _choices},
674+
},
675+
)
683676

684-
return await func()
677+
return _choices
685678

686679

687680
@define()

0 commit comments

Comments
 (0)