@@ -8,12 +8,25 @@ public class ForumTagBuilder
private string? _name;
private IEmote? _emoji;
private bool _moderated;
private ulong? _id;
/// <summary>
/// Returns the maximum length of name allowed by Discord.
/// </summary>
public const int MaxNameLength = 20;
/// <summary>
/// Gets or sets the snowflake Id of the tag.
/// </summary>
/// <remarks>
/// If set this will update existing tag or will create a new one otherwise.
/// </remarks>
public ulong? Id
{
get { return _id; }
set { _id = value; }
}
/// <summary>
/// Gets or sets the name of the tag.
/// </summary>
@@ -50,7 +63,7 @@ public class ForumTagBuilder
/// <summary>
/// Initializes a new <see cref="ForumTagBuilder"/> class.
/// </summary>
/// </summary>
public ForumTagBuilder()
{
@@ -59,31 +72,48 @@ public class ForumTagBuilder
/// <summary>
/// Initializes a new <see cref="ForumTagBuilder"/> class with values
/// </summary>
public ForumTagBuilder(string name)
/// <param name="id"> If set existing tag will be updated or a new one will be created otherwise.</param>
/// <param name="name"> Name of the tag.</param>
/// <param name="isModerated"> Sets whether this tag can only be added to or removed from threads by a member
/// with the <see cref="GuildPermissions.ManageThreads"/> permission. </param>
public ForumTagBuilder(string name, ulong? id = null, bool isModerated = false)
{
Name = name;
IsModerated = false;
IsModerated = isModerated;
Id = id;
}
/// <summary>
/// Initializes a new <see cref="ForumTagBuilder"/> class with values
/// </summary>
public ForumTagBuilder(string name, IEmote? emoji = null, bool moderated = false)
/// <param name="name"> Name of the tag.</param>
/// <param name="id"> If set existing tag will be updated or a new one will be created otherwise.</param>
/// <param name="emoji"> Display emoji of the tag.</param>
/// <param name="isModerated"> Sets whether this tag can only be added to or removed from threads by a member
/// with the <see cref="GuildPermissions.ManageThreads"/> permission. </param>
public ForumTagBuilder(string name, ulong? id = null, bool isModerated = false, IEmote? emoji = null)
{
Name = name;
Emoji = emoji;
IsModerated = moderated;
IsModerated = isModerated;
Id = id;
}
/// <summary>
/// Initializes a new <see cref="ForumTagBuilder"/> class with values
/// </summary>
public ForumTagBuilder(string name, ulong? emoteId = null, bool moderated = false)
/// /// <param name="name"> Name of the tag.</param>
/// <param name="id"> If set existing tag will be updated or a new one will be created otherwise.</param>
/// <param name="emoteId"> The id of custom Display emoji of the tag.</param>
/// <param name="isModerated"> Sets whether this tag can only be added to or removed from threads by a member
/// with the <see cref="GuildPermissions.ManageThreads"/> permission </param>
public ForumTagBuilder(string name, ulong? id = null, bool isModerated = false, ulong? emoteId = null)
{
Name = name;
if(emoteId is not null)
Emoji = new Emote(emoteId.Value, null, false);
IsModerated = moderated;
IsModerated = isModerated;
Id = id;
}
/// <summary>
@@ -108,6 +138,17 @@ public class ForumTagBuilder
return this;
}
/// <summary>
/// Sets the id of the tag.
/// </summary>
/// <param name="id"> If set existing tag will be updated or a new one will be created otherwise.</param>
/// <exception cref="ArgumentException">Name length must be less than or equal to <see cref="MaxNameLength"/>.</exception>
public ForumTagBuilder WithId(ulong? id)
{
Id = id;
return this;
}
/// <summary>
/// Sets the emoji of the tag.
/// </summary>
@@ -118,11 +159,33 @@ public class ForumTagBuilder
}
/// <summary>
/// Sets the IsModerated of the tag.
/// Sets whether this tag can only be added to or removed from threads by a member
/// with the <see cref="GuildPermissions.ManageThreads"/> permission
/// </summary>
public ForumTagBuilder WithModerated(bool moderated)
{
IsModerated = moderated;
return this;
}
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object? obj)
=> obj is ForumTagBuilder builder && Equals(builder);
/// <summary>
/// Gets whether supplied tag builder is equals to the current one.
/// </summary>
public bool Equals(ForumTagBuilder? builder)
=> builder is not null &&
Id == builder.Id &&
Name == builder.Name &&
(Emoji is Emoji emoji && builder.Emoji is Emoji otherEmoji && emoji.Equals(otherEmoji) ||
Emoji is Emote emote && builder.Emoji is Emote otherEmote && emote.Equals(otherEmote)) &&
IsModerated == builder.IsModerated;
public static bool operator ==(ForumTagBuilder? left, ForumTagBuilder? right)
=> left?.Equals(right) ?? right is null ;
public static bool operator !=(ForumTagBuilder? left, ForumTagBuilder? right) => !(left == right);
}