aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-02-09 20:25:11 -0800
committerZeyla Hellyer <[email protected]>2018-02-09 20:26:00 -0800
commitdbfc06e9c6df506839fb178eaeb9db704aefd357 (patch)
treed91f56767a99267185ba77c036cd1c17fc82e96e
parentGeneralise `image`, `thumbnail`, `url` and `attachment` (diff)
downloadserenity-dbfc06e9c6df506839fb178eaeb9db704aefd357.tar.xz
serenity-dbfc06e9c6df506839fb178eaeb9db704aefd357.zip
Add 'Get Guild Vanity Url' endpoint
Docs: <https://github.com/discordapp/discord-api-docs/commit/98f6643703012d2f3780ba730ce1191120f85dcd>
-rw-r--r--src/http/mod.rs19
-rw-r--r--src/http/ratelimiting.rs6
-rw-r--r--src/model/guild/guild_id.rs10
-rw-r--r--src/model/guild/mod.rs10
-rw-r--r--src/model/guild/partial_guild.rs10
5 files changed, 55 insertions, 0 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs
index 6b56abd..e40b3c6 100644
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -1241,6 +1241,25 @@ pub fn get_guild_invites(guild_id: u64) -> Result<Vec<RichInvite>> {
.map_err(From::from)
}
+/// Gets a guild's vanity URL if it has one.
+pub fn get_guild_vanity_url(guild_id: u64) -> Result<String> {
+ #[derive(Deserialize)]
+ struct GuildVanityUrl {
+ code: String,
+ }
+
+ let response = request!(
+ Route::GuildsIdVanityUrl(guild_id),
+ get,
+ "/guilds/{}/vanity-url",
+ guild_id
+ );
+
+ serde_json::from_reader::<HyperResponse, GuildVanityUrl>(response)
+ .map(|x| x.code)
+ .map_err(From::from)
+}
+
/// Gets the members of a guild. Optionally pass a `limit` and the Id of the
/// user to offset the result by.
pub fn get_guild_members(guild_id: u64,
diff --git a/src/http/ratelimiting.rs b/src/http/ratelimiting.rs
index ca269e3..d46d196 100644
--- a/src/http/ratelimiting.rs
+++ b/src/http/ratelimiting.rs
@@ -316,6 +316,12 @@ pub enum Route {
///
/// [`GuildId`]: struct.GuildId.html
GuildsIdRolesId(u64),
+ /// Route for the `/guilds/:guild_id/vanity-url` path.
+ ///
+ /// The data is the relevant [`GuildId`].
+ ///
+ /// [`GuildId`]: struct.GuildId.html
+ GuildsIdVanityUrl(u64),
/// Route for the `/guilds/:guild_id/webhooks` path.
///
/// The data is the relevant [`GuildId`].
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs
index adfac05..c07a40f 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -535,6 +535,16 @@ impl GuildId {
http::remove_ban(self.0, user_id.into().0)
}
+ /// Retrieve's the guild's vanity URL.
+ ///
+ /// **Note**: Requires the [Manage Guild] permission.
+ ///
+ /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
+ #[inline]
+ pub fn vanity_url(&self) -> Result<String> {
+ http::get_guild_vanity_url(self.0)
+ }
+
/// Retrieves the guild's webhooks.
///
/// **Note**: Requires the [Manage Webhooks] permission.
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index 142fc73..629c496 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -1463,6 +1463,16 @@ impl Guild {
self.id.unban(user_id)
}
+ /// Retrieve's the guild's vanity URL.
+ ///
+ /// **Note**: Requires the [Manage Guild] permission.
+ ///
+ /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
+ #[inline]
+ pub fn vanity_url(&self) -> Result<String> {
+ self.id.vanity_url()
+ }
+
/// Retrieves the guild's webhooks.
///
/// **Note**: Requires the [Manage Webhooks] permission.
diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs
index aebd6e7..d324517 100644
--- a/src/model/guild/partial_guild.rs
+++ b/src/model/guild/partial_guild.rs
@@ -431,6 +431,16 @@ impl PartialGuild {
#[inline]
pub fn unban<U: Into<UserId>>(&self, user_id: U) -> Result<()> { self.id.unban(user_id) }
+ /// Retrieve's the guild's vanity URL.
+ ///
+ /// **Note**: Requires the [Manage Guild] permission.
+ ///
+ /// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
+ #[inline]
+ pub fn vanity_url(&self) -> Result<String> {
+ self.id.vanity_url()
+ }
+
/// Retrieves the guild's webhooks.
///
/// **Note**: Requires the [Manage Webhooks] permission.