Skip to content

Commit 71cda2d

Browse files
EepyElvyramAxYoLo01pre-commit-ci[bot]
authored
feat!: Add a guild id property for the member object (#1025)
* feat!: Add a guild id property for the member object * Update interactions/api/models/member.py Co-authored-by: Max <maxyolo01.ytb@gmail.com> * ci: correct from checks. * ref: use self._extras * ci: correct from checks. * ref: raise an exception when not present * ci: correct from checks. * Update gw.py * Update member.py * feat: ensure a guild_id in _extras whenever possible Co-authored-by: Max <maxyolo01.ytb@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent fafce55 commit 71cda2d

File tree

7 files changed

+165
-341
lines changed

7 files changed

+165
-341
lines changed

interactions/api/http/member.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def get_member(self, guild_id: int, member_id: int) -> Optional[dict]:
3535
)
3636
)
3737

38-
member = Member(**res, _client=self)
38+
member = Member(**res, _client=self, guild_id=Snowflake(guild_id))
3939
guild = self.cache[Guild].get(Snowflake(guild_id))
4040
if guild.members is None:
4141
guild.members = [member]
@@ -68,9 +68,13 @@ async def get_list_of_members(
6868
res = await self._req.request(Route("GET", f"/guilds/{guild_id}/members"), params=payload)
6969
guild = self.cache[Guild].get(Snowflake(guild_id))
7070
if guild.members is None:
71-
guild.members = [Member(**_res, _client=self) for _res in res]
71+
guild.members = [
72+
Member(**_res, _client=self, guild_id=Snowflake(guild_id)) for _res in res
73+
]
7274
else:
73-
for member in [Member(**_res, _client=self) for _res in res]:
75+
for member in [
76+
Member(**_res, _client=self, guild_id=Snowflake(guild_id)) for _res in res
77+
]:
7478
for index, _member in enumerate(guild.members):
7579
if _member.id == member.id:
7680
guild.members[index] = member

interactions/api/models/guild.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ def __attrs_post_init__(self): # sourcery skip: last-if-guard
361361
if not self.presences:
362362
self.presences = guild.presences
363363

364+
if self.members:
365+
for member in self.members:
366+
if not member._extras.get("guild_id"):
367+
member._extras["guild_id"] = self.id
368+
364369
def __repr__(self) -> str:
365370
return self.name
366371

@@ -578,7 +583,7 @@ async def get_member(
578583
guild_id=int(self.id),
579584
member_id=int(member_id),
580585
)
581-
member = Member(**res, _client=self._client)
586+
member = Member(**res, _client=self._client, guild_id=self.id)
582587
if self.members is None:
583588
self.members = []
584589
for index, _member in enumerate(self.members):
@@ -1098,7 +1103,7 @@ async def modify_member(
10981103
reason=reason,
10991104
)
11001105

1101-
_member = Member(**res, _client=self._client)
1106+
_member = Member(**res, _client=self._client, guild_id=self.id)
11021107
if self.members is None:
11031108
self.members = []
11041109
for index, member in enumerate(self.members):
@@ -2038,7 +2043,7 @@ async def get_list_of_members(
20382043
res = await self._client.get_list_of_members(
20392044
guild_id=int(self.id), limit=limit, after=_after
20402045
)
2041-
_members = [Member(**member, _client=self._client) for member in res]
2046+
_members = [Member(**member, _client=self._client, guild_id=self.id) for member in res]
20422047
if self.members is None:
20432048
self.members = []
20442049
for member in _members:
@@ -2062,7 +2067,7 @@ async def search_members(self, query: str, limit: Optional[int] = 1) -> List[Mem
20622067
res = await self._client.search_guild_members(
20632068
guild_id=int(self.id), query=query, limit=limit
20642069
)
2065-
return [Member(**member, _client=self._client) for member in res]
2070+
return [Member(**member, _client=self._client, guild_id=self.id) for member in res]
20662071

20672072
async def get_all_members(self) -> List[Member]:
20682073
"""
@@ -2089,7 +2094,7 @@ async def get_all_members(self) -> List[Member]:
20892094
guild_id=int(self.id), limit=100, after=int(_last_member.id)
20902095
)
20912096
_all_members.extend(_members)
2092-
self.members = [Member(**_, _client=self._client) for _ in _all_members]
2097+
self.members = [Member(**_, _client=self._client, guild_id=self.id) for _ in _all_members]
20932098
return self.members
20942099

20952100
async def get_webhooks(self) -> List[Webhook]:

0 commit comments

Comments
 (0)