Browse Source

update TextChannel properties to include a Type optional parameter with validation

as of writing, this feature is still only available to verified guilds, which makes it impossible for testing.
pull/1293/head
Chris Johnston 6 years ago
parent
commit
a2d1731ae0
5 changed files with 23 additions and 0 deletions
  1. +10
    -0
      src/Discord.Net.Core/Entities/Channels/TextChannelProperties.cs
  2. +2
    -0
      src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs
  3. +9
    -0
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  4. +1
    -0
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
  5. +1
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs

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

@@ -38,5 +38,15 @@ namespace Discord
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the value does not fall within [0, 120].</exception>
public Optional<int> SlowModeInterval { get; set; }

/// <summary>
/// Gets or sets the type of channel.
/// Only setting to a <see cref="ChannelType.News"/> is supported.
/// </summary>
/// <remarks>
/// Setting this value to a different type will change the type of channel that is associated with this Id.
/// </remarks>
/// <exception cref="ArgumentException">Thrown if the type of channel that is being set is not valid.</exception>
public Optional<ChannelType> Type { get; set; }
}
}

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

@@ -12,5 +12,7 @@ namespace Discord.API.Rest
public Optional<bool> IsNsfw { get; set; }
[JsonProperty("rate_limit_per_user")]
public Optional<int> SlowModeInterval { get; set; }
[JsonProperty("type")]
public Optional<ChannelType> Type { get; set; }
}
}

+ 9
- 0
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -377,6 +377,15 @@ namespace Discord.API
Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name));
Preconditions.AtLeast(args.SlowModeInterval, 0, nameof(args.SlowModeInterval));
Preconditions.AtMost(args.SlowModeInterval, 120, nameof(args.SlowModeInterval));
if (args.Type.IsSpecified)
{
// can only change Text/NewsChannel into a Text or News
var warn = "You may not change a Text or News channel into a Voice, Group, DM, or Category channel.";
Preconditions.NotEqual((uint)args.Type.Value, (uint)ChannelType.Voice, nameof(args.Type), warn);
Preconditions.NotEqual((uint)args.Type.Value, (uint)ChannelType.Group, nameof(args.Type), warn);
Preconditions.NotEqual((uint)args.Type.Value, (uint)ChannelType.DM, nameof(args.Type), warn);
Preconditions.NotEqual((uint)args.Type.Value, (uint)ChannelType.Category, nameof(args.Type), warn);
}
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(channelId: channelId);


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

@@ -46,6 +46,7 @@ namespace Discord.Rest
Topic = args.Topic,
IsNsfw = args.IsNsfw,
SlowModeInterval = args.SlowModeInterval,
Type = args.Type
};
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
}


+ 1
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs View File

@@ -19,5 +19,6 @@ namespace Discord.WebSocket
entity.Update(state, model);
return entity;
}
//TODO: Need to set custom channel properties for this type, as apparently it does not support slow mode or overwrites.
}
}

Loading…
Cancel
Save