From 27b86c6eb7d055bb2dd2e2e3f60ed04e3e46ffe2 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Fri, 28 Apr 2017 21:09:02 -0400 Subject: [PATCH] Refactored IChannel.Nsfw to IsNsfw, removed NsfwUtils Per pull-request feedback --- .../Attributes/Preconditions/RequireNsfwAttribute.cs | 2 +- src/Discord.Net.Core/Entities/Channels/IChannel.cs | 2 +- src/Discord.Net.Core/Utils/NsfwUtils.cs | 10 ---------- .../Entities/Channels/ChannelHelper.cs | 5 +++++ src/Discord.Net.Rest/Entities/Channels/RestChannel.cs | 2 +- .../Entities/Channels/RpcVirtualMessageChannel.cs | 2 +- src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs | 5 +++-- .../Entities/Channels/SocketChannel.cs | 5 +++-- 8 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 src/Discord.Net.Core/Utils/NsfwUtils.cs diff --git a/src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs b/src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs index 61e6b2bc8..a52ec6ddd 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, IDependencyMap map) { - if (context.Channel.Nsfw) + if (context.Channel.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 23d1893a9..fbb979951 100644 --- a/src/Discord.Net.Core/Entities/Channels/IChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IChannel.cs @@ -9,7 +9,7 @@ namespace Discord string Name { get; } /// Checks if the channel is NSFW. - bool Nsfw { get; } + 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/Utils/NsfwUtils.cs b/src/Discord.Net.Core/Utils/NsfwUtils.cs deleted file mode 100644 index cda461ecc..000000000 --- a/src/Discord.Net.Core/Utils/NsfwUtils.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Discord -{ - public static class NsfwUtils - { - public static bool IsNsfw(IChannel channel) => - IsNsfw(channel.Name); - public static bool IsNsfw(string channelName) => - channelName.StartsWith("nsfw"); - } -} diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index e6d017a89..72553c3fa 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -289,5 +289,10 @@ namespace Discord.Rest author = RestUser.Create(client, guild, model, webhookId); return author; } + + public static bool IsNsfw(IChannel channel) => + IsNsfw(channel.Name); + public static bool IsNsfw(string channelName) => + channelName.StartsWith("nsfw"); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs index bc1fc5158..7291b591e 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs @@ -46,7 +46,7 @@ namespace Discord.Rest //IChannel string IChannel.Name => null; - bool IChannel.Nsfw => NsfwUtils.IsNsfw(this); + bool IChannel.IsNsfw => ChannelHelper.IsNsfw(this); Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overriden diff --git a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs index b12bb009c..dfd996ee1 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs @@ -97,7 +97,7 @@ namespace Discord.Rest //IChannel string IChannel.Name { get { throw new NotSupportedException(); } } - bool IChannel.Nsfw { 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 7a22a4e6c..d26c593ba 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs @@ -1,4 +1,5 @@ -using System; +using Discord.Rest; +using System; using Model = Discord.API.Rpc.Channel; @@ -7,7 +8,7 @@ namespace Discord.Rpc public class RpcChannel : RpcEntity { public string Name { get; private set; } - public bool Nsfw => NsfwUtils.IsNsfw(Name); + public bool IsNsfw => ChannelHelper.IsNsfw(Name); public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs index 340ab91c1..42c4156f3 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs @@ -1,4 +1,5 @@ -using System; +using Discord.Rest; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -40,7 +41,7 @@ namespace Discord.WebSocket //IChannel string IChannel.Name => null; - bool IChannel.Nsfw => NsfwUtils.IsNsfw(this); + bool IChannel.IsNsfw => ChannelHelper.IsNsfw(this); Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overridden