From b919a1e52ce30afb558ac1ca9fe7ecdeac378213 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Wed, 13 Mar 2019 01:41:29 -0700 Subject: [PATCH 1/2] Add NestedChannelProperties type This change fixes an issue that was introduced with the INestedChannel type. Previously, it was possible to use ModifyAsync on a ChannelCategory to set it's CategoryId. This is not supported, and would probably error. This is a breaking change, however I can't imagine that anyone was trying to nest categories before this. I don't think that it should affect anyone. This change adds the NestedChannelProperties and ModifyNestedChannelParams types, which follow the same class hierarchy as the public-facing channel entities. This allows only guild voice and text channels to be placed under a category. The change --- .../Channels/GuildChannelProperties.cs | 9 --------- .../Channels/NestedChannelProperties.cs | 18 ++++++++++++++++++ .../Entities/Channels/TextChannelProperties.cs | 2 +- .../Channels/VoiceChannelProperties.cs | 2 +- .../API/Rest/ModifyGuildChannelParams.cs | 2 -- .../API/Rest/ModifyNestedChannelParams.cs | 12 ++++++++++++ .../API/Rest/ModifyTextChannelParams.cs | 2 +- .../API/Rest/ModifyVoiceChannelParams.cs | 4 ++-- .../Entities/Channels/ChannelHelper.cs | 3 +-- 9 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs create mode 100644 src/Discord.Net.Rest/API/Rest/ModifyNestedChannelParams.cs diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs index 9552b0a60..ff94f9ae7 100644 --- a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs @@ -21,14 +21,5 @@ namespace Discord /// Moves the channel to the following position. This property is zero-based. /// public Optional Position { get; set; } - /// - /// Gets or sets the category ID for this channel. - /// - /// - /// 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 0 will detach this channel from its parent if one - /// is set. - /// - public Optional CategoryId { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs new file mode 100644 index 000000000..75b72d0d5 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs @@ -0,0 +1,18 @@ +namespace Discord +{ + /// + /// Properties that are used to modify an with the specified changes. + /// + public class NestedChannelProperties : GuildChannelProperties + { + /// + /// Gets or sets the category ID for this channel. + /// + /// + /// 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 0 will detach this channel from its parent if one + /// is set. + /// + public Optional CategoryId { get; set; } + } +} diff --git a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs index 6dcbf860a..994b043d7 100644 --- a/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs @@ -6,7 +6,7 @@ namespace Discord /// Provides properties that are used to modify an with the specified changes. /// /// - public class TextChannelProperties : GuildChannelProperties + public class TextChannelProperties : NestedChannelProperties { /// /// Gets or sets the topic of the channel. diff --git a/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs index fb4d47800..d423400db 100644 --- a/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs @@ -3,7 +3,7 @@ namespace Discord /// /// Provides properties that are used to modify an with the specified changes. /// - public class VoiceChannelProperties : GuildChannelProperties + public class VoiceChannelProperties : NestedChannelProperties { /// /// Gets or sets the bitrate of the voice connections in this channel. Must be greater than 8000. diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs index e5e8a4632..4427424aa 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs @@ -10,8 +10,6 @@ namespace Discord.API.Rest public Optional Name { get; set; } [JsonProperty("position")] public Optional Position { get; set; } - [JsonProperty("parent_id")] - public Optional CategoryId { get; set; } [JsonProperty("permission_overwrites")] public Optional Overwrites { get; set; } } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyNestedChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyNestedChannelParams.cs new file mode 100644 index 000000000..716f4a116 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyNestedChannelParams.cs @@ -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 CategoryId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs index 94f149fc1..274a47d4a 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs @@ -4,7 +4,7 @@ using Newtonsoft.Json; namespace Discord.API.Rest { [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - internal class ModifyTextChannelParams : ModifyGuildChannelParams + internal class ModifyTextChannelParams : ModifyNestedChannelParams { [JsonProperty("topic")] public Optional Topic { get; set; } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs index ce36eb11f..41b492204 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs @@ -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 Bitrate { get; set; } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index d8a97e85a..d6992aa87 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -27,8 +27,7 @@ namespace Discord.Rest 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); } From 102aa0c05d596d28fe587a924ebec4b041cc273f Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Sat, 22 Jun 2019 11:13:31 -0700 Subject: [PATCH 2/2] docs: update CategoryId remarks for detaching a channel setting a categoryid to 0 will result in a bad request, null will actually detach --- .../Entities/Channels/NestedChannelProperties.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs index 75b72d0d5..345b29e41 100644 --- a/src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs @@ -10,7 +10,7 @@ namespace Discord /// /// /// 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 0 will detach this channel from its parent if one + /// specified channel; setting this value to null will detach this channel from its parent if one /// is set. /// public Optional CategoryId { get; set; }