Browse Source

throw NotSupportedException in News channel

throw a NotSupportedException whenever trying to use SlowModeInterval or anything related to overwrite permissions
pull/1293/head
Chris Johnston 6 years ago
parent
commit
f6343d2ddb
3 changed files with 38 additions and 10 deletions
  1. +7
    -7
      src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
  2. +29
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketNewsChannel.cs
  3. +2
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs

+ 7
- 7
src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs View File

@@ -30,7 +30,7 @@ namespace Discord.WebSocket
public int Position { get; private set; } public int Position { get; private set; }


/// <inheritdoc /> /// <inheritdoc />
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
public virtual IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
/// <summary> /// <summary>
/// Gets a collection of users that are able to view the channel. /// Gets a collection of users that are able to view the channel.
/// </summary> /// </summary>
@@ -87,7 +87,7 @@ namespace Discord.WebSocket
/// <returns> /// <returns>
/// An overwrite object for the targeted user; <c>null</c> if none is set. /// An overwrite object for the targeted user; <c>null</c> if none is set.
/// </returns> /// </returns>
public OverwritePermissions? GetPermissionOverwrite(IUser user)
public virtual OverwritePermissions? GetPermissionOverwrite(IUser user)
{ {
for (int i = 0; i < _overwrites.Length; i++) for (int i = 0; i < _overwrites.Length; i++)
{ {
@@ -103,7 +103,7 @@ namespace Discord.WebSocket
/// <returns> /// <returns>
/// An overwrite object for the targeted role; <c>null</c> if none is set. /// An overwrite object for the targeted role; <c>null</c> if none is set.
/// </returns> /// </returns>
public OverwritePermissions? GetPermissionOverwrite(IRole role)
public virtual OverwritePermissions? GetPermissionOverwrite(IRole role)
{ {
for (int i = 0; i < _overwrites.Length; i++) for (int i = 0; i < _overwrites.Length; i++)
{ {
@@ -122,7 +122,7 @@ namespace Discord.WebSocket
/// <returns> /// <returns>
/// A task representing the asynchronous permission operation for adding the specified permissions to the channel. /// A task representing the asynchronous permission operation for adding the specified permissions to the channel.
/// </returns> /// </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); 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))); _overwrites = _overwrites.Add(new Overwrite(user.Id, PermissionTarget.User, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue)));
@@ -137,7 +137,7 @@ namespace Discord.WebSocket
/// <returns> /// <returns>
/// A task representing the asynchronous permission operation for adding the specified permissions to the channel. /// A task representing the asynchronous permission operation for adding the specified permissions to the channel.
/// </returns> /// </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); 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))); _overwrites = _overwrites.Add(new Overwrite(role.Id, PermissionTarget.Role, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue)));
@@ -150,7 +150,7 @@ namespace Discord.WebSocket
/// <returns> /// <returns>
/// A task representing the asynchronous operation for removing the specified permissions from the channel. /// A task representing the asynchronous operation for removing the specified permissions from the channel.
/// </returns> /// </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); await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false);


@@ -171,7 +171,7 @@ namespace Discord.WebSocket
/// <returns> /// <returns>
/// A task representing the asynchronous operation for removing the specified permissions from the channel. /// A task representing the asynchronous operation for removing the specified permissions from the channel.
/// </returns> /// </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); await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false);




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

@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks;
using Model = Discord.API.Channel; using Model = Discord.API.Channel;


namespace Discord.WebSocket namespace Discord.WebSocket
@@ -19,6 +22,31 @@ namespace Discord.WebSocket
entity.Update(state, model); entity.Update(state, model);
return entity; return entity;
} }
//TODO: Need to set custom channel properties for this type, as apparently it does not support slow mode or overwrites.
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.");
}
} }
} }

+ 2
- 2
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -21,7 +21,7 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
public string Topic { get; private set; } public string Topic { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public int SlowModeInterval { get; private set; }
public virtual int SlowModeInterval { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public ulong? CategoryId { get; private set; } public ulong? CategoryId { get; private set; }
/// <summary> /// <summary>
@@ -33,7 +33,7 @@ namespace Discord.WebSocket
public ICategoryChannel Category public ICategoryChannel Category
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
/// <inheritdoc /> /// <inheritdoc />
public Task SyncPermissionsAsync(RequestOptions options = null)
public virtual Task SyncPermissionsAsync(RequestOptions options = null)
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options); => ChannelHelper.SyncPermissionsAsync(this, Discord, options);


private bool _nsfw; private bool _nsfw;


Loading…
Cancel
Save