Skip to content

Commit

Permalink
Fix parsing of role add/remove audit log changes
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis committed Dec 24, 2023
1 parent d57a8cf commit c1fa9c4
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/model/guild/audit_log/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ macro_rules! generate_change {
},
)*

/* These changes are special because their variant names do not match their keys. */

/// Role was added to a member.
#[serde(rename = "$add")]
RolesAdded {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "old_value")]
old: Option<Vec<AffectedRole>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "new_value")]
new: Option<Vec<AffectedRole>>,
},
/// Role was removed to a member.
#[serde(rename = "$remove")]
RolesRemove {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "old_value")]
old: Option<Vec<AffectedRole>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "new_value")]
new: Option<Vec<AffectedRole>>,
},

/// Unknown key was changed.
Other {
name: String,
Expand All @@ -77,6 +100,8 @@ macro_rules! generate_change {
pub fn key(&self) -> &str {
match self {
$( Self::$name { .. } => $key, )*
Self::RolesAdded { .. } => "$add",
Self::RolesRemove { .. } => "$remove",
Self::Other { name, .. } => name,
Self::Unknown => "unknown",
}
Expand Down Expand Up @@ -200,10 +225,6 @@ generate_change! {
"rate_limit_per_user" => RateLimitPerUser(u16),
/// Region of a guild was changed.
"region" => Region(String),
/// Role was added to a member.
"add" => RolesAdded(Vec<AffectedRole>),
/// Role was removed to a member.
"remove" => RolesRemove(Vec<AffectedRole>),
/// ID of the rules channel was changed.
"rules_channel_id" => RulesChannelId(ChannelId),
/// Invite splash page artwork was changed.
Expand Down

0 comments on commit c1fa9c4

Please sign in to comment.