Browse Source

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
pull/1282/head
Chris Johnston 6 years ago
parent
commit
b919a1e52c
9 changed files with 36 additions and 18 deletions
  1. +0
    -9
      src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs
  2. +18
    -0
      src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs
  3. +1
    -1
      src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs
  4. +1
    -1
      src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs
  5. +0
    -2
      src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs
  6. +12
    -0
      src/Discord.Net.Rest/API/Rest/ModifyNestedChannelParams.cs
  7. +1
    -1
      src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs
  8. +2
    -2
      src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs
  9. +1
    -2
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs

+ 0
- 9
src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs View File

@@ -21,14 +21,5 @@ namespace Discord
/// Moves the channel to the following position. This property is zero-based. /// Moves the channel to the following position. This property is zero-based.
/// </summary> /// </summary>
public Optional<int> Position { get; set; } 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
- 0
src/Discord.Net.Core/Entities/Channels/NestedChannelProperties.cs View File

@@ -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>0</c> will detach this channel from its parent if one
/// is set.
/// </remarks>
public Optional<ulong?> CategoryId { get; set; }
}
}

+ 1
- 1
src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs View File

@@ -6,7 +6,7 @@ namespace Discord
/// Provides properties that are used to modify an <see cref="ITextChannel"/> with the specified changes. /// Provides properties that are used to modify an <see cref="ITextChannel"/> with the specified changes.
/// </summary> /// </summary>
/// <seealso cref="ITextChannel.ModifyAsync(System.Action{TextChannelProperties}, RequestOptions)"/> /// <seealso cref="ITextChannel.ModifyAsync(System.Action{TextChannelProperties}, RequestOptions)"/>
public class TextChannelProperties : GuildChannelProperties
public class TextChannelProperties : NestedChannelProperties
{ {
/// <summary> /// <summary>
/// Gets or sets the topic of the channel. /// Gets or sets the topic of the channel.


+ 1
- 1
src/Discord.Net.Core/Entities/Channels/VoiceChannelProperties.cs View File

@@ -3,7 +3,7 @@ namespace Discord
/// <summary> /// <summary>
/// Provides properties that are used to modify an <see cref="IVoiceChannel" /> with the specified changes. /// Provides properties that are used to modify an <see cref="IVoiceChannel" /> with the specified changes.
/// </summary> /// </summary>
public class VoiceChannelProperties : GuildChannelProperties
public class VoiceChannelProperties : NestedChannelProperties
{ {
/// <summary> /// <summary>
/// Gets or sets the bitrate of the voice connections in this channel. Must be greater than 8000. /// Gets or sets the bitrate of the voice connections in this channel. Must be greater than 8000.


+ 0
- 2
src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs View File

@@ -10,8 +10,6 @@ namespace Discord.API.Rest
public Optional<string> Name { get; set; } public Optional<string> Name { get; set; }
[JsonProperty("position")] [JsonProperty("position")]
public Optional<int> Position { get; set; } public Optional<int> Position { get; set; }
[JsonProperty("parent_id")]
public Optional<ulong?> CategoryId { get; set; }
[JsonProperty("permission_overwrites")] [JsonProperty("permission_overwrites")]
public Optional<Overwrite[]> Overwrites { get; set; } public Optional<Overwrite[]> Overwrites { get; set; }
} }


+ 12
- 0
src/Discord.Net.Rest/API/Rest/ModifyNestedChannelParams.cs View File

@@ -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; }
}
}

+ 1
- 1
src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs View File

@@ -4,7 +4,7 @@ using Newtonsoft.Json;
namespace Discord.API.Rest namespace Discord.API.Rest
{ {
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
internal class ModifyTextChannelParams : ModifyGuildChannelParams
internal class ModifyTextChannelParams : ModifyNestedChannelParams
{ {
[JsonProperty("topic")] [JsonProperty("topic")]
public Optional<string> Topic { get; set; } public Optional<string> Topic { get; set; }


+ 2
- 2
src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs View File

@@ -1,10 +1,10 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json; using Newtonsoft.Json;


namespace Discord.API.Rest namespace Discord.API.Rest
{ {
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
internal class ModifyVoiceChannelParams : ModifyGuildChannelParams
internal class ModifyVoiceChannelParams : ModifyNestedChannelParams
{ {
[JsonProperty("bitrate")] [JsonProperty("bitrate")]
public Optional<int> Bitrate { get; set; } public Optional<int> Bitrate { get; set; }


+ 1
- 2
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -27,8 +27,7 @@ namespace Discord.Rest
var apiArgs = new API.Rest.ModifyGuildChannelParams var apiArgs = new API.Rest.ModifyGuildChannelParams
{ {
Name = args.Name, Name = args.Name,
Position = args.Position,
CategoryId = args.CategoryId
Position = args.Position
}; };
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
} }


Loading…
Cancel
Save