Browse Source

Removed IChannel#Nsfw, added to ITextChannel

tags/2.0.0-beta
Christopher F 7 years ago
parent
commit
608bc359ee
10 changed files with 14 additions and 17 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Attributes/Preconditions/RequireNsfwAttribute.cs
  2. +1
    -4
      src/Discord.Net.Core/Entities/Channels/IChannel.cs
  3. +3
    -0
      src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
  4. +0
    -1
      src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
  5. +3
    -3
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  6. +0
    -1
      src/Discord.Net.Rest/Entities/Channels/RpcVirtualMessageChannel.cs
  7. +0
    -1
      src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs
  8. +2
    -0
      src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs
  9. +0
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
  10. +4
    -5
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.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, 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."));


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

@@ -7,10 +7,7 @@ namespace Discord
{
/// <summary> Gets the name of this channel. </summary>
string Name { get; }

/// <summary> Checks if the channel is NSFW. </summary>
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);


+ 3
- 0
src/Discord.Net.Core/Entities/Channels/ITextChannel.cs View File

@@ -5,6 +5,9 @@ namespace Discord
{
public interface ITextChannel : IMessageChannel, IMentionable, IGuildChannel
{
/// <summary> Checks if the channel is NSFW. </summary>
bool IsNsfw { get; }

/// <summary> Gets the current topic for this text channel. </summary>
string Topic { get; }



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

@@ -46,7 +46,6 @@ namespace Discord.Rest

//IChannel
string IChannel.Name => null;
bool IChannel.IsNsfw => false;

Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overriden


+ 3
- 3
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -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<TextChannelProperties> func, RequestOptions options = null)
@@ -152,6 +153,5 @@ namespace Discord.Rest
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
}
bool IChannel.IsNsfw => Nsfw || ChannelHelper.IsNsfw(this);
}
}

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

@@ -99,7 +99,6 @@ namespace Discord.Rest

//IChannel
string IChannel.Name { get { throw new NotSupportedException(); } }
bool IChannel.IsNsfw { get { throw new NotSupportedException(); } }
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
{
throw new NotSupportedException();


+ 0
- 1
src/Discord.Net.Rpc/Entities/Channels/RpcChannel.cs View File

@@ -8,7 +8,6 @@ namespace Discord.Rpc
public class RpcChannel : RpcEntity<ulong>
{
public string Name { get; private set; }
public bool IsNsfw => ChannelHelper.IsNsfw(Name);

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



+ 2
- 0
src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs View File

@@ -16,6 +16,8 @@ namespace Discord.Rpc
public IReadOnlyCollection<RpcMessage> 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)


+ 0
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs View File

@@ -41,7 +41,6 @@ namespace Discord.WebSocket

//IChannel
string IChannel.Name => null;
bool IChannel.IsNsfw => false;

Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overridden


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

@@ -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<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>();
@@ -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<TextChannelProperties> 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);
}
}

Loading…
Cancel
Save