From 5b601fae0b5c5c35eebd1c12a31a9f8b8aa70f46 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Fri, 22 Apr 2022 08:41:47 +0300 Subject: [PATCH] feat(client)!: Use rest in client methods --- melisa/client.py | 20 ++++++-------------- melisa/rest.py | 2 -- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/melisa/client.py b/melisa/client.py index 03381c5..f2c7edc 100644 --- a/melisa/client.py +++ b/melisa/client.py @@ -218,6 +218,7 @@ class Client: async def fetch_user(self, user_id: Union[Snowflake, str, int]): """ Fetch User from the Discord API (by id). + Parameters ---------- user_id : :class:`Union[Snowflake, str, int]` @@ -226,13 +227,12 @@ class Client: # ToDo: Update cache if USER_CACHING enabled. - data = await self.http.get(f"users/{user_id}") - - return User.from_dict(data) + return await self.rest.fetch_user(user_id) async def fetch_guild(self, guild_id: Union[Snowflake, str, int]): """ Fetch Guild from the Discord API (by id). + Parameters ---------- guild_id : :class:`Union[Snowflake, str, int]` @@ -241,17 +241,14 @@ class Client: # ToDo: Update cache if GUILD_CACHE enabled. - data = await self.http.get(f"guilds/{guild_id}") - - return Guild.from_dict(data) + return await self.rest.fetch_guild(guild_id) async def fetch_channel( self, channel_id: Union[Snowflake, str, int] ) -> Union[Channel, Any]: """ Fetch Channel from the Discord API (by id). - If type of channel is unknown: - it will return just :class:`melisa.models.guild.channel.Channel` object. + Parameters ---------- channel_id : :class:`Union[Snowflake, str, int]` @@ -260,12 +257,7 @@ class Client: # ToDo: Update cache if CHANNEL_CACHE enabled. - data = (await self.http.get(f"channels/{channel_id}")) or {} - - data.update({"type": ChannelType(data.pop("type"))}) - - channel_cls = channel_types_for_converting.get(data["type"], Channel) - return channel_cls.from_dict(data) + return await self.rest.fetch_channel(channel_id) async def wait_for( self, diff --git a/melisa/rest.py b/melisa/rest.py index f5e0578..df741f3 100644 --- a/melisa/rest.py +++ b/melisa/rest.py @@ -63,8 +63,6 @@ class RESTApp: Id of channel to fetch """ - # ToDo: Update cache if CHANNEL_CACHE enabled. - data = await self.http.get(f"channels/{channel_id}") return _choose_channel_type(data)