Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement endpoints for getting emojis of a guild #937

Merged
merged 2 commits into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,24 @@ impl Http {
}).await
}

/// Gets all emojis of a guild.
pub async fn get_emojis(&self, guild_id: u64) -> Result<Vec<Emoji>> {
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<Emoji> {
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<Gateway> {
self.fire(Request {
Expand Down
17 changes: 17 additions & 0 deletions src/http/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http>) -> Result<Vec<Emoji>> {
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<Http>, emoji_id: EmojiId) -> Result<Emoji> {
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.
Expand Down
16 changes: 16 additions & 0 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http>) -> Result<Vec<Emoji>> {
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<Http>, emoji_id: EmojiId) -> Result<Emoji> {
self.id.emoji(http, emoji_id).await
}

/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
Expand Down
16 changes: 16 additions & 0 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http>) -> Result<Vec<Emoji>> {
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<Http>, emoji_id: EmojiId) -> Result<Emoji> {
self.id.emoji(http, emoji_id).await
}

/// Gets all integration of the guild.
///
/// This performs a request over the REST API.
Expand Down