Skip to content

Commit

Permalink
Add MentionRaidProtectionEnabled (#3056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 authored Jan 19, 2025
1 parent d828cd8 commit 0e9caf3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public class AutoModRuleProperties
/// Gets or sets the exempt channels for the rule. Empty if the rule has no exempt channels.
/// </summary>
public Optional<ulong[]> ExemptChannels { get; set; }

/// <summary>
/// Gets or sets whether to automatically detect mention raids.
/// </summary>
public Optional<bool> MentionRaidProtectionEnabled { get; set; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable
/// This collection will be empty if <see cref="TriggerType"/> is not
/// <see cref="AutoModTriggerType.Keyword"/>.
/// </remarks>
public IReadOnlyCollection<string> KeywordFilter { get; }
IReadOnlyCollection<string> KeywordFilter { get; }

/// <summary>
/// Gets regex patterns for this rule. Empty if the rule has no regexes.
Expand All @@ -52,7 +52,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable
/// This collection will be empty if <see cref="TriggerType"/> is not
/// <see cref="AutoModTriggerType.Keyword"/>.
/// </remarks>
public IReadOnlyCollection<string> RegexPatterns { get; }
IReadOnlyCollection<string> RegexPatterns { get; }

/// <summary>
/// Gets the allow list patterns for this rule. Empty if the rule has no allowed terms.
Expand All @@ -61,7 +61,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable
/// This collection will be empty if <see cref="TriggerType"/> is not
/// <see cref="AutoModTriggerType.Keyword"/>.
/// </remarks>
public IReadOnlyCollection<string> AllowList { get; }
IReadOnlyCollection<string> AllowList { get; }

/// <summary>
/// Gets the preset keyword types for this rule. Empty if the rule has no presets.
Expand All @@ -70,7 +70,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable
/// This collection will be empty if <see cref="TriggerType"/> is not
/// <see cref="AutoModTriggerType.KeywordPreset"/>.
/// </remarks>
public IReadOnlyCollection<KeywordPresetTypes> Presets { get; }
IReadOnlyCollection<KeywordPresetTypes> Presets { get; }

/// <summary>
/// Gets the total mention limit for this rule.
Expand All @@ -79,7 +79,7 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable
/// This property will be <see langword="null"/> if <see cref="TriggerType"/> is not
/// <see cref="AutoModTriggerType.MentionSpam"/>.
/// </remarks>
public int? MentionTotalLimit { get; }
int? MentionTotalLimit { get; }

/// <summary>
/// Gets a collection of actions that will be preformed if a user breaks this rule.
Expand All @@ -101,6 +101,15 @@ public interface IAutoModRule : ISnowflakeEntity, IDeletable
/// </summary>
IReadOnlyCollection<ulong> ExemptChannels { get; }

/// <summary>
/// Gets or sets whether to automatically detect mention raids.
/// </summary>
/// <remarks>
/// This property will be <see langword="null"/> if <see cref="TriggerType"/> is not
/// <see cref="AutoModTriggerType.MentionSpam"/>.
/// </remarks>
bool? MentionRaidProtectionEnabled { get; }

/// <summary>
/// Modifies this rule.
/// </summary>
Expand Down
56 changes: 25 additions & 31 deletions src/Discord.Net.Rest/API/Common/AutoModerationRule.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
35 changes: 16 additions & 19 deletions src/Discord.Net.Rest/API/Common/TriggerMetadata.cs
Original file line number Diff line number Diff line change
@@ -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<string[]> KeywordFilter { get; set; }
[JsonProperty("keyword_filter")]
public Optional<string[]> KeywordFilter { get; set; }

[JsonProperty("regex_patterns")]
public Optional<string[]> RegexPatterns { get; set; }

[JsonProperty("regex_patterns")]
public Optional<string[]> RegexPatterns { get; set; }
[JsonProperty("presets")]
public Optional<KeywordPresetTypes[]> Presets { get; set; }

[JsonProperty("presets")]
public Optional<KeywordPresetTypes[]> Presets { get; set; }
[JsonProperty("allow_list")]
public Optional<string[]> AllowList { get; set; }

[JsonProperty("allow_list")]
public Optional<string[]> AllowList { get; set; }
[JsonProperty("mention_total_limit")]
public Optional<int> MentionLimit { get; set; }

[JsonProperty("mention_total_limit")]
public Optional<int> MentionLimit { get; set; }
}
[JsonProperty("mention_raid_protection_enabled")]
public Optional<bool> MentionRaidProtectionEnabled { get; set; }
}
1 change: 1 addition & 0 deletions src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ public static Task<AutoModerationRule> ModifyRuleAsync(BaseDiscordClient client,
AllowList = args.AllowList.IsSpecified ? args.AllowList : rule.AllowList.ToArray(),
MentionLimit = args.MentionLimit.IsSpecified ? args.MentionLimit : rule.MentionTotalLimit ?? Optional<int>.Unspecified,
Presets = args.Presets.IsSpecified ? args.Presets : rule.Presets.ToArray(),
MentionRaidProtectionEnabled = args.MentionRaidProtectionEnabled.IsSpecified ? args.MentionRaidProtectionEnabled : rule.MentionRaidProtectionEnabled ?? Optional<bool>.Unspecified,
} : Optional<API.TriggerMetadata>.Unspecified
};

Expand Down
4 changes: 4 additions & 0 deletions src/Discord.Net.Rest/Entities/Guilds/RestAutoModRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class RestAutoModRule : RestEntity<ulong>, IAutoModRule
/// <inheritdoc />
public IReadOnlyCollection<ulong> ExemptChannels { get; private set; }

/// <inheritdoc />
public bool? MentionRaidProtectionEnabled { get; private set; }

internal RestAutoModRule(BaseDiscordClient discord, ulong id) : base(discord, id)
{

Expand Down Expand Up @@ -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();
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class SocketAutoModRule : SocketEntity<ulong>, IAutoModRule
/// </summary>
public IReadOnlyCollection<SocketGuildChannel> ExemptChannels { get; private set; }

/// <inheritdoc />
public bool? MentionRaidProtectionEnabled { get; private set; }

/// <inheritdoc/>
public DateTimeOffset CreatedAt
=> SnowflakeUtils.FromSnowflake(Id);
Expand Down Expand Up @@ -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();
}

/// <inheritdoc/>
Expand Down

0 comments on commit 0e9caf3

Please sign in to comment.