[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;
|
||||
@@ -252,6 +253,7 @@ namespace Discord.Rest
|
||||
Deny = overwrite.Permissions.DenyValue.ToString()
|
||||
}).ToArray()
|
||||
: Optional.Create<API.Overwrite[]>(),
|
||||
DefaultAutoArchiveDuration = props.AutoArchiveDuration
|
||||
};
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return RestTextChannel.Create(client, guild, model);
|
||||
@@ -338,6 +340,65 @@ namespace Discord.Rest
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return RestCategoryChannel.Create(client, guild, model);
|
||||
}
|
||||
|
||||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
|
||||
public static async Task<RestForumChannel> CreateForumChannelAsync(IGuild guild, BaseDiscordClient client,
|
||||
string name, RequestOptions options, Action<ForumChannelProperties> func = null)
|
||||
{
|
||||
if (name == null)
|
||||
throw new ArgumentNullException(paramName: nameof(name));
|
||||
|
||||
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,
|
||||
Overwrites = props.PermissionOverwrites.IsSpecified
|
||||
? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite
|
||||
{
|
||||
TargetId = overwrite.TargetId,
|
||||
TargetType = overwrite.TargetType,
|
||||
Allow = overwrite.Permissions.AllowValue.ToString(),
|
||||
Deny = overwrite.Permissions.DenyValue.ToString()
|
||||
}).ToArray()
|
||||
: Optional.Create<API.Overwrite[]>(),
|
||||
SlowModeInterval = props.ThreadCreationInterval,
|
||||
AvailableTags = props.Tags.GetValueOrDefault(Array.Empty<ForumTagProperties>()).Select(
|
||||
x => new ModifyForumTagParams
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
EmojiId = x.Emoji is Emote emote
|
||||
? emote.Id
|
||||
: Optional<ulong?>.Unspecified,
|
||||
EmojiName = x.Emoji is Emoji emoji
|
||||
? emoji.Name
|
||||
: Optional<string>.Unspecified,
|
||||
Moderated = x.IsModerated
|
||||
}).ToArray(),
|
||||
DefaultReactionEmoji = props.DefaultReactionEmoji.IsSpecified
|
||||
? new API.ModifyForumReactionEmojiParams
|
||||
{
|
||||
EmojiId = props.DefaultReactionEmoji.Value is Emote emote ?
|
||||
emote.Id : Optional<ulong?>.Unspecified,
|
||||
EmojiName = props.DefaultReactionEmoji.Value is Emoji emoji ?
|
||||
emoji.Name : Optional<string>.Unspecified
|
||||
}
|
||||
: Optional<ModifyForumReactionEmojiParams>.Unspecified,
|
||||
ThreadRateLimitPerUser = props.DefaultSlowModeInterval,
|
||||
CategoryId = props.CategoryId,
|
||||
IsNsfw = props.IsNsfw,
|
||||
Topic = props.Topic,
|
||||
DefaultAutoArchiveDuration = props.AutoArchiveDuration,
|
||||
DefaultSortOrder = props.DefaultSortOrder.GetValueOrDefault(ForumSortOrder.LatestActivity)
|
||||
};
|
||||
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return RestForumChannel.Create(client, guild, model);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Voice Regions
|
||||
|
||||
Reference in New Issue
Block a user