feature: Fix #1280 Add NewsChannel Types (#1293)

* add News channel type

* remove (very outdated) todo

* add [Socket/Rest]NewsChannel types

* 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.

* actually create the news channels when given the type

* throw NotSupportedException in News channel

throw a NotSupportedException whenever trying to use SlowModeInterval or anything related to overwrite permissions

* make RestNewsChannel throw NotSupportedException also

* remove the (untested) ability to change channel types
This commit is contained in:
Chris Johnston
2019-05-04 14:07:31 -07:00
committed by Christopher F
parent 2254a99942
commit 9084c4214e
8 changed files with 130 additions and 19 deletions

View File

@@ -15,7 +15,7 @@ namespace Discord.Rest
private ImmutableArray<Overwrite> _overwrites;
/// <inheritdoc />
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
public virtual IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
internal IGuild Guild { get; }
/// <inheritdoc />
@@ -34,6 +34,8 @@ namespace Discord.Rest
{
switch (model.Type)
{
case ChannelType.News:
return RestNewsChannel.Create(discord, guild, model);
case ChannelType.Text:
return RestTextChannel.Create(discord, guild, model);
case ChannelType.Voice:
@@ -79,7 +81,7 @@ namespace Discord.Rest
/// <returns>
/// An overwrite object for the targeted user; <c>null</c> if none is set.
/// </returns>
public OverwritePermissions? GetPermissionOverwrite(IUser user)
public virtual OverwritePermissions? GetPermissionOverwrite(IUser user)
{
for (int i = 0; i < _overwrites.Length; i++)
{
@@ -96,7 +98,7 @@ namespace Discord.Rest
/// <returns>
/// An overwrite object for the targeted role; <c>null</c> if none is set.
/// </returns>
public OverwritePermissions? GetPermissionOverwrite(IRole role)
public virtual OverwritePermissions? GetPermissionOverwrite(IRole role)
{
for (int i = 0; i < _overwrites.Length; i++)
{
@@ -115,7 +117,7 @@ namespace Discord.Rest
/// <returns>
/// A task representing the asynchronous permission operation for adding the specified permissions to the channel.
/// </returns>
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
public virtual async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
{
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, permissions, options).ConfigureAwait(false);
_overwrites = _overwrites.Add(new Overwrite(user.Id, PermissionTarget.User, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue)));
@@ -129,7 +131,7 @@ namespace Discord.Rest
/// <returns>
/// A task representing the asynchronous permission operation for adding the specified permissions to the channel.
/// </returns>
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
public virtual async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
{
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, permissions, options).ConfigureAwait(false);
_overwrites = _overwrites.Add(new Overwrite(role.Id, PermissionTarget.Role, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue)));
@@ -143,7 +145,7 @@ namespace Discord.Rest
/// <returns>
/// A task representing the asynchronous operation for removing the specified permissions from the channel.
/// </returns>
public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
public virtual async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
{
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false);
@@ -164,7 +166,7 @@ namespace Discord.Rest
/// <returns>
/// A task representing the asynchronous operation for removing the specified permissions from the channel.
/// </returns>
public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
public virtual async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false);