From 2a1c3852fb90f09951d4b13191c87f4f15d22ba2 Mon Sep 17 00:00:00 2001 From: "Alex M. M" Date: Sun, 23 Aug 2020 01:53:21 +0200 Subject: [PATCH] Implement endpoints for getting emojis of a guild (#937) * Add http methods to retrieve emojis * Add model counterparts of the http methods --- src/http/client.rs | 18 ++++++++++++++++++ src/http/routing.rs | 17 +++++++++++++++++ src/model/guild/guild_id.rs | 16 ++++++++++++++++ src/model/guild/mod.rs | 16 ++++++++++++++++ src/model/guild/partial_guild.rs | 16 ++++++++++++++++ 5 files changed, 83 insertions(+) diff --git a/src/http/client.rs b/src/http/client.rs index add1465ec4f..06ab218cf45 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -1009,6 +1009,24 @@ impl Http { }).await } + /// Gets all emojis of a guild. + pub async fn get_emojis(&self, guild_id: u64) -> Result> { + self.fire(Request { + body: None, + headers: None, + route: RouteInfo::GetEmojis { guild_id }, + }).await + } + + /// Gets information about an emoji in a guild. + pub async fn get_emoji(&self, guild_id: u64, emoji_id: u64) -> Result { + self.fire(Request { + body: None, + headers: None, + route: RouteInfo::GetEmoji { guild_id, emoji_id }, + }).await + } + /// Gets current gateway. pub async fn get_gateway(&self) -> Result { self.fire(Request { diff --git a/src/http/routing.rs b/src/http/routing.rs index 8b830e16e0f..4ccc0788f70 100644 --- a/src/http/routing.rs +++ b/src/http/routing.rs @@ -817,6 +817,13 @@ pub enum RouteInfo<'a> { }, GetCurrentApplicationInfo, GetCurrentUser, + GetEmojis { + guild_id: u64, + }, + GetEmoji { + guild_id: u64, + emoji_id: u64, + }, GetGateway, GetGuild { guild_id: u64, @@ -1251,6 +1258,16 @@ impl<'a> RouteInfo<'a> { Route::UsersMe, Cow::from(Route::user("@me")), ), + RouteInfo::GetEmojis { guild_id } => ( + LightMethod::Get, + Route::GuildsIdEmojis(guild_id), + Cow::from(Route::guild_emojis(guild_id)), + ), + RouteInfo::GetEmoji { guild_id, emoji_id } => ( + LightMethod::Get, + Route::GuildsIdEmojisId(guild_id), + Cow::from(Route::guild_emoji(guild_id, emoji_id)), + ), RouteInfo::GetGateway => ( LightMethod::Get, Route::Gateway, diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index fa7a3380acc..74fa160ac9f 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -424,6 +424,22 @@ impl GuildId { http.as_ref().get_guild(self.0).await } + /// Gets all [`Emoji`]s of this guild via HTTP. + /// + /// [`Emoji`]: struct.Emoji.html + #[inline] + pub async fn emojis(&self, http: impl AsRef) -> Result> { + http.as_ref().get_emojis(self.0).await + } + + /// Gets an [`Emoji`] of this guild by its ID via HTTP. + /// + /// [`Emoji`]: struct.Emoji.html + #[inline] + pub async fn emoji(&self, http: impl AsRef, emoji_id: EmojiId) -> Result { + http.as_ref().get_emoji(self.0, emoji_id.0).await + } + /// Gets all integration of the guild. /// /// This performs a request over the REST API. diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index ae165c661d4..17c7db43342 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -825,6 +825,22 @@ impl Guild { .map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon)) } + /// Gets all [`Emoji`]s of this guild via HTTP. + /// + /// [`Emoji`]: struct.Emoji.html + #[inline] + pub async fn emojis(&self, http: impl AsRef) -> Result> { + self.id.emojis(http).await + } + + /// Gets an [`Emoji`] of this guild by its ID via HTTP. + /// + /// [`Emoji`]: struct.Emoji.html + #[inline] + pub async fn emoji(&self, http: impl AsRef, emoji_id: EmojiId) -> Result { + self.id.emoji(http, emoji_id).await + } + /// Gets all integration of the guild. /// /// This performs a request over the REST API. diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index a65ca1ef179..7175ce1ee05 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -368,6 +368,22 @@ impl PartialGuild { .map(|icon| format!(cdn!("/icons/{}/{}.webp"), self.id, icon)) } + /// Gets all [`Emoji`]s of this guild via HTTP. + /// + /// [`Emoji`]: struct.Emoji.html + #[inline] + pub async fn emojis(&self, http: impl AsRef) -> Result> { + self.id.emojis(http).await + } + + /// Gets an [`Emoji`] of this guild by its ID via HTTP. + /// + /// [`Emoji`]: struct.Emoji.html + #[inline] + pub async fn emoji(&self, http: impl AsRef, emoji_id: EmojiId) -> Result { + self.id.emoji(http, emoji_id).await + } + /// Gets all integration of the guild. /// /// This performs a request over the REST API.