Browse Source

Refactored IChannel.Nsfw to IsNsfw, removed NsfwUtils

Per pull-request feedback
pull/633/head
Christopher F 8 years ago
parent
commit
27b86c6eb7
8 changed files with 15 additions and 18 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs
  2. +1
    -1
      src/Discord.Net.Core/Entities/Channels/IChannel.cs
  3. +0
    -10
      src/Discord.Net.Core/Utils/NsfwUtils.cs
  4. +5
    -0
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
  5. +1
    -1
      src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
  6. +1
    -1
      src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs
  7. +3
    -2
      src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs
  8. +3
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs

+ 1
- 1
src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs View File

@@ -11,7 +11,7 @@ namespace Discord.Commands
{
public override Task<PreconditionResult> 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."));


+ 1
- 1
src/Discord.Net.Core/Entities/Channels/IChannel.cs View File

@@ -9,7 +9,7 @@ namespace Discord
string Name { get; }

/// <summary> Checks if the channel is NSFW. </summary>
bool Nsfw { get; }
bool IsNsfw { get; }

/// <summary> Gets a collection of all users in this channel. </summary>
IAsyncEnumerable<IReadOnlyCollection<IUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);


+ 0
- 10
src/Discord.Net.Core/Utils/NsfwUtils.cs View File

@@ -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");
}
}

+ 5
- 0
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -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");
}
}

+ 1
- 1
src/Discord.Net.Rest/Entities/Channels/RestChannel.cs View File

@@ -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<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overriden


+ 1
- 1
src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs View File

@@ -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<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
{
throw new NotSupportedException();


+ 3
- 2
src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs View File

@@ -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<ulong>
{
public string Name { get; private set; }
public bool Nsfw => NsfwUtils.IsNsfw(Name);
public bool IsNsfw => ChannelHelper.IsNsfw(Name);

public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);



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

@@ -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<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overridden


Loading…
Cancel
Save