Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
fix: remove member from guild/cache on remove (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstreaTSS authored Aug 15, 2022
1 parent 1d32ada commit 448828d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion naff/api/events/processors/member_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ async def _on_raw_guild_member_add(self, event: "RawGatewayEvent") -> None:
async def _on_raw_guild_member_remove(self, event: "RawGatewayEvent") -> None:
g_id = event.data.pop("guild_id")
user = self.cache.place_user_data(event.data["user"])
member = self.cache.get_member(g_id, user.id)

self.cache.delete_member(g_id, user.id)
guild = self.cache.get_guild(g_id)
guild.member_count -= 1
self.dispatch(events.MemberRemove(g_id, self.cache.get_member(g_id, user.id) or user))

self.dispatch(events.MemberRemove(g_id, member or user))

@Processor.define()
async def _on_raw_guild_member_update(self, event: "RawGatewayEvent") -> None:
Expand Down
4 changes: 3 additions & 1 deletion naff/client/smart_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def delete_member(self, guild_id: "Snowflake_Type", user_id: "Snowflake_Type") -
user_id = to_snowflake(user_id)
guild_id = to_snowflake(guild_id)

self.member_cache.pop((guild_id, user_id), None)
if member := self.member_cache.pop((guild_id, user_id), None):
member.guild._member_ids.discard(user_id)

self.delete_user_guild(user_id, guild_id)

def place_user_guild(self, user_id: "Snowflake_Type", guild_id: "Snowflake_Type") -> None:
Expand Down

0 comments on commit 448828d

Please sign in to comment.