* 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:
committed by
Christopher F
parent
2254a99942
commit
9084c4214e
@@ -30,7 +30,7 @@ namespace Discord.WebSocket
|
||||
public int Position { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
|
||||
public virtual IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
|
||||
/// <summary>
|
||||
/// Gets a collection of users that are able to view the channel.
|
||||
/// </summary>
|
||||
@@ -48,6 +48,8 @@ namespace Discord.WebSocket
|
||||
{
|
||||
switch (model.Type)
|
||||
{
|
||||
case ChannelType.News:
|
||||
return SocketNewsChannel.Create(guild, state, model);
|
||||
case ChannelType.Text:
|
||||
return SocketTextChannel.Create(guild, state, model);
|
||||
case ChannelType.Voice:
|
||||
@@ -55,7 +57,6 @@ namespace Discord.WebSocket
|
||||
case ChannelType.Category:
|
||||
return SocketCategoryChannel.Create(guild, state, model);
|
||||
default:
|
||||
// TODO: Proper implementation for channel categories
|
||||
return new SocketGuildChannel(guild.Discord, model.Id, guild);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ namespace Discord.WebSocket
|
||||
/// <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++)
|
||||
{
|
||||
@@ -102,7 +103,7 @@ namespace Discord.WebSocket
|
||||
/// <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++)
|
||||
{
|
||||
@@ -121,7 +122,7 @@ namespace Discord.WebSocket
|
||||
/// <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)));
|
||||
@@ -136,7 +137,7 @@ namespace Discord.WebSocket
|
||||
/// <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)));
|
||||
@@ -149,7 +150,7 @@ namespace Discord.WebSocket
|
||||
/// <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);
|
||||
|
||||
@@ -170,7 +171,7 @@ namespace Discord.WebSocket
|
||||
/// <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);
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public string Topic { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public int SlowModeInterval { get; private set; }
|
||||
public virtual int SlowModeInterval { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public ulong? CategoryId { get; private set; }
|
||||
/// <summary>
|
||||
@@ -33,7 +33,7 @@ namespace Discord.WebSocket
|
||||
public ICategoryChannel Category
|
||||
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
|
||||
/// <inheritdoc />
|
||||
public Task SyncPermissionsAsync(RequestOptions options = null)
|
||||
public virtual Task SyncPermissionsAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options);
|
||||
|
||||
private bool _nsfw;
|
||||
|
||||
Reference in New Issue
Block a user