Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing "default_forum_layout" property for DiscordChannel #466

Merged
merged 7 commits into from Apr 4, 2024
34 changes: 20 additions & 14 deletions DisCatSharp/Entities/Channel/DiscordChannel.cs
Expand Up @@ -234,6 +234,12 @@ public IReadOnlyList<DiscordOverwrite> PermissionOverwrites
[JsonProperty("default_sort_order", NullValueHandling = NullValueHandling.Include)]
public ForumPostSortOrder? DefaultSortOrder { get; internal set; }

/// <summary>
/// Gets the default forum layout for this channel
/// </summary>
[JsonProperty("default_forum_layout", NullValueHandling = NullValueHandling.Ignore)]
public ForumLayout? DefaultForumLayout { get; internal set; }

/// <summary>
/// Gets when the last pinned message was pinned.
/// </summary>
Expand Down Expand Up @@ -324,7 +330,7 @@ internal DiscordChannel(List<string>? ignored = null)
this._permissionOverwritesLazy = new(() => new ReadOnlyCollection<DiscordOverwrite>(this.PermissionOverwritesInternal));
}

#region Methods
#region Methods

/// <summary>
/// Sends a message to this channel.
Expand Down Expand Up @@ -509,7 +515,7 @@ public Task ModifyAsync(Action<ChannelEditModel> action)

return this.Discord.ApiClient.ModifyChannelAsync(this.Id, mdl.Name, mdl.Position, mdl.Topic, mdl.Nsfw,
mdl.Parent.Map(p => p?.Id), mdl.Bitrate, mdl.UserLimit, mdl.PerUserRateLimit, mdl.RtcRegion.Map(r => r?.Id),
mdl.QualityMode, mdl.DefaultAutoArchiveDuration, mdl.Type, mdl.PermissionOverwrites, mdl.Flags, mdl.AuditLogReason);
mdl.QualityMode, mdl.ForumLayout, mdl.DefaultAutoArchiveDuration, mdl.Type, mdl.PermissionOverwrites, mdl.Flags, mdl.AuditLogReason);
}

/// <summary>
Expand All @@ -533,7 +539,7 @@ public Task ModifyForumAsync(Action<ForumChannelEditModel> action)
? throw new NotSupportedException("Cannot have more than 20 tags in a forum channel.")
: (Task)this.Discord.ApiClient.ModifyForumChannelAsync(this.Id, mdl.Name, mdl.Position, mdl.Topic, mdl.Template, mdl.Nsfw,
mdl.Parent.Map(p => p?.Id), mdl.AvailableTags, mdl.DefaultReactionEmoji, mdl.PerUserRateLimit, mdl.PostCreateUserRateLimit,
mdl.DefaultSortOrder, mdl.DefaultAutoArchiveDuration, mdl.PermissionOverwrites, mdl.Flags, mdl.AuditLogReason);
mdl.DefaultSortOrder, mdl.DefaultForumLayout, mdl.DefaultAutoArchiveDuration, mdl.PermissionOverwrites, mdl.Flags, mdl.AuditLogReason);
}

/// <summary>
Expand Down Expand Up @@ -959,7 +965,7 @@ public Task DeleteMessageAsync(DiscordMessage message, string reason = null)
public Task<DiscordInvite> CreateInviteAsync(int maxAge = 86400, int maxUses = 0, bool temporary = false, bool unique = false, TargetType? targetType = null, ulong? targetApplicationId = null, ulong? targetUser = null, string reason = null)
=> this.Discord.ApiClient.CreateChannelInviteAsync(this.Id, maxAge, maxUses, targetType, targetApplicationId, targetUser, temporary, unique, reason);

#region Voice Channel
#region Voice Channel

/// <summary>
/// Sets a voice channels status.
Expand All @@ -982,9 +988,9 @@ public Task SetVoiceChannelStatusAsync(string status)
public Task RemoveVoiceChannelStatusAsync(string reason = null)
=> this.Type != ChannelType.Voice ? throw new NotSupportedException("Cannot execute this request on a non-voice channel.") : this.Discord.ApiClient.ModifyVoiceChannelStatusAsync(this.Id, null);

#endregion
#endregion

#region Stage
#region Stage

/// <summary>
/// Opens a stage.
Expand Down Expand Up @@ -1035,9 +1041,9 @@ public async Task CloseStageAsync(string reason = null)
public async Task<DiscordStageInstance> GetStageAsync()
=> await this.Discord.ApiClient.GetStageInstanceAsync(this.Id).ConfigureAwait(false);

#endregion
#endregion

#region Scheduled Events
#region Scheduled Events

/// <summary>
/// Creates a scheduled event based on the channel type.
Expand All @@ -1061,9 +1067,9 @@ public async Task<DiscordScheduledEvent> CreateScheduledEventAsync(string name,
return await this.Guild.CreateScheduledEventAsync(name, scheduledStartTime, null, this, null, description, type, coverImage, reason).ConfigureAwait(false);
}

#endregion
#endregion

#region Threads
#region Threads

/// <summary>
/// Creates a thread.
Expand Down Expand Up @@ -1198,7 +1204,7 @@ public async Task<DiscordChannel> CreateForumPostTagAsync(string name, DiscordEm
UnicodeEmojiString = emoji?.Id == null || emoji?.Id == 0 ? emoji?.Name ?? null : null,
Moderated = moderated,
Id = null
}).ToList(), Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, null, Optional.None, reason).ConfigureAwait(false);
}).ToList(), Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, null, Optional.None, reason).ConfigureAwait(false);

/// <summary>
/// Deletes a forum channel tag.
Expand All @@ -1210,9 +1216,9 @@ public async Task<DiscordChannel> CreateForumPostTagAsync(string name, DiscordEm
/// <exception cref="BadRequestException">Thrown when an invalid parameter was provided.</exception>
/// <exception cref="ServerErrorException">Thrown when Discord is unable to process the request.</exception>
public async Task<DiscordChannel> DeleteForumPostTag(ulong id, string reason = null)
=> this.Type != ChannelType.Forum ? throw new NotSupportedException("Channel needs to be type of Forum") : await this.Discord.ApiClient.ModifyForumChannelAsync(this.Id, null, null, Optional.None, Optional.None, null, Optional.None, this.InternalAvailableTags?.Where(x => x.Id != id)?.ToList(), Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, null, Optional.None, reason).ConfigureAwait(false);
=> this.Type != ChannelType.Forum ? throw new NotSupportedException("Channel needs to be type of Forum") : await this.Discord.ApiClient.ModifyForumChannelAsync(this.Id, null, null, Optional.None, Optional.None, null, Optional.None, this.InternalAvailableTags?.Where(x => x.Id != id)?.ToList(), Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, null, Optional.None, reason).ConfigureAwait(false);

#endregion
#endregion

/// <summary>
/// Adds a channel permission overwrite for specified role.
Expand Down Expand Up @@ -1457,7 +1463,7 @@ public Permissions PermissionsFor(DiscordMember mbr)
? $"Channel {this.Name} ({this.Id})"
: $"Channel {this.Id}";

#endregion
#endregion

/// <summary>
/// Checks whether this <see cref="DiscordChannel"/> is equal to another object.
Expand Down
4 changes: 3 additions & 1 deletion DisCatSharp/Entities/Guild/DiscordGuild.cs
Expand Up @@ -1361,6 +1361,7 @@ public Task<DiscordChannel> CreateTextChannelAsync(string name, DiscordChannel p
/// <param name="postCreateUserRateLimit">Slow mode timeout for user post creations.</param>
/// <param name="defaultAutoArchiveDuration">The default auto archive duration for new threads.</param>
/// <param name="defaultSortOrder">The default sort order for posts in the new channel.</param>
/// <param name="defaultLayout">The default forum layout for this channel</param>
/// <param name="flags">The flags of the new channel.</param>
/// <param name="reason">Reason for audit logs.</param>
/// <returns>The newly-created channel.</returns>
Expand All @@ -1379,10 +1380,11 @@ public Task<DiscordChannel> CreateTextChannelAsync(string name, DiscordChannel p
Optional<int?> postCreateUserRateLimit = default,
ThreadAutoArchiveDuration defaultAutoArchiveDuration = ThreadAutoArchiveDuration.OneDay,
Optional<ForumPostSortOrder> defaultSortOrder = default,
Optional<ForumLayout?> defaultLayout = default,
Optional<ChannelFlags?> flags = default,
string reason = null
)
=> this.Discord.ApiClient.CreateForumChannelAsync(this.Id, name, parent?.Id, topic, null, nsfw, defaultReactionEmoji, perUserRateLimit, postCreateUserRateLimit, defaultSortOrder, defaultAutoArchiveDuration, overwrites, flags, reason);
=> this.Discord.ApiClient.CreateGuildForumChannelAsync(this.Id, name, parent?.Id, topic, null, nsfw, defaultReactionEmoji, perUserRateLimit, postCreateUserRateLimit, defaultSortOrder, defaultLayout, defaultAutoArchiveDuration, overwrites, flags, reason);

/// <summary>
/// Creates a new channel category in this guild.
Expand Down
4 changes: 2 additions & 2 deletions DisCatSharp/Entities/Guild/ThreadAndForum/ForumPostTag.cs
Expand Up @@ -96,7 +96,7 @@ public async Task<ForumPostTag> ModifyAsync(Action<ForumPostTagEditModel> action
Moderated = mdl.Moderated.HasValue ? mdl.Moderated.Value : this.Moderated,
Name = mdl.Name.HasValue ? mdl.Name.Value : this.Name,
UnicodeEmojiString = mdl.Emoji.HasValue ? mdl.Emoji.Value.Name : this.UnicodeEmojiString
}).ToList(), null, null, null, null, null, null, null, mdl.AuditLogReason);
}).ToList(), null, null, null, null, null, null, null, null, mdl.AuditLogReason);
return res.InternalAvailableTags.First(x => x.Id == this.Id);
}

Expand All @@ -105,7 +105,7 @@ public async Task<ForumPostTag> ModifyAsync(Action<ForumPostTagEditModel> action
/// </summary>
/// <exception cref="NotImplementedException">This method is currently not implemented.</exception>
public Task DeleteAsync(string reason = null)
=> this.Discord.ApiClient.ModifyForumChannelAsync(this.ChannelId, null, null, Optional.None, Optional.None, null, Optional.None, this.Channel.InternalAvailableTags.Where(x => x.Id != this.Id).ToList(), Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, null, Optional.None, reason);
=> this.Discord.ApiClient.ModifyForumChannelAsync(this.ChannelId, null, null, Optional.None, Optional.None, null, Optional.None, this.Channel.InternalAvailableTags.Where(x => x.Id != this.Id).ToList(), Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, Optional.None, null, Optional.None, reason);

/// <summary>
/// Checks whether this <see cref="ForumPostTag"/> is equal to another object.
Expand Down
12 changes: 12 additions & 0 deletions DisCatSharp/Net/Abstractions/Rest/RestChannelPayloads.cs
Expand Up @@ -99,6 +99,12 @@ internal sealed class RestChannelCreatePayload : ObservableApiObject
[JsonProperty("default_sort_order", NullValueHandling = NullValueHandling.Ignore)]
public Optional<ForumPostSortOrder> DefaultSortOrder { get; internal set; }

/// <summary>
/// Gets the default forum layout for this channel
/// </summary>
[JsonProperty("default_forum_layout", NullValueHandling = NullValueHandling.Ignore)]
public Optional<ForumLayout?> DefaultForumLayout { get; internal set; }

/// <summary>
/// Gets or sets the channel flags.
/// </summary>
Expand Down Expand Up @@ -210,6 +216,12 @@ internal sealed class RestChannelModifyPayload : ObservableApiObject
[JsonProperty("default_sort_order", NullValueHandling = NullValueHandling.Ignore)]
public Optional<ForumPostSortOrder?> DefaultSortOrder { get; internal set; }

/// <summary>
/// Gets the default forum layout for this channel
/// </summary>
[JsonProperty("default_forum_layout", NullValueHandling = NullValueHandling.Ignore)]
public Optional<ForumLayout?> ForumLayout { get; internal set; }

/// <summary>
/// Gets or sets the channel flags.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions DisCatSharp/Net/Models/ChannelEditModel.cs
Expand Up @@ -80,6 +80,11 @@ public class ChannelEditModel : BaseEditModel
/// </summary>
public IEnumerable<DiscordOverwriteBuilder> PermissionOverwrites { internal get; set; }

/// <summary>
/// Sets the channel's default forum layout
/// </summary>
public ForumLayout? ForumLayout { internal get; set; }

public Optional<ChannelFlags?> Flags { internal get; set; }

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions DisCatSharp/Net/Models/ForumChannelEditModel.cs
Expand Up @@ -51,6 +51,11 @@ public class ForumChannelEditModel : BaseEditModel
/// </summary>
public Optional<ForumPostSortOrder?> DefaultSortOrder { internal get; set; }

/// <summary>
/// Sets the default forum layout
/// </summary>
public Optional<ForumLayout?> DefaultForumLayout { get; internal set; }

/// <summary>
/// <para>Sets the parent of this channel.</para>
/// <para>This should be channel with <see cref="DisCatSharp.Entities.DiscordChannel.Type"/> set to <see cref="ChannelType.Category"/>.</para>
Expand Down