properly unsubscribe member when being removed

This commit is contained in:
Luna 2021-08-30 23:52:35 -03:00
parent 43e34cde3a
commit 1819075137
2 changed files with 15 additions and 1 deletions

View File

@ -50,7 +50,11 @@ async def remove_member(guild_id: int, member_id: int):
user = await app.storage.get_user(member_id) user = await app.storage.get_user(member_id)
await app.dispatcher.guild.unsub(guild_id, member_id) states, channels = await app.dispatcher.guild.unsub_user(guild_id, user_id)
for channel_id in channels:
for state in states:
await app.dispatcher.channel.unsub(channel_id, state.session_id)
await app.lazy_guild.remove_member(guild_id, user["id"]) await app.lazy_guild.remove_member(guild_id, user["id"])
await app.dispatcher.guild.dispatch( await app.dispatcher.guild.dispatch(
guild_id, guild_id,

View File

@ -71,6 +71,16 @@ class GuildDispatcher(DispatcherWithState[int, str, GatewayEvent, List[str]]):
return states, channel_ids return states, channel_ids
async def unsub_user(
self, guild_id: int, user_id: int
) -> Tuple[List[GatewayState], List[int]]:
states = app.state_manager.fetch_states(user_id, guild_id)
for state in states:
await self.unsub(guild_id, state.session_id)
guild_chan_ids = await app.storage.get_channel_ids(guild_id)
return states, guild_chan_ids
async def dispatch_filter( async def dispatch_filter(
self, guild_id: int, filter_function, event: GatewayEvent self, guild_id: int, filter_function, event: GatewayEvent
): ):