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

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Model = Discord.API.Channel;
namespace Discord.WebSocket
{
/// <summary>
/// Represents a WebSocket-based news channel in a guild that has the same properties as a <see cref="RestTextChannel"/>.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketNewsChannel : SocketTextChannel
{
internal SocketNewsChannel(DiscordSocketClient discord, ulong id, SocketGuild guild)
:base(discord, id, guild)
{
}
internal new static SocketNewsChannel Create(SocketGuild guild, ClientState state, Model model)
{
var entity = new SocketNewsChannel(guild.Discord, model.Id, guild);
entity.Update(state, model);
return entity;
}
public override int SlowModeInterval
{
get { throw new NotSupportedException("News channels do not support Slow Mode."); }
}
public override Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
{
throw new NotSupportedException("News channels do not support Overwrite Permissions.");
}
public override Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
{
throw new NotSupportedException("News channels do not support Overwrite Permissions.");
}
public override IReadOnlyCollection<Overwrite> PermissionOverwrites
=> throw new NotSupportedException("News channels do not support Overwrite Permissions.");
public override Task SyncPermissionsAsync(RequestOptions options = null)
{
throw new NotSupportedException("News channels do not support Overwrite Permissions.");
}
public override Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{
throw new NotSupportedException("News channels do not support Overwrite Permissions.");
}
public override Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
{
throw new NotSupportedException("News channels do not support Overwrite Permissions.");
}
}
}