Skip to content

Commit

Permalink
Fix @everyone role deserialisation (#2716)
Browse files Browse the repository at this point in the history
The `@everyone` role sometimes has a role position of -1, but not always!
  • Loading branch information
GnomedDev committed May 23, 2024
1 parent 30bfafa commit e66a734
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/builder/edit_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct EditRole<'a> {
mentionable: Option<bool>,

#[serde(skip)]
position: Option<u16>,
position: Option<i16>,
#[serde(skip)]
audit_log_reason: Option<&'a str>,
}
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'a> EditRole<'a> {

/// Set the role's position in the role list. This correlates to the role's position in the
/// user list.
pub fn position(mut self, position: u16) -> Self {
pub fn position(mut self, position: i16) -> Self {
self.position = Some(position);
self
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ impl Http {
&self,
guild_id: GuildId,
role_id: RoleId,
position: u16,
position: i16,
audit_log_reason: Option<&str>,
) -> Result<Vec<Role>> {
let map = json!([{
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ impl GuildId {
self,
http: impl AsRef<Http>,
role_id: RoleId,
position: u16,
position: i16,
) -> Result<Vec<Role>> {
http.as_ref().edit_role_position(self, role_id, position, None).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl Member {
/// more roles have the same highest position, then the role with the lowest ID is the highest.
#[cfg(feature = "cache")]
#[deprecated = "Use Guild::member_highest_role"]
pub fn highest_role_info(&self, cache: impl AsRef<Cache>) -> Option<(RoleId, u16)> {
pub fn highest_role_info(&self, cache: impl AsRef<Cache>) -> Option<(RoleId, i16)> {
cache
.as_ref()
.guild(self.guild_id)
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ impl Guild {
&self,
http: impl AsRef<Http>,
role_id: RoleId,
position: u16,
position: i16,
) -> Result<Vec<Role>> {
self.id.edit_role_position(http, role_id, position).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ impl PartialGuild {
&self,
http: impl AsRef<Http>,
role_id: RoleId,
position: u16,
position: i16,
) -> Result<Vec<Role>> {
self.id.edit_role_position(http, role_id, position).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Role {
/// position is higher.
///
/// The `@everyone` role is usually either `-1` or `0`.
pub position: u16,
pub position: i16,
/// The tags this role has. It can be used to determine if this role is a special role in this
/// guild such as guild subscriber role, or if the role is linked to an [`Integration`] or a
/// bot.
Expand Down

0 comments on commit e66a734

Please sign in to comment.