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

fix: remove member from guild/cache on remove #603

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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