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

Disallow modifying the CategoryId for CategoryChannels #1282

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,5 @@ public class GuildChannelProperties
/// Moves the channel to the following position. This property is zero-based.
/// </summary>
public Optional<int> Position { get; set; }
/// <summary>
/// Gets or sets the category ID for this channel.
/// </summary>
/// <remarks>
/// Setting this value to a category's snowflake identifier will change or set this channel's parent to the
/// specified channel; setting this value to <c>0</c> will detach this channel from its parent if one
/// is set.
/// </remarks>
public Optional<ulong?> CategoryId { get; set; }
}
}
18 changes: 18 additions & 0 deletions src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Discord
{
/// <summary>
/// Properties that are used to modify an <see cref="INestedChannel"/> with the specified changes.
/// </summary>
public class NestedChannelProperties : GuildChannelProperties
{
/// <summary>
/// Gets or sets the category ID for this channel.
/// </summary>
/// <remarks>
/// Setting this value to a category's snowflake identifier will change or set this channel's parent to the
/// specified channel; setting this value to <c>null</c> will detach this channel from its parent if one
/// is set.
/// </remarks>
public Optional<ulong?> CategoryId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Discord
/// Provides properties that are used to modify an <see cref="ITextChannel"/> with the specified changes.
/// </summary>
/// <seealso cref="ITextChannel.ModifyAsync(System.Action{TextChannelProperties}, RequestOptions)"/>
public class TextChannelProperties : GuildChannelProperties
public class TextChannelProperties : NestedChannelProperties
{
/// <summary>
/// Gets or sets the topic of the channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Discord
/// <summary>
/// Provides properties that are used to modify an <see cref="IVoiceChannel" /> with the specified changes.
/// </summary>
public class VoiceChannelProperties : GuildChannelProperties
public class VoiceChannelProperties : NestedChannelProperties
{
/// <summary>
/// Gets or sets the bitrate of the voice connections in this channel. Must be greater than 8000.
Expand Down
2 changes: 0 additions & 2 deletions src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ internal class ModifyGuildChannelParams
public Optional<string> Name { get; set; }
[JsonProperty("position")]
public Optional<int> Position { get; set; }
[JsonProperty("parent_id")]
public Optional<ulong?> CategoryId { get; set; }
[JsonProperty("permission_overwrites")]
public Optional<Overwrite[]> Overwrites { get; set; }
}
Expand Down
12 changes: 12 additions & 0 deletions src/Discord.Net.Rest/API/Rest/ModifyNestedChannelParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API.Rest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
internal class ModifyNestedChannelParams : ModifyGuildChannelParams
{
[JsonProperty("parent_id")]
public Optional<ulong?> CategoryId { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Discord.API.Rest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
internal class ModifyTextChannelParams : ModifyGuildChannelParams
internal class ModifyTextChannelParams : ModifyNestedChannelParams
{
[JsonProperty("topic")]
public Optional<string> Topic { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API.Rest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
internal class ModifyVoiceChannelParams : ModifyGuildChannelParams
internal class ModifyVoiceChannelParams : ModifyNestedChannelParams
{
[JsonProperty("bitrate")]
public Optional<int> Bitrate { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordCl
var apiArgs = new API.Rest.ModifyGuildChannelParams
{
Name = args.Name,
Position = args.Position,
CategoryId = args.CategoryId
Position = args.Position
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
}
Expand Down