on_guild_remove and on_guilds_update listeners

This commit is contained in:
grey-cat-1908 2022-03-22 17:06:27 +03:00
parent a371653a7d
commit bc17864e3a
2 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1,28 @@
# Copyright MelisaDev 2022 - Present
# Full MIT License can be found in `LICENSE.txt` at the project root.
from __future__ import annotations
import asyncio
from ..utils.types import Coro
from ..models.guild import UnavailableGuild
async def guild_delete_listener(self, gateway, payload: dict):
gateway.session_id = payload.get("session_id")
guild = UnavailableGuild.from_dict(payload)
self.guilds.pop(guild.id, None)
custom_listener = self._events.get("on_guild_remove")
if custom_listener is not None:
asyncio.ensure_future(custom_listener(guild))
return
def export() -> Coro:
return guild_delete_listener

View file

@ -0,0 +1,29 @@
# Copyright MelisaDev 2022 - Present
# Full MIT License can be found in `LICENSE.txt` at the project root.
from __future__ import annotations
import asyncio
from ..utils.types import Coro
from ..models.guild import Guild
async def guild_update_listener(self, gateway, payload: dict):
gateway.session_id = payload.get("session_id")
new_guild = Guild.from_dict(payload)
old_guild = self.guilds.get(new_guild.id)
self.guilds[new_guild.id] = new_guild
custom_listener = self._events.get("on_guild_update")
if custom_listener is not None:
asyncio.ensure_future(custom_listener(old_guild, new_guild))
return
def export() -> Coro:
return guild_update_listener