mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-09-22 19:22:01 +03:00
feat(client)!: Use rest in client methods
This commit is contained in:
parent
725432162d
commit
5b601fae0b
2 changed files with 6 additions and 16 deletions
|
@ -218,6 +218,7 @@ class Client:
|
||||||
async def fetch_user(self, user_id: Union[Snowflake, str, int]):
|
async def fetch_user(self, user_id: Union[Snowflake, str, int]):
|
||||||
"""
|
"""
|
||||||
Fetch User from the Discord API (by id).
|
Fetch User from the Discord API (by id).
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
user_id : :class:`Union[Snowflake, str, int]`
|
user_id : :class:`Union[Snowflake, str, int]`
|
||||||
|
@ -226,13 +227,12 @@ class Client:
|
||||||
|
|
||||||
# ToDo: Update cache if USER_CACHING enabled.
|
# ToDo: Update cache if USER_CACHING enabled.
|
||||||
|
|
||||||
data = await self.http.get(f"users/{user_id}")
|
return await self.rest.fetch_user(user_id)
|
||||||
|
|
||||||
return User.from_dict(data)
|
|
||||||
|
|
||||||
async def fetch_guild(self, guild_id: Union[Snowflake, str, int]):
|
async def fetch_guild(self, guild_id: Union[Snowflake, str, int]):
|
||||||
"""
|
"""
|
||||||
Fetch Guild from the Discord API (by id).
|
Fetch Guild from the Discord API (by id).
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
guild_id : :class:`Union[Snowflake, str, int]`
|
guild_id : :class:`Union[Snowflake, str, int]`
|
||||||
|
@ -241,17 +241,14 @@ class Client:
|
||||||
|
|
||||||
# ToDo: Update cache if GUILD_CACHE enabled.
|
# ToDo: Update cache if GUILD_CACHE enabled.
|
||||||
|
|
||||||
data = await self.http.get(f"guilds/{guild_id}")
|
return await self.rest.fetch_guild(guild_id)
|
||||||
|
|
||||||
return Guild.from_dict(data)
|
|
||||||
|
|
||||||
async def fetch_channel(
|
async def fetch_channel(
|
||||||
self, channel_id: Union[Snowflake, str, int]
|
self, channel_id: Union[Snowflake, str, int]
|
||||||
) -> Union[Channel, Any]:
|
) -> Union[Channel, Any]:
|
||||||
"""
|
"""
|
||||||
Fetch Channel from the Discord API (by id).
|
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
|
Parameters
|
||||||
----------
|
----------
|
||||||
channel_id : :class:`Union[Snowflake, str, int]`
|
channel_id : :class:`Union[Snowflake, str, int]`
|
||||||
|
@ -260,12 +257,7 @@ class Client:
|
||||||
|
|
||||||
# ToDo: Update cache if CHANNEL_CACHE enabled.
|
# ToDo: Update cache if CHANNEL_CACHE enabled.
|
||||||
|
|
||||||
data = (await self.http.get(f"channels/{channel_id}")) or {}
|
return await self.rest.fetch_channel(channel_id)
|
||||||
|
|
||||||
data.update({"type": ChannelType(data.pop("type"))})
|
|
||||||
|
|
||||||
channel_cls = channel_types_for_converting.get(data["type"], Channel)
|
|
||||||
return channel_cls.from_dict(data)
|
|
||||||
|
|
||||||
async def wait_for(
|
async def wait_for(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -63,8 +63,6 @@ class RESTApp:
|
||||||
Id of channel to fetch
|
Id of channel to fetch
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ToDo: Update cache if CHANNEL_CACHE enabled.
|
|
||||||
|
|
||||||
data = await self.http.get(f"channels/{channel_id}")
|
data = await self.http.get(f"channels/{channel_id}")
|
||||||
|
|
||||||
return _choose_channel_type(data)
|
return _choose_channel_type(data)
|
||||||
|
|
Loading…
Reference in a new issue