diff --git a/src/Discord.Net.Core/Entities/Guilds/AutoModeration/AutoModRuleProperties.cs b/src/Discord.Net.Core/Entities/Guilds/AutoModeration/AutoModRuleProperties.cs index 0dd8a38855..8a0cdb8b0a 100644 --- a/src/Discord.Net.Core/Entities/Guilds/AutoModeration/AutoModRuleProperties.cs +++ b/src/Discord.Net.Core/Entities/Guilds/AutoModeration/AutoModRuleProperties.cs @@ -131,6 +131,11 @@ public class AutoModRuleProperties /// Gets or sets the exempt channels for the rule. Empty if the rule has no exempt channels. /// public Optional ExemptChannels { get; set; } + + /// + /// Gets or sets whether to automatically detect mention raids. + /// + public Optional MentionRaidProtectionEnabled { get; set; } } /// diff --git a/src/Discord.Net.Core/Entities/Guilds/AutoModeration/IAutoModRule.cs b/src/Discord.Net.Core/Entities/Guilds/AutoModeration/IAutoModRule.cs index c87ecf3dc7..b44bfcdbf7 100644 --- a/src/Discord.Net.Core/Entities/Guilds/AutoModeration/IAutoModRule.cs +++ b/src/Discord.Net.Core/Entities/Guilds/AutoModeration/IAutoModRule.cs @@ -43,7 +43,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable /// This collection will be empty if is not /// . /// - public IReadOnlyCollection KeywordFilter { get; } + IReadOnlyCollection KeywordFilter { get; } /// /// Gets regex patterns for this rule. Empty if the rule has no regexes. @@ -52,7 +52,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable /// This collection will be empty if is not /// . /// - public IReadOnlyCollection RegexPatterns { get; } + IReadOnlyCollection RegexPatterns { get; } /// /// Gets the allow list patterns for this rule. Empty if the rule has no allowed terms. @@ -61,7 +61,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable /// This collection will be empty if is not /// . /// - public IReadOnlyCollection AllowList { get; } + IReadOnlyCollection AllowList { get; } /// /// Gets the preset keyword types for this rule. Empty if the rule has no presets. @@ -70,7 +70,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable /// This collection will be empty if is not /// . /// - public IReadOnlyCollection Presets { get; } + IReadOnlyCollection Presets { get; } /// /// Gets the total mention limit for this rule. @@ -79,7 +79,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable /// This property will be if is not /// . /// - public int? MentionTotalLimit { get; } + int? MentionTotalLimit { get; } /// /// Gets a collection of actions that will be preformed if a user breaks this rule. @@ -101,6 +101,15 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable /// IReadOnlyCollection ExemptChannels { get; } + /// + /// Gets or sets whether to automatically detect mention raids. + /// + /// + /// This property will be if is not + /// . + /// + bool? MentionRaidProtectionEnabled { get; } + /// /// Modifies this rule. /// diff --git a/src/Discord.Net.Rest/API/Common/AutoModerationRule.cs b/src/Discord.Net.Rest/API/Common/AutoModerationRule.cs index f30af5beea..4d8217ed66 100644 --- a/src/Discord.Net.Rest/API/Common/AutoModerationRule.cs +++ b/src/Discord.Net.Rest/API/Common/AutoModerationRule.cs @@ -1,45 +1,39 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Discord.API +namespace Discord.API; + +internal class AutoModerationRule { - internal class AutoModerationRule - { - [JsonProperty("id")] - public ulong Id { get; set; } + [JsonProperty("id")] + public ulong Id { get; set; } - [JsonProperty("guild_id")] - public ulong GuildId { get; set; } + [JsonProperty("guild_id")] + public ulong GuildId { get; set; } - [JsonProperty("name")] - public string Name { get; set; } + [JsonProperty("name")] + public string Name { get; set; } - [JsonProperty("creator_id")] - public ulong CreatorId { get; set; } + [JsonProperty("creator_id")] + public ulong CreatorId { get; set; } - [JsonProperty("event_type")] - public AutoModEventType EventType { get; set; } + [JsonProperty("event_type")] + public AutoModEventType EventType { get; set; } - [JsonProperty("trigger_type")] - public AutoModTriggerType TriggerType { get; set; } + [JsonProperty("trigger_type")] + public AutoModTriggerType TriggerType { get; set; } - [JsonProperty("trigger_metadata")] - public TriggerMetadata TriggerMetadata { get; set; } + [JsonProperty("trigger_metadata")] + public TriggerMetadata TriggerMetadata { get; set; } - [JsonProperty("actions")] - public AutoModAction[] Actions { get; set; } + [JsonProperty("actions")] + public AutoModAction[] Actions { get; set; } - [JsonProperty("enabled")] - public bool Enabled { get; set; } + [JsonProperty("enabled")] + public bool Enabled { get; set; } - [JsonProperty("exempt_roles")] - public ulong[] ExemptRoles { get; set; } + [JsonProperty("exempt_roles")] + public ulong[] ExemptRoles { get; set; } - [JsonProperty("exempt_channels")] - public ulong[] ExemptChannels { get; set; } - } + [JsonProperty("exempt_channels")] + public ulong[] ExemptChannels { get; set; } } diff --git a/src/Discord.Net.Rest/API/Common/TriggerMetadata.cs b/src/Discord.Net.Rest/API/Common/TriggerMetadata.cs index 214e464c95..b74ce8dc89 100644 --- a/src/Discord.Net.Rest/API/Common/TriggerMetadata.cs +++ b/src/Discord.Net.Rest/API/Common/TriggerMetadata.cs @@ -1,27 +1,24 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Discord.API +namespace Discord.API; + +internal class TriggerMetadata { - internal class TriggerMetadata - { - [JsonProperty("keyword_filter")] - public Optional KeywordFilter { get; set; } + [JsonProperty("keyword_filter")] + public Optional KeywordFilter { get; set; } + + [JsonProperty("regex_patterns")] + public Optional RegexPatterns { get; set; } - [JsonProperty("regex_patterns")] - public Optional RegexPatterns { get; set; } + [JsonProperty("presets")] + public Optional Presets { get; set; } - [JsonProperty("presets")] - public Optional Presets { get; set; } + [JsonProperty("allow_list")] + public Optional AllowList { get; set; } - [JsonProperty("allow_list")] - public Optional AllowList { get; set; } + [JsonProperty("mention_total_limit")] + public Optional MentionLimit { get; set; } - [JsonProperty("mention_total_limit")] - public Optional MentionLimit { get; set; } - } + [JsonProperty("mention_raid_protection_enabled")] + public Optional MentionRaidProtectionEnabled { get; set; } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index cd760a6f8f..b5c1bc3027 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -1538,6 +1538,7 @@ public static Task ModifyRuleAsync(BaseDiscordClient client, AllowList = args.AllowList.IsSpecified ? args.AllowList : rule.AllowList.ToArray(), MentionLimit = args.MentionLimit.IsSpecified ? args.MentionLimit : rule.MentionTotalLimit ?? Optional.Unspecified, Presets = args.Presets.IsSpecified ? args.Presets : rule.Presets.ToArray(), + MentionRaidProtectionEnabled = args.MentionRaidProtectionEnabled.IsSpecified ? args.MentionRaidProtectionEnabled : rule.MentionRaidProtectionEnabled ?? Optional.Unspecified, } : Optional.Unspecified }; diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestAutoModRule.cs b/src/Discord.Net.Rest/Entities/Guilds/RestAutoModRule.cs index 2b7b07b7cc..83a4db4883 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestAutoModRule.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestAutoModRule.cs @@ -55,6 +55,9 @@ public class RestAutoModRule : RestEntity, IAutoModRule /// public IReadOnlyCollection ExemptChannels { get; private set; } + /// + public bool? MentionRaidProtectionEnabled { get; private set; } + internal RestAutoModRule(BaseDiscordClient discord, ulong id) : base(discord, id) { @@ -95,6 +98,7 @@ internal void Update(Model model) Enabled = model.Enabled; ExemptRoles = model.ExemptRoles.ToImmutableArray(); ExemptChannels = model.ExemptChannels.ToImmutableArray(); + MentionRaidProtectionEnabled = model.TriggerMetadata.MentionRaidProtectionEnabled.ToNullable(); } /// diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs index 844a6828fa..005ed4e7e2 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs @@ -60,6 +60,9 @@ public class SocketAutoModRule : SocketEntity, IAutoModRule /// public IReadOnlyCollection ExemptChannels { get; private set; } + /// + public bool? MentionRaidProtectionEnabled { get; private set; } + /// public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -106,6 +109,7 @@ internal void Update(Model model) Enabled = model.Enabled; ExemptRoles = model.ExemptRoles.Select(x => Guild.GetRole(x)).ToImmutableArray(); ExemptChannels = model.ExemptChannels.Select(x => Guild.GetChannel(x)).ToImmutableArray(); + MentionRaidProtectionEnabled = model.TriggerMetadata.MentionRaidProtectionEnabled.ToNullable(); } ///