mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
on_guild_remove and on_guilds_update listeners
This commit is contained in:
parent
a371653a7d
commit
bc17864e3a
2 changed files with 57 additions and 0 deletions
28
melisa/listeners/guild_remove.py
Normal file
28
melisa/listeners/guild_remove.py
Normal 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
|
29
melisa/listeners/guild_update.py
Normal file
29
melisa/listeners/guild_update.py
Normal 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
|
Loading…
Reference in a new issue