[Fix] Forum channel related issues.
This commit is contained in:
@@ -31,7 +31,7 @@ public class ForumChannelProperties : TextChannelProperties
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a collection of tags inside of this forum channel.
|
/// Gets or sets a collection of tags inside of this forum channel.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Optional<IEnumerable<ForumTagProperties>> Tags { get; set; }
|
public Optional<IEnumerable<IForumTag>> Tags { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a new default reaction emoji in this forum channel.
|
/// Gets or sets a new default reaction emoji in this forum channel.
|
||||||
|
|||||||
@@ -1,67 +1,62 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A struct representing a forum channel tag.
|
||||||
|
/// </summary>
|
||||||
|
public readonly struct ForumTag : ISnowflakeEntity, IForumTag
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc/>
|
||||||
/// A struct representing a forum channel tag.
|
public ulong Id { get; }
|
||||||
/// </summary>
|
|
||||||
public struct ForumTag : ISnowflakeEntity, IForumTag
|
/// <inheritdoc/>
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IEmote? Emoji { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool IsModerated { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||||
|
|
||||||
|
internal ForumTag(ulong id, string name, ulong? emojiId = null, string? emojiName = null, bool moderated = false)
|
||||||
{
|
{
|
||||||
/// <summary>
|
if (emojiId.HasValue && emojiId.Value != 0)
|
||||||
/// Gets the Id of the tag.
|
Emoji = new Emote(emojiId.Value, null, false);
|
||||||
/// </summary>
|
else if (emojiName != null)
|
||||||
public ulong Id { get; }
|
Emoji = new Emoji(emojiName);
|
||||||
|
else
|
||||||
|
Emoji = null;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
Id = id;
|
||||||
public string Name { get; }
|
Name = name;
|
||||||
|
IsModerated = moderated;
|
||||||
/// <inheritdoc/>
|
|
||||||
public IEmote? Emoji { get; }
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public bool IsModerated { get; }
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
|
||||||
|
|
||||||
internal ForumTag(ulong id, string name, ulong? emojiId = null, string? emojiName = null, bool moderated = false)
|
|
||||||
{
|
|
||||||
if (emojiId.HasValue && emojiId.Value != 0)
|
|
||||||
Emoji = new Emote(emojiId.Value, null, false);
|
|
||||||
else if (emojiName != null)
|
|
||||||
Emoji = new Emoji(emojiName);
|
|
||||||
else
|
|
||||||
Emoji = null;
|
|
||||||
|
|
||||||
Id = id;
|
|
||||||
Name = name;
|
|
||||||
IsModerated = moderated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode() => (Id, Name, Emoji, IsModerated).GetHashCode();
|
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
|
||||||
=> obj is ForumTag tag && Equals(tag);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether supplied tag is equals to the current one.
|
|
||||||
/// </summary>
|
|
||||||
public bool Equals(ForumTag tag)
|
|
||||||
=> Id == tag.Id &&
|
|
||||||
Name == tag.Name &&
|
|
||||||
(Emoji is Emoji emoji && tag.Emoji is Emoji otherEmoji && emoji.Equals(otherEmoji) ||
|
|
||||||
Emoji is Emote emote && tag.Emoji is Emote otherEmote && emote.Equals(otherEmote)) &&
|
|
||||||
IsModerated == tag.IsModerated;
|
|
||||||
|
|
||||||
public static bool operator ==(ForumTag? left, ForumTag? right)
|
|
||||||
=> left?.Equals(right) ?? right is null;
|
|
||||||
|
|
||||||
public static bool operator !=(ForumTag? left, ForumTag? right) => !(left == right);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode() => (Id, Name, Emoji, IsModerated).GetHashCode();
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
=> obj is ForumTag tag && Equals(tag);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether supplied tag is equals to the current one.
|
||||||
|
/// </summary>
|
||||||
|
public bool Equals(ForumTag tag)
|
||||||
|
=> Id == tag.Id &&
|
||||||
|
Name == tag.Name &&
|
||||||
|
(Emoji is Emoji emoji && tag.Emoji is Emoji otherEmoji && emoji.Equals(otherEmoji) ||
|
||||||
|
Emoji is Emote emote && tag.Emoji is Emote otherEmote && emote.Equals(otherEmote)) &&
|
||||||
|
IsModerated == tag.IsModerated;
|
||||||
|
|
||||||
|
public static bool operator ==(ForumTag? left, ForumTag? right)
|
||||||
|
=> left?.Equals(right) ?? right is null;
|
||||||
|
|
||||||
|
public static bool operator !=(ForumTag? left, ForumTag? right) => !(left == right);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
readonly ulong? IForumTag.Id => Id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,8 +124,8 @@ public class ForumTagBuilder
|
|||||||
public ForumTagProperties Build()
|
public ForumTagProperties Build()
|
||||||
{
|
{
|
||||||
if (_name is null)
|
if (_name is null)
|
||||||
throw new ArgumentNullException(nameof(Name), "Name must be set to build the tag");
|
throw new ArgumentNullException(nameof(Name), "Name must be set to build the tag.");
|
||||||
return new ForumTagProperties(_name!, _emoji, _moderated);
|
return new ForumTagProperties(_id, _name, _emoji, _moderated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class ForumTagProperties : IForumTag
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Id of the tag.
|
/// Gets the Id of the tag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ulong Id { get; }
|
public ulong? Id { get; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
@@ -18,11 +18,12 @@ public class ForumTagProperties : IForumTag
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool IsModerated { get; }
|
public bool IsModerated { get; }
|
||||||
|
|
||||||
internal ForumTagProperties(string name, IEmote? emoji = null, bool isMmoderated = false)
|
internal ForumTagProperties(ulong? id, string name, IEmote? emoji = null, bool isModerated = false)
|
||||||
{
|
{
|
||||||
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Emoji = emoji;
|
Emoji = emoji;
|
||||||
IsModerated = isMmoderated;
|
IsModerated = isModerated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode() => (Id, Name, Emoji, IsModerated).GetHashCode();
|
public override int GetHashCode() => (Id, Name, Emoji, IsModerated).GetHashCode();
|
||||||
|
|||||||
@@ -7,6 +7,14 @@ namespace Discord;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IForumTag
|
public interface IForumTag
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Id of the tag.
|
||||||
|
///</summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This property may be <see langword="null"/> if the object is <see cref="ForumTagProperties"/>.
|
||||||
|
/// </remarks>
|
||||||
|
ulong? Id { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the tag.
|
/// Gets the name of the tag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ namespace Discord.API.Rest
|
|||||||
|
|
||||||
if (Slowmode.IsSpecified)
|
if (Slowmode.IsSpecified)
|
||||||
payload["rate_limit_per_user"] = Slowmode.Value;
|
payload["rate_limit_per_user"] = Slowmode.Value;
|
||||||
|
if (TagIds.IsSpecified)
|
||||||
|
payload["applied_tags"] = TagIds.Value;
|
||||||
|
|
||||||
// message
|
// message
|
||||||
if (Content.IsSpecified)
|
if (Content.IsSpecified)
|
||||||
@@ -60,8 +62,6 @@ namespace Discord.API.Rest
|
|||||||
message["sticker_ids"] = Stickers.Value;
|
message["sticker_ids"] = Stickers.Value;
|
||||||
if (Flags.IsSpecified)
|
if (Flags.IsSpecified)
|
||||||
message["flags"] = Flags.Value;
|
message["flags"] = Flags.Value;
|
||||||
if (TagIds.IsSpecified)
|
|
||||||
message["applied_tags"] = TagIds.Value;
|
|
||||||
|
|
||||||
List<object> attachments = new();
|
List<object> attachments = new();
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ internal static class ForumHelper
|
|||||||
var args = new ForumChannelProperties();
|
var args = new ForumChannelProperties();
|
||||||
func(args);
|
func(args);
|
||||||
|
|
||||||
Preconditions.AtMost(args.Tags.IsSpecified ? args.Tags.Value.Count() : 0, 5, nameof(args.Tags), "Forum channel can have max 20 tags.");
|
Preconditions.AtMost(args.Tags.IsSpecified ? args.Tags.Value.Count() : 0, 20, nameof(args.Tags), "Forum channel can have max 20 tags.");
|
||||||
|
|
||||||
var apiArgs = new API.Rest.ModifyForumChannelParams()
|
var apiArgs = new API.Rest.ModifyForumChannelParams()
|
||||||
{
|
{
|
||||||
@@ -36,6 +36,7 @@ internal static class ForumHelper
|
|||||||
Tags = args.Tags.IsSpecified
|
Tags = args.Tags.IsSpecified
|
||||||
? args.Tags.Value.Select(tag => new API.ModifyForumTagParams
|
? args.Tags.Value.Select(tag => new API.ModifyForumTagParams
|
||||||
{
|
{
|
||||||
|
Id = tag.Id ?? Optional<ulong>.Unspecified,
|
||||||
Name = tag.Name,
|
Name = tag.Name,
|
||||||
EmojiId = tag.Emoji is Emote emote
|
EmojiId = tag.Emoji is Emote emote
|
||||||
? emote.Id
|
? emote.Id
|
||||||
|
|||||||
@@ -229,7 +229,8 @@ namespace Discord.Rest
|
|||||||
MessageComponent = components?.Components?.Any() ?? false ? components.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified,
|
MessageComponent = components?.Components?.Any() ?? false ? components.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional<API.ActionRowComponent[]>.Unspecified,
|
||||||
Slowmode = slowmode,
|
Slowmode = slowmode,
|
||||||
Stickers = stickers?.Any() ?? false ? stickers.Select(x => x.Id).ToArray() : Optional<ulong[]>.Unspecified,
|
Stickers = stickers?.Any() ?? false ? stickers.Select(x => x.Id).ToArray() : Optional<ulong[]>.Unspecified,
|
||||||
Title = title
|
Title = title,
|
||||||
|
TagIds = tagIds
|
||||||
};
|
};
|
||||||
|
|
||||||
var model = await client.ApiClient.CreatePostAsync(channel.Id, args, options);
|
var model = await client.ApiClient.CreatePostAsync(channel.Id, args, options);
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ namespace Discord.Rest
|
|||||||
AvailableTags = props.Tags.GetValueOrDefault(Array.Empty<ForumTagProperties>()).Select(
|
AvailableTags = props.Tags.GetValueOrDefault(Array.Empty<ForumTagProperties>()).Select(
|
||||||
x => new ModifyForumTagParams
|
x => new ModifyForumTagParams
|
||||||
{
|
{
|
||||||
Id = x.Id,
|
Id = x.Id ?? Optional<ulong>.Unspecified,
|
||||||
Name = x.Name,
|
Name = x.Name,
|
||||||
EmojiId = x.Emoji is Emote emote
|
EmojiId = x.Emoji is Emote emote
|
||||||
? emote.Id
|
? emote.Id
|
||||||
|
|||||||
Reference in New Issue
Block a user