Browse Source

made some properties optional

pull/2578/head
Misha133 2 years ago
parent
commit
5a430f9e48
5 changed files with 33 additions and 13 deletions
  1. +15
    -0
      src/Discord.Net.Core/Entities/Guilds/AutoModeration/AutoModRuleProperties.cs
  2. +2
    -2
      src/Discord.Net.Core/Entities/Guilds/AutoModeration/IAutoModRule.cs
  3. +5
    -5
      src/Discord.Net.Rest/API/Common/TriggerMetadata.cs
  4. +3
    -0
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  5. +8
    -6
      src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs

+ 15
- 0
src/Discord.Net.Core/Entities/Guilds/AutoModeration/AutoModRuleProperties.cs View File

@@ -31,6 +31,21 @@ namespace Discord
/// </summary>
public Optional<string[]> KeywordFilter { get; set; }

/// <summary>
/// Gets or sets regex patterns for the rule.
/// </summary>
public Optional<string[]> RegexPatterns { get; set; }

/// <summary>
/// Gets or sets the allow list for the rule.
/// </summary>
public Optional<string[]> AllowList { get; set; }

/// <summary>
/// Gets or sets total mention limit for the rule.
/// </summary>
public Optional<int> MentionLimit { get; set; }

/// <summary>
/// Gets or sets the presets for the rule.
/// </summary>


+ 2
- 2
src/Discord.Net.Core/Entities/Guilds/AutoModeration/IAutoModRule.cs View File

@@ -76,10 +76,10 @@ namespace Discord
/// Gets the total mention limit for this rule.
/// </summary>
/// <remarks>
/// This collection will be empty if <see cref="TriggerType"/> is not
/// This property will be <see langword="null"/> if <see cref="TriggerType"/> is not
/// <see cref="AutoModTriggerType.MentionSpam"/>.
/// </remarks>
public int MentionTotalLimit { get; }
public int? MentionTotalLimit { get; }

/// <summary>
/// Gets a collection of actions that will be preformed if a user breaks this rule.


+ 5
- 5
src/Discord.Net.Rest/API/Common/TriggerMetadata.cs View File

@@ -10,18 +10,18 @@ namespace Discord.API
internal class TriggerMetadata
{
[JsonProperty("keyword_filter")]
public string[] KeywordFilter { get; set; }
public Optional<string[]> KeywordFilter { get; set; }

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

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

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

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

+ 3
- 0
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -1087,6 +1087,9 @@ namespace Discord.Rest
TriggerMetadata = args.KeywordFilter.IsSpecified || args.Presets.IsSpecified ? new API.TriggerMetadata
{
KeywordFilter = args.KeywordFilter.GetValueOrDefault(Array.Empty<string>()),
RegexPatterns = args.RegexPatterns.GetValueOrDefault(Array.Empty<string>()),
AllowList = args.AllowList.GetValueOrDefault(Array.Empty<string>()),
MentionLimit = args.MentionLimit,
Presets = args.Presets.GetValueOrDefault(Array.Empty<KeywordPresetTypes>())
} : Optional<API.TriggerMetadata>.Unspecified
};


+ 8
- 6
src/Discord.Net.WebSocket/Entities/Guilds/SocketAutoModRule.cs View File

@@ -46,7 +46,7 @@ namespace Discord.WebSocket
public IReadOnlyCollection<AutoModRuleAction> Actions { get; private set; }

/// <inheritdoc/>
public int MentionTotalLimit { get; private set; }
public int? MentionTotalLimit { get; private set; }

/// <inheritdoc/>
public bool Enabled { get; private set; }
@@ -87,11 +87,13 @@ namespace Discord.WebSocket
Creator ??= Guild.GetUser(_creatorId);
EventType = model.EventType;
TriggerType = model.TriggerType;
KeywordFilter = model.TriggerMetadata.KeywordFilter.ToImmutableArray();
Presets = model.TriggerMetadata.Presets.ToImmutableArray();
RegexPatterns = model.TriggerMetadata.RegexPatterns.ToImmutableArray();
AllowList = model.TriggerMetadata.AllowList.ToImmutableArray();
MentionTotalLimit = model.TriggerMetadata.MentionLimit;
KeywordFilter = model.TriggerMetadata.KeywordFilter.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
Presets = model.TriggerMetadata.Presets.GetValueOrDefault(Array.Empty<KeywordPresetTypes>()).ToImmutableArray();
RegexPatterns = model.TriggerMetadata.RegexPatterns.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
AllowList = model.TriggerMetadata.AllowList.GetValueOrDefault(Array.Empty<string>()).ToImmutableArray();
MentionTotalLimit = model.TriggerMetadata.MentionLimit.IsSpecified
? model.TriggerMetadata.MentionLimit.Value
: null;
Actions = model.Actions.Select(x => new AutoModRuleAction(x.Type, x.Metadata.GetValueOrDefault()?.ChannelId.ToNullable(), x.Metadata.GetValueOrDefault()?.DurationSeconds.ToNullable())).ToImmutableArray();
Enabled = model.Enabled;
ExemptRoles = model.ExemptRoles.Select(x => Guild.GetRole(x)).ToImmutableArray();


Loading…
Cancel
Save