Skip to content

Commit

Permalink
expand auto moderation objects
Browse files Browse the repository at this point in the history
  • Loading branch information
0b10011 committed May 25, 2024
1 parent 5b55382 commit 4efc61f
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 61 deletions.
60 changes: 2 additions & 58 deletions src/resources/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use url::Url;

use super::{
guild::{GuildId, UnavailableGuild},
permissions::Permissions,
team::Team,
user::UnavailableUser,
ImageHash,
Expand Down Expand Up @@ -115,7 +116,7 @@ pub struct InstallParams {
pub permissions: Permissions,
}

/// https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes
/// Discord docs: https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
Expand Down Expand Up @@ -193,60 +194,3 @@ bitflags::bitflags! {
const ApplicationCommandBadge = 1 << 23;
}
}

bitflags::bitflags! {
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
pub struct Permissions: u64 {
const CreateInstantInvite = 1 << 0;
const KickMembers = 1 << 1;
const BanMembers = 1 << 2;
const Administrator = 1 << 3;
const ManageChannels = 1 << 4;
const ManageGuild = 1 << 5;
const AddReactions = 1 << 6;
const ViewAuditLog = 1 << 7;
const PrioritySpeaker = 1 << 8;
const Stream = 1 << 9;
const ViewChannel = 1 << 10;
const SendMessages = 1 << 11;
const SendTtsMessages = 1 << 12;
const ManageMessages = 1 << 13;
const EmbedLinks = 1 << 14;
const AttachFiles = 1 << 15;
const ReadMessageHistory = 1 << 16;
const MentionEveryone = 1 << 17;
const UseExternalEmojis = 1 << 18;
const ViewGuildInsights = 1 << 19;
const Connect = 1 << 20;
const Speak = 1 << 21;
const MuteMembers = 1 << 22;
const DeafenMembers = 1 << 23;
const MoveMembers = 1 << 24;
const UseVad = 1 << 25;
const ChangeNickname = 1 << 26;
const ManageNicknames = 1 << 27;
const ManageRoles = 1 << 28;
const ManageWebhooks = 1 << 29;
const ManageGuildExpressions = 1 << 30;
const UseApplicationCommands = 1 << 31;
const RequestToSpeak = 1 << 32;
const ManageEvents = 1 << 33;
const ManageThreads = 1 << 34;
const CreatePublicThreads = 1 << 35;
const CreatePrivateThreads = 1 << 36;
const UseExternalStickers = 1 << 37;
const SendMessagesInThreads = 1 << 38;
const UseEmbeddedActivities = 1 << 39;
const ModerateMembers = 1 << 40;
const ViewCreatorMonetizationAnalytics = 1 << 41;
const UseSoundboard = 1 << 42;
const CreateGuildExpressions = 1 << 43;
const CreateEvents = 1 << 44;
const UseExternalSounds = 1 << 45;
const SendVoiceMessages = 1 << 46;
const SendPolls = 1 << 49;
}
}
3 changes: 2 additions & 1 deletion src/resources/application_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
use serde::{Deserialize, Serialize};

use super::{
application::{ApplicationId, IntegrationType, Permissions},
application::{ApplicationId, IntegrationType},
channel::ChannelType,
guild::GuildId,
interactions::InteractionContextType,
permissions::Permissions,
Translation,
};

Expand Down
90 changes: 89 additions & 1 deletion src/resources/auto_moderation.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,107 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use super::{channel::ChannelId, guild::GuildId, permissions::RoleId};

/// Discord docs: https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct AutoModerationRule {}
pub struct AutoModerationRule {
pub id: AutoModerationRuleId,
pub guild_id: GuildId,
pub name: String,
pub creator_id: CreatorId,
pub event_type: EventType,
pub trigger_type: TriggerType,
pub trigger_metadata: TriggerMetadata,
pub actions: Vec<AutoModerationAction>,
pub enabled: bool,
pub exempt_roles: Vec<RoleId>,
pub exempt_channels: Vec<ChannelId>,
}

#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct AutoModerationRuleId(pub String);

#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct CreatorId(pub String);

/// Discord docs: https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
pub enum TriggerType {
Keyword = 1,
Spam = 3,
KeywordPreset = 4,
MentionSpam = 5,
}

#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct TriggerMetadata {
pub keyword_filter: Vec<String>,
pub regex_patterns: Vec<String>,
pub presets: Vec<KeywordPresetType>,
pub allow_list: Vec<String>,
pub mention_total_limit: u8,
pub mention_raid_protection_enabled: bool,
}

/// Discord docs: https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
pub enum KeywordPresetType {
Profanity = 1,
SexualContent = 2,
Slurs = 3,
}

/// Discord docs: https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
pub enum EventType {
MessageSend = 1,
}

/// Discord docs: https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-auto-moderation-action-structure
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct AutoModerationAction {
pub r#type: ActionType,
#[cfg_attr(feature = "serde", serde(default))]
pub metadata: Option<ActionMetadata>,
}

/// Discord docs: https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
pub enum ActionType {
BlockMessage = 1,
SendAlertMessage = 2,
Timeout = 3,
}

#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct ActionMetadata {
pub channel_id: ChannelId,
pub duration_seconds: u32,
#[cfg_attr(feature = "serde", serde(default))]
pub custom_message: Option<String>,
}
1 change: 1 addition & 0 deletions src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod guild_scheduled_event;
pub mod guild_template;
pub mod interactions;
pub mod invite;
pub mod permissions;
pub mod poll;
pub mod stage_instance;
pub mod sticker;
Expand Down
119 changes: 119 additions & 0 deletions src/resources/permissions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use super::{application::ApplicationId, guild::IntegrationId, ImageHash};

bitflags::bitflags! {
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
pub struct Permissions: u64 {
const CreateInstantInvite = 1 << 0;
const KickMembers = 1 << 1;
const BanMembers = 1 << 2;
const Administrator = 1 << 3;
const ManageChannels = 1 << 4;
const ManageGuild = 1 << 5;
const AddReactions = 1 << 6;
const ViewAuditLog = 1 << 7;
const PrioritySpeaker = 1 << 8;
const Stream = 1 << 9;
const ViewChannel = 1 << 10;
const SendMessages = 1 << 11;
const SendTtsMessages = 1 << 12;
const ManageMessages = 1 << 13;
const EmbedLinks = 1 << 14;
const AttachFiles = 1 << 15;
const ReadMessageHistory = 1 << 16;
const MentionEveryone = 1 << 17;
const UseExternalEmojis = 1 << 18;
const ViewGuildInsights = 1 << 19;
const Connect = 1 << 20;
const Speak = 1 << 21;
const MuteMembers = 1 << 22;
const DeafenMembers = 1 << 23;
const MoveMembers = 1 << 24;
const UseVad = 1 << 25;
const ChangeNickname = 1 << 26;
const ManageNicknames = 1 << 27;
const ManageRoles = 1 << 28;
const ManageWebhooks = 1 << 29;
const ManageGuildExpressions = 1 << 30;
const UseApplicationCommands = 1 << 31;
const RequestToSpeak = 1 << 32;
const ManageEvents = 1 << 33;
const ManageThreads = 1 << 34;
const CreatePublicThreads = 1 << 35;
const CreatePrivateThreads = 1 << 36;
const UseExternalStickers = 1 << 37;
const SendMessagesInThreads = 1 << 38;
const UseEmbeddedActivities = 1 << 39;
const ModerateMembers = 1 << 40;
const ViewCreatorMonetizationAnalytics = 1 << 41;
const UseSoundboard = 1 << 42;
const CreateGuildExpressions = 1 << 43;
const CreateEvents = 1 << 44;
const UseExternalSounds = 1 << 45;
const SendVoiceMessages = 1 << 46;
const SendPolls = 1 << 49;
}
}

#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct Role {
pub id: RoleId,
pub name: String,
pub color: Rgb,
pub hoist: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub icon: Option<ImageHash>,
#[cfg_attr(feature = "serde", serde(default))]
pub unicode_emoji: Option<String>,
pub position: u64,
pub permissions: Permissions,
pub managed: bool,
pub mentionable: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub tags: Option<RoleTags>,
pub flags: RoleFlags,
}

#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct RoleId(pub String);

#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct Rgb(pub u8, pub u8, pub u8);

/// Discord docs: https://discord.com/developers/docs/topics/permissions#role-object-role-tags-structure
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct RoleTags {
#[cfg_attr(feature = "serde", serde(default))]
pub bot_id: Option<ApplicationId>,
#[cfg_attr(feature = "serde", serde(default))]
pub integration_id: Option<IntegrationId>,
#[cfg_attr(feature = "serde", serde(default))]
pub premium_subscriber: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub subscription_listing_id: Option<String>,
#[cfg_attr(feature = "serde", serde(default))]
pub available_for_purchase: bool,
#[cfg_attr(feature = "serde", serde(default))]
pub guild_connections: bool,
}

/// Discord docs: https://discord.com/developers/docs/topics/permissions#role-object-role-flags
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum RoleFlags {
InPrompt = 1 << 0,
}
2 changes: 1 addition & 1 deletion src/resources/team.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// https://discord.com/developers/docs/topics/teams
/// Discord docs: https://discord.com/developers/docs/topics/teams
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down

0 comments on commit 4efc61f

Please sign in to comment.