mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
some things with guild model and events
This commit is contained in:
parent
b8faa2df8a
commit
49d2a5f899
3 changed files with 19 additions and 5 deletions
|
@ -47,7 +47,7 @@ class Client:
|
|||
self._events: Dict[str, Coro] = {}
|
||||
|
||||
# ToDo: Transfer guilds in to the cache manager
|
||||
self.guilds = []
|
||||
self.guilds = {}
|
||||
self.user = None
|
||||
|
||||
self._loop = asyncio.get_event_loop()
|
||||
|
@ -59,6 +59,7 @@ class Client:
|
|||
|
||||
self._activity = activity
|
||||
self._status = status
|
||||
self._none_guilds_cached = False
|
||||
|
||||
APIModelBase.set_client(self)
|
||||
|
||||
|
|
|
@ -3,18 +3,28 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from ..utils.types import Coro
|
||||
from ..models.guild import Guild
|
||||
|
||||
|
||||
async def guild_create_listener(self, gateway, payload: dict):
|
||||
gateway.session_id = payload.get("session_id")
|
||||
|
||||
self.guilds[payload["id"]] = payload
|
||||
guild_was_cached_as_none = False
|
||||
|
||||
guild = Guild.from_dict(payload)
|
||||
|
||||
if self.guilds.get(guild.id, "empty") != "empty":
|
||||
guild_was_cached_as_none = True
|
||||
|
||||
self.guilds[guild.id] = guild
|
||||
|
||||
custom_listener = self._events.get("on_guild_create")
|
||||
|
||||
if custom_listener is not None:
|
||||
await custom_listener(payload) # ToDo: Guild Model
|
||||
if custom_listener is not None and guild_was_cached_as_none is False:
|
||||
asyncio.ensure_future(custom_listener(guild))
|
||||
|
||||
return
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@ async def on_ready_listener(self, gateway, payload: dict):
|
|||
|
||||
guilds = payload.get("guilds")
|
||||
|
||||
if self._none_guilds_cached is False:
|
||||
self.guilds = dict(map(lambda i: (i["id"], None), guilds))
|
||||
self._none_guilds_cached = True
|
||||
|
||||
self.user = User.from_dict(payload.get("user"))
|
||||
|
||||
custom_listener = self._events.get("on_shard_ready")
|
||||
|
|
Loading…
Reference in a new issue