[Feature] Add missing properties in forum & thread channels (#2469)
* add `AppliedTags` property * convert collections into immutable arrays * remove "not supported" remark * implement `ThreadChannelProperties` * Add `DefaultSlowModeInterval` and `DefaultSlowModeInterval` properties to forum channels * add `Moderated` property to `ForumTag`` * `ForumTag` inherits `ISnowflakeEntity` * Fix `DiscordRestClient.GetChannelAsync` not getting forum channel * a lot of changes added: - channel flags - `ForumTagBuilder` - imroved channel modification * fixed a bug in forum tag emoji parsing * inherit forum channel from `INesteeChannel` * implement `INestedChannel` in forum channels * Add `Flags` property to channels * add iteraface for forum tags & add equality operators * Add default reaction emoji property * add support for modifing default reaction & some renaming * add createForumChannelAsync to guild * *fix resharper being a d... and moving code to next line* * add a `ForumChannels` property * Some fixes & add support for `default_sort_order` * fix misleading comment * fix #2502 * support creating post with applied tags * fix xmldoc * set category id on model update * add limit checks for tag count
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Discord.API;
|
||||
using Discord.API.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -46,18 +47,23 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
public static async Task<Model> ModifyAsync(IThreadChannel channel, BaseDiscordClient client,
|
||||
Action<TextChannelProperties> func,
|
||||
Action<ThreadChannelProperties> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new TextChannelProperties();
|
||||
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,
|
||||
Archived = args.Archived,
|
||||
AutoArchiveDuration = args.AutoArchiveDuration,
|
||||
Locked = args.Locked,
|
||||
Slowmode = args.SlowModeInterval
|
||||
Slowmode = args.SlowModeInterval,
|
||||
AppliedTags = args.AppliedTags,
|
||||
Flags = args.Flags,
|
||||
};
|
||||
return await client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
@@ -103,7 +109,10 @@ namespace Discord.Rest
|
||||
return RestThreadUser.Create(client, channel.Guild, model, channel);
|
||||
}
|
||||
|
||||
public static async Task<RestThreadChannel> CreatePostAsync(IForumChannel channel, BaseDiscordClient client, string title, ThreadArchiveDuration archiveDuration = ThreadArchiveDuration.OneDay, int? slowmode = null, string text = null, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None)
|
||||
public static async Task<RestThreadChannel> CreatePostAsync(IForumChannel channel, BaseDiscordClient client, string title,
|
||||
ThreadArchiveDuration archiveDuration = ThreadArchiveDuration.OneDay, int? slowmode = null, string text = null, Embed embed = null,
|
||||
RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, ISticker[] stickers = null,
|
||||
Embed[] embeds = null, MessageFlags flags = MessageFlags.None, ulong[] tagIds = null)
|
||||
{
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
@@ -112,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)
|
||||
@@ -134,10 +144,12 @@ namespace Discord.Rest
|
||||
Preconditions.AtMost(stickers.Length, 3, nameof(stickers), "A max of 3 stickers are allowed.");
|
||||
}
|
||||
|
||||
|
||||
if (flags is not MessageFlags.None and not MessageFlags.SuppressEmbeds)
|
||||
throw new ArgumentException("The only valid MessageFlags are SuppressEmbeds and none.", nameof(flags));
|
||||
|
||||
if (channel.Flags.HasFlag(ChannelFlags.RequireTag))
|
||||
throw new ArgumentException($"The channel {channel.Name} requires posts to have at least one tag.");
|
||||
|
||||
var args = new CreatePostParams()
|
||||
{
|
||||
Title = title,
|
||||
@@ -151,7 +163,8 @@ namespace Discord.Rest
|
||||
Flags = flags,
|
||||
Components = components?.Components?.Any() ?? false ? components.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified,
|
||||
Stickers = stickers?.Any() ?? false ? stickers.Select(x => x.Id).ToArray() : Optional<ulong[]>.Unspecified,
|
||||
}
|
||||
},
|
||||
Tags = tagIds
|
||||
};
|
||||
|
||||
var model = await client.ApiClient.CreatePostAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
@@ -159,7 +172,9 @@ namespace Discord.Rest
|
||||
return RestThreadChannel.Create(client, channel.Guild, model);
|
||||
}
|
||||
|
||||
public static async Task<RestThreadChannel> CreatePostAsync(IForumChannel channel, BaseDiscordClient client, string title, IEnumerable<FileAttachment> attachments, ThreadArchiveDuration archiveDuration, int? slowmode, string text, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageComponent components, ISticker[] stickers, Embed[] embeds, MessageFlags flags)
|
||||
public static async Task<RestThreadChannel> CreatePostAsync(IForumChannel channel, BaseDiscordClient client, string title, IEnumerable<FileAttachment> attachments,
|
||||
ThreadArchiveDuration archiveDuration, int? slowmode, string text, Embed embed, RequestOptions options, AllowedMentions allowedMentions, MessageComponent components,
|
||||
ISticker[] stickers, Embed[] embeds, MessageFlags flags, ulong[] tagIds = null)
|
||||
{
|
||||
embeds ??= Array.Empty<Embed>();
|
||||
if (embed != null)
|
||||
@@ -168,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)
|
||||
@@ -190,9 +207,11 @@ namespace Discord.Rest
|
||||
Preconditions.AtMost(stickers.Length, 3, nameof(stickers), "A max of 3 stickers are allowed.");
|
||||
}
|
||||
|
||||
|
||||
if (flags is not MessageFlags.None and not MessageFlags.SuppressEmbeds)
|
||||
throw new ArgumentException("The only valid MessageFlags are SuppressEmbeds and none.", nameof(flags));
|
||||
|
||||
if (channel.Flags.HasFlag(ChannelFlags.RequireTag))
|
||||
throw new ArgumentException($"The channel {channel.Name} requires posts to have at least one tag.");
|
||||
|
||||
var args = new CreateMultipartPostAsync(attachments.ToArray())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user