diff options
author | Noah <mounderfod@gmail.com> | 2022-07-08 21:26:49 +0100 |
---|---|---|
committer | Noah <mounderfod@gmail.com> | 2022-07-08 21:26:49 +0100 |
commit | 39bdd5e8089bd337bf775ca2ca574f1934662ba2 (patch) | |
tree | 0b3a43065bc2c01440af449d5b2ed1cddc59fb14 /discord | |
parent | ddc5a3d3fed034a04bedb24cadc5f592daff4a27 (diff) | |
download | discobra-39bdd5e8089bd337bf775ca2ca574f1934662ba2.tar.gz |
feat(gateway): Add ready data to `user` attribute of `Client`
Diffstat (limited to 'discord')
-rw-r--r-- | discord/client.py | 5 | ||||
-rw-r--r-- | discord/user.py | 22 |
2 files changed, 26 insertions, 1 deletions
diff --git a/discord/client.py b/discord/client.py index c500d1c..c61c4b9 100644 --- a/discord/client.py +++ b/discord/client.py @@ -5,6 +5,8 @@ import threading import websockets from typing import Coroutine from discord.intents import Intents, gen_number +from discord.user import User + class Client: def __init__(self, intents: list[Intents]): @@ -35,6 +37,7 @@ class Client: ready = await gateway.recv() if (hasattr(self, 'on_ready')): await getattr(self, 'on_ready')() + self.user = User(json.loads(ready)['d']['user']) async def heartbeat(self, gateway: websockets.WebSocketClientProtocol, interval: int): while True: @@ -55,4 +58,4 @@ class Client: def run(self, token: str): self.token = token - asyncio.run(self.connect(self.token, self.code)) + asyncio.run(self.connect(self.token, self.code)) \ No newline at end of file diff --git a/discord/user.py b/discord/user.py index e69de29..838b6e2 100644 --- a/discord/user.py +++ b/discord/user.py @@ -0,0 +1,22 @@ +class User: + __slots__ = ( + "id", + "username", + "discriminator", + "avatar", + "bot", + "system", + "mfa_enabled", + "banner", + "accent_color", + "locale", + "verified", + "email", + "flags", + "premium_type", + "public_flags" + ) + + def __init__(self, data: dict): + for k, v in data: + setattr(self, k, v) |