Skip to content

Commit

Permalink
Make edit_role_position plural
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Aug 23, 2024
1 parent 9db92c1 commit 5ff5f0d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/builder/edit_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ impl<'a> EditRole<'a> {
};

if let Some(position) = self.position {
guild_id.edit_role_position(http, role.id, position, self.audit_log_reason).await?;
guild_id
.edit_role_positions(http, [(role.id, position)], self.audit_log_reason)
.await?;
}
Ok(role)
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ impl Http {
}

/// Changes the position of a role in a guild.
pub async fn edit_role_position(
pub async fn edit_role_positions(
&self,
guild_id: GuildId,
map: &impl serde::Serialize,
Expand Down
18 changes: 10 additions & 8 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,10 @@ impl GuildId {
/// Returns an [`Error::Http`] if the current user lacks permission.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
pub async fn edit_role_position(
pub async fn edit_role_positions(
self,
http: &Http,
role_id: RoleId,
position: i16,
roles: impl IntoIterator<Item = (RoleId, i16)>,
reason: Option<&str>,
) -> Result<Vec<Role>> {
#[derive(serde::Serialize)]
Expand All @@ -827,12 +826,15 @@ impl GuildId {
Maximum::AuditLogReason.check_overflow(reason.len())?;
}

let map = EditRole {
id: role_id,
position,
};
let map = roles
.into_iter()
.map(|(id, position)| EditRole {
id,
position,
})
.collect::<Vec<_>>();

http.edit_role_position(self, &map, reason).await
http.edit_role_positions(self, &map, reason).await
}

/// Edits the guild's welcome screen.
Expand Down
7 changes: 3 additions & 4 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,14 +1100,13 @@ impl Guild {
/// Returns [`Error::Http`] if the current user lacks permission.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
pub async fn edit_role_position(
pub async fn edit_role_positions(
&self,
http: &Http,
role_id: RoleId,
position: i16,
roles: impl IntoIterator<Item = (RoleId, i16)>,
audit_log_reason: Option<&str>,
) -> Result<Vec<Role>> {
self.id.edit_role_position(http, role_id, position, audit_log_reason).await
self.id.edit_role_positions(http, roles, audit_log_reason).await
}

/// Modifies a scheduled event in the guild with the data set, if any.
Expand Down
7 changes: 3 additions & 4 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,14 +825,13 @@ impl PartialGuild {
/// Returns [`Error::Http`] if the current user lacks permission.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
pub async fn edit_role_position(
pub async fn edit_role_positions(
&self,
http: &Http,
role_id: RoleId,
position: i16,
roles: impl IntoIterator<Item = (RoleId, i16)>,
audit_log_reason: Option<&str>,
) -> Result<Vec<Role>> {
self.id.edit_role_position(http, role_id, position, audit_log_reason).await
self.id.edit_role_positions(http, roles, audit_log_reason).await
}

/// Edits a sticker.
Expand Down

0 comments on commit 5ff5f0d

Please sign in to comment.