diff options
| author | Ken Swenson <[email protected]> | 2017-10-19 08:27:40 -0400 |
|---|---|---|
| committer | alex <[email protected]> | 2017-10-19 14:27:40 +0200 |
| commit | f47a0c831efe5842ca38cb1067de361ae42f6edc (patch) | |
| tree | 95c43f077546596e8afea6964be4372ce25b7055 /src | |
| parent | Add a missing break (diff) | |
| download | serenity-f47a0c831efe5842ca38cb1067de361ae42f6edc.tar.xz serenity-f47a0c831efe5842ca38cb1067de361ae42f6edc.zip | |
Implement changing a role's position (#201)
Diffstat (limited to 'src')
| -rw-r--r-- | src/http/mod.rs | 18 | ||||
| -rw-r--r-- | src/model/guild/guild_id.rs | 21 | ||||
| -rw-r--r-- | src/model/guild/mod.rs | 20 |
3 files changed, 59 insertions, 0 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 0abed02..099a33c 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -814,6 +814,24 @@ pub fn edit_role(guild_id: u64, role_id: u64, map: &JsonMap) -> Result<Role> { .map_err(From::from) } +/// Changes the position of a role in a guild. +pub fn edit_role_position(guild_id: u64, role_id: u64, position: u64) -> Result<Vec<Role>> { + let body = serde_json::to_string(&json!({ + "id": role_id, + "position": position, + }))?; + let response = request!( + Route::GuildsIdRolesId(guild_id), + patch(body), + "/guilds/{}/roles/{}", + guild_id, + role_id + ); + + serde_json::from_reader::<HyperResponse, Vec<Role>>(response) + .map_err(From::from) +} + /// Edits a the webhook with the given data. /// /// The Value is a map with optional values of: diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 64e1181..622d059 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -303,6 +303,27 @@ impl GuildId { http::edit_role(self.0, role_id.into().0, &f(EditRole::default()).0) } + /// Edits the order of [`Role`]s + /// Requires the [Manage Roles] permission. + /// + /// # Examples + /// + /// Change the order of a role: + /// + /// ```rust,ignore + /// use serenity::model::{GuildId, RoleId}; + /// GuildId(7).edit_role_position(RoleId(8), 2); + /// ``` + /// + /// [`Role`]: struct.Role.html + /// [Manage Roles]: permissions/constant.MANAGE_ROLES.html + #[inline] + pub fn edit_role_position<R>(&self, role_id: R, position: u64) -> Result<Vec<Role>> + where R: Into<RoleId> { + http::edit_role_position(self.0, role_id.into().0, position) + } + + /// Search the cache for the guild. #[cfg(feature = "cache")] pub fn find(&self) -> Option<Arc<RwLock<Guild>>> { CACHE.read().unwrap().guild(*self) } diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 5a5ab63..aa9fd1d 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -597,6 +597,26 @@ impl Guild { self.id.edit_role(role_id, f) } + /// Edits the order of [`Role`]s + /// Requires the [Manage Roles] permission. + /// + /// # Examples + /// + /// Change the order of a role: + /// + /// ```rust,ignore + /// use serenity::model::RoleId; + /// guild.edit_role_position(RoleId(8), 2); + /// ``` + /// + /// [`Role`]: struct.Role.html + /// [Manage Roles]: permissions/constant.MANAGE_ROLES.html + #[inline] + pub fn edit_role_position<R>(&self, role_id: R, position: u64) -> Result<Vec<Role>> + where R: Into<RoleId> { + self.id.edit_role_position(role_id, position) + } + /// Gets a partial amount of guild data by its Id. /// /// Requires that the current user be in the guild. |