From 608bc359ee01fc801ef226e153869b30d81f24b4 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Tue, 29 Aug 2017 17:26:36 -0400 Subject: [PATCH] Removed IChannel#Nsfw, added to ITextChannel --- .../Attributes/Preconditions/RequireNsfwAttribute.cs | 2 +- src/Discord.Net.Core/Entities/Channels/IChannel.cs | 5 +---- src/Discord.Net.Core/Entities/Channels/ITextChannel.cs | 3 +++ src/Discord.Net.Rest/Entities/Channels/RestChannel.cs | 1 - .../Entities/Channels/RestTextChannel.cs | 6 +++--- .../Entities/Channels/RpcVirtualMessageChannel.cs | 1 - src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs | 1 - src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs | 2 ++ .../Entities/Channels/SocketChannel.cs | 1 - .../Entities/Channels/SocketTextChannel.cs | 9 ++++----- 10 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs index 94235b1ae..b3cf25365 100644 --- a/src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs @@ -11,7 +11,7 @@ namespace Discord.Commands { public override Task CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) { - if (context.Channel.IsNsfw) + if (context.Channel is ITextChannel text && text.IsNsfw) return Task.FromResult(PreconditionResult.FromSuccess()); else return Task.FromResult(PreconditionResult.FromError("This command may only be invoked in an NSFW channel.")); diff --git a/src/Discord.Net.Core/Entities/Channels/IChannel.cs b/src/Discord.Net.Core/Entities/Channels/IChannel.cs index fbb979951..ea930e112 100644 --- a/src/Discord.Net.Core/Entities/Channels/IChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IChannel.cs @@ -7,10 +7,7 @@ namespace Discord { /// Gets the name of this channel. string Name { get; } - - /// Checks if the channel is NSFW. - bool IsNsfw { get; } - + /// Gets a collection of all users in this channel. IAsyncEnumerable> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); diff --git a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs index 038faf6bc..b2b7e491f 100644 --- a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs @@ -5,6 +5,9 @@ namespace Discord { public interface ITextChannel : IMessageChannel, IMentionable, IGuildChannel { + /// Checks if the channel is NSFW. + bool IsNsfw { get; } + /// Gets the current topic for this text channel. string Topic { get; } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs index 9e4c97cfa..bc521784d 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs @@ -46,7 +46,6 @@ namespace Discord.Rest //IChannel string IChannel.Name => null; - bool IChannel.IsNsfw => false; Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overriden diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index 3353dc7b0..8a096302b 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -15,7 +15,8 @@ namespace Discord.Rest public string Mention => MentionUtils.MentionChannel(Id); - internal bool Nsfw { get; private set; } + private bool _nsfw; + public bool IsNsfw => _nsfw || ChannelHelper.IsNsfw(this); internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id) : base(discord, guild, id) @@ -32,7 +33,7 @@ namespace Discord.Rest base.Update(model); Topic = model.Topic.Value; - Nsfw = model.Nsfw.GetValueOrDefault(); + _nsfw = model.Nsfw.GetValueOrDefault(); } public async Task ModifyAsync(Action func, RequestOptions options = null) @@ -152,6 +153,5 @@ namespace Discord.Rest else return AsyncEnumerable.Empty>(); } - bool IChannel.IsNsfw => Nsfw || ChannelHelper.IsNsfw(this); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs index 775f2ea82..7043c8c76 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs @@ -99,7 +99,6 @@ namespace Discord.Rest //IChannel string IChannel.Name { get { throw new NotSupportedException(); } } - bool IChannel.IsNsfw { get { throw new NotSupportedException(); } } IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) { throw new NotSupportedException(); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs index d26c593ba..0c22a03f7 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs @@ -8,7 +8,6 @@ namespace Discord.Rpc public class RpcChannel : RpcEntity { public string Name { get; private set; } - public bool IsNsfw => ChannelHelper.IsNsfw(Name); public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs index 72b45e466..9de2968db 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs @@ -16,6 +16,8 @@ namespace Discord.Rpc public IReadOnlyCollection CachedMessages { get; private set; } public string Mention => MentionUtils.MentionChannel(Id); + // TODO: Check if RPC includes the 'nsfw' field on Channel models + public bool IsNsfw => ChannelHelper.IsNsfw(this); internal RpcTextChannel(DiscordRpcClient discord, ulong id, ulong guildId) : base(discord, id, guildId) diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs index b0d7261fd..502e61d15 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs @@ -41,7 +41,6 @@ namespace Discord.WebSocket //IChannel string IChannel.Name => null; - bool IChannel.IsNsfw => false; Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overridden diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index 1b351aae4..07ec630d3 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -16,7 +16,9 @@ namespace Discord.WebSocket private readonly MessageCache _messages; public string Topic { get; private set; } - internal bool Nsfw { get; private set; } + + private bool _nsfw; + public bool IsNsfw => _nsfw || ChannelHelper.IsNsfw(this); public string Mention => MentionUtils.MentionChannel(Id); public IReadOnlyCollection CachedMessages => _messages?.Messages ?? ImmutableArray.Create(); @@ -42,7 +44,7 @@ namespace Discord.WebSocket base.Update(state, model); Topic = model.Topic.Value; - Nsfw = model.Nsfw.GetValueOrDefault(); + _nsfw = model.Nsfw.GetValueOrDefault(); } public Task ModifyAsync(Action func, RequestOptions options = null) @@ -146,8 +148,5 @@ namespace Discord.WebSocket => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); - - // IChannel - bool IChannel.IsNsfw => Nsfw || ChannelHelper.IsNsfw(this); } } \ No newline at end of file