Browse Source

add limit checks for tag count

pull/2469/head
Misha133 2 years ago
parent
commit
9ddcfb0eb5
3 changed files with 12 additions and 0 deletions
  1. +3
    -0
      src/Discord.Net.Rest/Entities/Channels/ForumHelper.cs
  2. +7
    -0
      src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs
  3. +2
    -0
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs

+ 3
- 0
src/Discord.Net.Rest/Entities/Channels/ForumHelper.cs View File

@@ -14,6 +14,9 @@ internal static class ForumHelper
{
var args = new ForumChannelProperties();
func(args);

Preconditions.AtMost(args.Tags.IsSpecified ? args.Tags.Value.Count() : 0, 5, nameof(args.Tags), "Forum channel can have max 20 tags.");
var apiArgs = new API.Rest.ModifyForumChannelParams()
{
Name = args.Name,


+ 7
- 0
src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs View File

@@ -1,3 +1,4 @@
using Discord.API;
using Discord.API.Rest;
using System;
using System.Collections.Generic;
@@ -51,6 +52,9 @@ namespace Discord.Rest
{
var args = new ThreadChannelProperties();
func(args);

Preconditions.AtMost(args.AppliedTags.IsSpecified ? args.AppliedTags.Value.Count() : 0, 5, nameof(args.AppliedTags), "Forum post can have max 5 applied tags.");

var apiArgs = new ModifyThreadParams
{
Name = args.Name,
@@ -117,6 +121,7 @@ namespace Discord.Rest
Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.AtMost(tagIds?.Length ?? 0, 5, nameof(tagIds), "Forum post can have max 5 applied tags.");

// check that user flag and user Id list are exclusive, same with role flag and role Id list
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
@@ -178,6 +183,8 @@ namespace Discord.Rest
Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed.");
Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed.");
Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.AtMost(tagIds?.Length ?? 0, 5, nameof(tagIds), "Forum post can have max 5 applied tags.");


// check that user flag and user Id list are exclusive, same with role flag and role Id list
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)


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

@@ -351,6 +351,8 @@ namespace Discord.Rest
var props = new ForumChannelProperties();
func?.Invoke(props);

Preconditions.AtMost(props.Tags.IsSpecified ? props.Tags.Value.Count() : 0, 5, nameof(props.Tags), "Forum channel can have max 20 tags.");

var args = new CreateGuildChannelParams(name, ChannelType.Forum)
{
Position = props.Position,


Loading…
Cancel
Save