use super::change_key::AuditLogChangeKey;
use crate::{
application::command::permissions::GuildCommandPermissions,
channel::{
message::sticker::StickerFormatType, permission_overwrite::PermissionOverwrite,
stage_instance::PrivacyLevel, thread::AutoArchiveDuration,
},
guild::{
DefaultMessageNotificationLevel, ExplicitContentFilter, MfaLevel, NSFWLevel, Permissions,
VerificationLevel,
},
id::{
marker::{
ApplicationMarker, ChannelMarker, GenericMarker, GuildMarker, RoleMarker, UserMarker,
},
Id,
},
util::{ImageHash, Timestamp},
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct AffectedRole {
pub id: Id<RoleMarker>,
pub name: String,
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(untagged)]
pub enum AuditLogChangeTypeValue {
Unsigned(u64),
String(String),
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(rename_all = "snake_case", tag = "key")]
pub enum AuditLogChange {
AfkChannelId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<ChannelMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<ChannelMarker>>,
},
AfkTimeout {
#[serde(rename = "new_value")]
new: u64,
#[serde(rename = "old_value")]
old: u64,
},
Allow {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Permissions>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Permissions>,
},
ApplicationId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<ApplicationMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<ApplicationMarker>>,
},
Archived {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
Asset {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
AutoArchiveDuration {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<AutoArchiveDuration>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<AutoArchiveDuration>,
},
Available {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
AvatarHash {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<ImageHash>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<ImageHash>,
},
BannerHash {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<ImageHash>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<ImageHash>,
},
Bitrate {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
ChannelId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<ChannelMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<ChannelMarker>>,
},
Code {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
Color {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
CommandId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<GuildCommandPermissions>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<GuildCommandPermissions>,
},
CommunicationDisabledUntil {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Timestamp>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Timestamp>,
},
Deaf {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
DefaultAutoArchiveDuration {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<AutoArchiveDuration>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<AutoArchiveDuration>,
},
DefaultMessageNotifications {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<DefaultMessageNotificationLevel>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<DefaultMessageNotificationLevel>,
},
Deny {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Permissions>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Permissions>,
},
Description {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
DiscoverySplashHash {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<ImageHash>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<ImageHash>,
},
EnableEmoticons {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
EntityType {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
ExpireBehavior {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
ExpireGracePeriod {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
ExplicitContentFilter {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<ExplicitContentFilter>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<ExplicitContentFilter>,
},
FormatType {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<StickerFormatType>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<StickerFormatType>,
},
GuildId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<GuildMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<GuildMarker>>,
},
Hoist {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
IconHash {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<ImageHash>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<ImageHash>,
},
Id {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<GenericMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<GenericMarker>>,
},
ImageHash {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<ImageHash>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<ImageHash>,
},
Invitable {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
InviterId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<UserMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<UserMarker>>,
},
Location {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
Locked {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
MaxAge {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
MaxUses {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
Mentionable {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
MfaLevel {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<MfaLevel>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<MfaLevel>,
},
Mute {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
Name {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
Nick {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
Nsfw {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
NsfwLevel {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<NSFWLevel>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<NSFWLevel>,
},
OwnerId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<UserMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<UserMarker>>,
},
PermissionOverwrites {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Vec<PermissionOverwrite>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Vec<PermissionOverwrite>>,
},
Permissions {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Permissions>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Permissions>,
},
Position {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
PreferredLocale {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
PrivacyLevel {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<PrivacyLevel>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<PrivacyLevel>,
},
PruneDeleteDays {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
PublicUpdatesChannelId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<ChannelMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<ChannelMarker>>,
},
RateLimitPerUser {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
Region {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
#[serde(rename = "$add")]
RoleAdded {
#[serde(default, rename = "new_value", skip_serializing_if = "Vec::is_empty")]
new: Vec<AffectedRole>,
#[serde(default, rename = "old_value", skip_serializing_if = "Vec::is_empty")]
old: Vec<AffectedRole>,
},
#[serde(rename = "$remove")]
RoleRemoved {
#[serde(default, rename = "new_value", skip_serializing_if = "Vec::is_empty")]
new: Vec<AffectedRole>,
#[serde(default, rename = "old_value", skip_serializing_if = "Vec::is_empty")]
old: Vec<AffectedRole>,
},
RulesChannelId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<ChannelMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<ChannelMarker>>,
},
SplashHash {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<ImageHash>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<ImageHash>,
},
Status {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
SystemChannelId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<ChannelMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<ChannelMarker>>,
},
Tags {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
Temporary {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
Topic {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
Type {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<AuditLogChangeTypeValue>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<AuditLogChangeTypeValue>,
},
UnicodeEmoji {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
UserLimit {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
Uses {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<u64>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<u64>,
},
VanityUrlCode {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<String>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<String>,
},
VerificationLevel {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<VerificationLevel>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<VerificationLevel>,
},
WidgetChannelId {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<Id<ChannelMarker>>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<Id<ChannelMarker>>,
},
WidgetEnabled {
#[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
new: Option<bool>,
#[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
old: Option<bool>,
},
#[serde(other)]
Other,
}
impl AuditLogChange {
pub const fn key(&self) -> Option<AuditLogChangeKey> {
Some(match self {
Self::AfkChannelId { .. } => AuditLogChangeKey::AfkChannelId,
Self::AfkTimeout { .. } => AuditLogChangeKey::AfkTimeout,
Self::Allow { .. } => AuditLogChangeKey::Allow,
Self::ApplicationId { .. } => AuditLogChangeKey::ApplicationId,
Self::Archived { .. } => AuditLogChangeKey::Archived,
Self::Asset { .. } => AuditLogChangeKey::Asset,
Self::AutoArchiveDuration { .. } => AuditLogChangeKey::AutoArchiveDuration,
Self::Available { .. } => AuditLogChangeKey::Available,
Self::AvatarHash { .. } => AuditLogChangeKey::AvatarHash,
Self::BannerHash { .. } => AuditLogChangeKey::BannerHash,
Self::Bitrate { .. } => AuditLogChangeKey::Bitrate,
Self::ChannelId { .. } => AuditLogChangeKey::ChannelId,
Self::Code { .. } => AuditLogChangeKey::Code,
Self::Color { .. } => AuditLogChangeKey::Color,
Self::CommandId { .. } => AuditLogChangeKey::CommandId,
Self::CommunicationDisabledUntil { .. } => {
AuditLogChangeKey::CommunicationDisabledUntil
}
Self::Deaf { .. } => AuditLogChangeKey::Deaf,
Self::DefaultAutoArchiveDuration { .. } => {
AuditLogChangeKey::DefaultAutoArchiveDuration
}
Self::DefaultMessageNotifications { .. } => {
AuditLogChangeKey::DefaultMessageNotifications
}
Self::Deny { .. } => AuditLogChangeKey::Deny,
Self::Description { .. } => AuditLogChangeKey::Description,
Self::DiscoverySplashHash { .. } => AuditLogChangeKey::DiscoverySplashHash,
Self::EnableEmoticons { .. } => AuditLogChangeKey::EnableEmoticons,
Self::EntityType { .. } => AuditLogChangeKey::EntityType,
Self::ExpireBehavior { .. } => AuditLogChangeKey::ExpireBehavior,
Self::ExpireGracePeriod { .. } => AuditLogChangeKey::ExpireGracePeriod,
Self::ExplicitContentFilter { .. } => AuditLogChangeKey::ExplicitContentFilter,
Self::FormatType { .. } => AuditLogChangeKey::FormatType,
Self::GuildId { .. } => AuditLogChangeKey::GuildId,
Self::Hoist { .. } => AuditLogChangeKey::Hoist,
Self::IconHash { .. } => AuditLogChangeKey::IconHash,
Self::Id { .. } => AuditLogChangeKey::Id,
Self::ImageHash { .. } => AuditLogChangeKey::ImageHash,
Self::Invitable { .. } => AuditLogChangeKey::Invitable,
Self::InviterId { .. } => AuditLogChangeKey::InviterId,
Self::Location { .. } => AuditLogChangeKey::Location,
Self::Locked { .. } => AuditLogChangeKey::Locked,
Self::MaxAge { .. } => AuditLogChangeKey::MaxAge,
Self::MaxUses { .. } => AuditLogChangeKey::MaxUses,
Self::Mentionable { .. } => AuditLogChangeKey::Mentionable,
Self::MfaLevel { .. } => AuditLogChangeKey::MfaLevel,
Self::Mute { .. } => AuditLogChangeKey::Mute,
Self::Name { .. } => AuditLogChangeKey::Name,
Self::Nick { .. } => AuditLogChangeKey::Nick,
Self::Nsfw { .. } => AuditLogChangeKey::Nsfw,
Self::NsfwLevel { .. } => AuditLogChangeKey::NsfwLevel,
Self::OwnerId { .. } => AuditLogChangeKey::OwnerId,
Self::PermissionOverwrites { .. } => AuditLogChangeKey::PermissionOverwrites,
Self::Permissions { .. } => AuditLogChangeKey::Permissions,
Self::Position { .. } => AuditLogChangeKey::Position,
Self::PreferredLocale { .. } => AuditLogChangeKey::PreferredLocale,
Self::PrivacyLevel { .. } => AuditLogChangeKey::PrivacyLevel,
Self::PruneDeleteDays { .. } => AuditLogChangeKey::PruneDeleteDays,
Self::PublicUpdatesChannelId { .. } => AuditLogChangeKey::PublicUpdatesChannelId,
Self::RateLimitPerUser { .. } => AuditLogChangeKey::RateLimitPerUser,
Self::Region { .. } => AuditLogChangeKey::Region,
Self::RoleAdded { .. } => AuditLogChangeKey::RoleAdded,
Self::RoleRemoved { .. } => AuditLogChangeKey::RoleRemoved,
Self::RulesChannelId { .. } => AuditLogChangeKey::RulesChannelId,
Self::SplashHash { .. } => AuditLogChangeKey::SplashHash,
Self::Status { .. } => AuditLogChangeKey::Status,
Self::SystemChannelId { .. } => AuditLogChangeKey::SystemChannelId,
Self::Tags { .. } => AuditLogChangeKey::Tags,
Self::Temporary { .. } => AuditLogChangeKey::Temporary,
Self::Topic { .. } => AuditLogChangeKey::Topic,
Self::Type { .. } => AuditLogChangeKey::Type,
Self::UnicodeEmoji { .. } => AuditLogChangeKey::UnicodeEmoji,
Self::UserLimit { .. } => AuditLogChangeKey::UserLimit,
Self::Uses { .. } => AuditLogChangeKey::Uses,
Self::VanityUrlCode { .. } => AuditLogChangeKey::VanityUrlCode,
Self::VerificationLevel { .. } => AuditLogChangeKey::VerificationLevel,
Self::WidgetChannelId { .. } => AuditLogChangeKey::WidgetChannelId,
Self::WidgetEnabled { .. } => AuditLogChangeKey::WidgetEnabled,
Self::Other => return None,
})
}
}
#[cfg(test)]
mod tests {
use super::{super::AuditLogChangeKey, AffectedRole, AuditLogChange, AuditLogChangeTypeValue};
use crate::{channel::ChannelType, guild::Permissions, id::Id};
use serde::{Deserialize, Serialize};
use serde_test::Token;
use static_assertions::{assert_fields, assert_impl_all};
use std::{fmt::Debug, hash::Hash};
assert_fields!(AffectedRole: id, name);
assert_fields!(AuditLogChange::AfkChannelId: new, old);
assert_fields!(AuditLogChange::AfkTimeout: new, old);
assert_fields!(AuditLogChange::Allow: new);
assert_fields!(AuditLogChange::ApplicationId: new);
assert_fields!(AuditLogChange::AvatarHash: new, old);
assert_fields!(AuditLogChange::BannerHash: new, old);
assert_fields!(AuditLogChange::Bitrate: new, old);
assert_fields!(AuditLogChange::ChannelId: new);
assert_fields!(AuditLogChange::Code: new);
assert_fields!(AuditLogChange::Color: new, old);
assert_fields!(AuditLogChange::CommandId: new, old);
assert_fields!(AuditLogChange::CommunicationDisabledUntil: new, old);
assert_fields!(AuditLogChange::Deaf: new, old);
assert_fields!(AuditLogChange::DefaultMessageNotifications: new, old);
assert_fields!(AuditLogChange::Deny: new);
assert_fields!(AuditLogChange::Description: new, old);
assert_fields!(AuditLogChange::DiscoverySplashHash: new, old);
assert_fields!(AuditLogChange::EnableEmoticons: new, old);
assert_fields!(AuditLogChange::ExpireBehavior: new);
assert_fields!(AuditLogChange::ExpireGracePeriod: new);
assert_fields!(AuditLogChange::ExplicitContentFilter: new, old);
assert_fields!(AuditLogChange::Hoist: new, old);
assert_fields!(AuditLogChange::IconHash: new, old);
assert_fields!(AuditLogChange::Id: new);
assert_fields!(AuditLogChange::ImageHash: new, old);
assert_fields!(AuditLogChange::Invitable: new, old);
assert_fields!(AuditLogChange::InviterId: new);
assert_fields!(AuditLogChange::MaxAge: new);
assert_fields!(AuditLogChange::MaxUses: new);
assert_fields!(AuditLogChange::Mentionable: new, old);
assert_fields!(AuditLogChange::MfaLevel: new, old);
assert_fields!(AuditLogChange::Mute: new, old);
assert_fields!(AuditLogChange::Name: new, old);
assert_fields!(AuditLogChange::Nick: new, old);
assert_fields!(AuditLogChange::NsfwLevel: new, old);
assert_fields!(AuditLogChange::OwnerId: new, old);
assert_fields!(AuditLogChange::Permissions: new, old);
assert_fields!(AuditLogChange::PrivacyLevel: new, old);
assert_fields!(AuditLogChange::Position: new, old);
assert_fields!(AuditLogChange::PreferredLocale: new, old);
assert_fields!(AuditLogChange::PruneDeleteDays: new);
assert_fields!(AuditLogChange::PublicUpdatesChannelId: new, old);
assert_fields!(AuditLogChange::RateLimitPerUser: new, old);
assert_fields!(AuditLogChange::RoleAdded: new);
assert_fields!(AuditLogChange::RoleRemoved: new);
assert_fields!(AuditLogChange::RulesChannelId: new, old);
assert_fields!(AuditLogChange::SplashHash: new, old);
assert_fields!(AuditLogChange::SystemChannelId: new, old);
assert_fields!(AuditLogChange::Temporary: new);
assert_fields!(AuditLogChange::Topic: new);
assert_fields!(AuditLogChange::Type: new);
assert_fields!(AuditLogChange::Uses: new);
assert_fields!(AuditLogChange::UserLimit: new, old);
assert_fields!(AuditLogChange::VanityUrlCode: new, old);
assert_fields!(AuditLogChange::VerificationLevel: new, old);
assert_fields!(AuditLogChange::WidgetChannelId: new, old);
assert_fields!(AuditLogChange::WidgetEnabled: new, old);
assert_impl_all!(
AffectedRole: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Send,
Serialize,
Sync
);
assert_impl_all!(
AuditLogChange: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Send,
Serialize,
Sync
);
assert_impl_all!(
AuditLogChangeTypeValue: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Send,
Serialize,
Sync
);
#[test]
fn afk_channel_id() {
let value = AuditLogChange::AfkChannelId {
new: Some(Id::new(1)),
old: None,
};
assert_eq!(Some(AuditLogChangeKey::AfkChannelId), value.key());
serde_test::assert_tokens(
&value,
&[
Token::Struct {
name: "AuditLogChange",
len: 2,
},
Token::String("key"),
Token::String("afk_channel_id"),
Token::String("new_value"),
Token::Some,
Token::NewtypeStruct { name: "Id" },
Token::String("1"),
Token::StructEnd,
],
);
}
#[test]
fn permissions() {
let old: Permissions = Permissions::SEND_MESSAGES;
let new: Permissions = old | Permissions::EMBED_LINKS;
let value = AuditLogChange::Permissions {
new: Some(new),
old: Some(old),
};
assert_eq!(Some(AuditLogChangeKey::Permissions), value.key());
serde_test::assert_tokens(
&value,
&[
Token::Struct {
name: "AuditLogChange",
len: 3,
},
Token::String("key"),
Token::String("permissions"),
Token::String("new_value"),
Token::Some,
Token::Str("18432"),
Token::String("old_value"),
Token::Some,
Token::Str("2048"),
Token::StructEnd,
],
);
}
#[test]
fn channel_type() {
let value = AuditLogChange::Type {
new: Some(AuditLogChangeTypeValue::Unsigned(u64::from(u8::from(
ChannelType::PrivateThread,
)))),
old: None,
};
serde_test::assert_tokens(
&value,
&[
Token::Struct {
name: "AuditLogChange",
len: 2,
},
Token::String("key"),
Token::Str("type"),
Token::String("new_value"),
Token::Some,
Token::U64(u64::from(u8::from(ChannelType::PrivateThread))),
Token::StructEnd,
],
);
}
#[test]
fn integration_type() {
let value = AuditLogChange::Type {
new: Some(AuditLogChangeTypeValue::String("discord".to_owned())),
old: None,
};
serde_test::assert_tokens(
&value,
&[
Token::Struct {
name: "AuditLogChange",
len: 2,
},
Token::String("key"),
Token::Str("type"),
Token::String("new_value"),
Token::Some,
Token::Str("discord"),
Token::StructEnd,
],
);
}
}