| @@ -11,7 +11,7 @@ namespace Discord.Commands | |||||
| { | { | ||||
| public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) | 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()); | return Task.FromResult(PreconditionResult.FromSuccess()); | ||||
| else | else | ||||
| return Task.FromResult(PreconditionResult.FromError("This command may only be invoked in an NSFW channel.")); | return Task.FromResult(PreconditionResult.FromError("This command may only be invoked in an NSFW channel.")); | ||||
| @@ -7,10 +7,7 @@ namespace Discord | |||||
| { | { | ||||
| /// <summary> Gets the name of this channel. </summary> | /// <summary> Gets the name of this channel. </summary> | ||||
| string Name { get; } | 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> | /// <summary> Gets a collection of all users in this channel. </summary> | ||||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | IAsyncEnumerable<IReadOnlyCollection<IUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
| @@ -5,6 +5,9 @@ namespace Discord | |||||
| { | { | ||||
| public interface ITextChannel : IMessageChannel, IMentionable, IGuildChannel | 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> | /// <summary> Gets the current topic for this text channel. </summary> | ||||
| string Topic { get; } | string Topic { get; } | ||||
| @@ -46,7 +46,6 @@ namespace Discord.Rest | |||||
| //IChannel | //IChannel | ||||
| string IChannel.Name => null; | string IChannel.Name => null; | ||||
| bool IChannel.IsNsfw => false; | |||||
| Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
| => Task.FromResult<IUser>(null); //Overriden | => Task.FromResult<IUser>(null); //Overriden | ||||
| @@ -15,7 +15,8 @@ namespace Discord.Rest | |||||
| public string Mention => MentionUtils.MentionChannel(Id); | 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) | internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id) | ||||
| : base(discord, guild, id) | : base(discord, guild, id) | ||||
| @@ -32,7 +33,7 @@ namespace Discord.Rest | |||||
| base.Update(model); | base.Update(model); | ||||
| Topic = model.Topic.Value; | Topic = model.Topic.Value; | ||||
| Nsfw = model.Nsfw.GetValueOrDefault(); | |||||
| _nsfw = model.Nsfw.GetValueOrDefault(); | |||||
| } | } | ||||
| public async Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null) | public async Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null) | ||||
| @@ -152,6 +153,5 @@ namespace Discord.Rest | |||||
| else | else | ||||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | ||||
| } | } | ||||
| bool IChannel.IsNsfw => Nsfw || ChannelHelper.IsNsfw(this); | |||||
| } | } | ||||
| } | } | ||||
| @@ -99,7 +99,6 @@ namespace Discord.Rest | |||||
| //IChannel | //IChannel | ||||
| string IChannel.Name { get { throw new NotSupportedException(); } } | string IChannel.Name { get { throw new NotSupportedException(); } } | ||||
| bool IChannel.IsNsfw { get { throw new NotSupportedException(); } } | |||||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||||
| { | { | ||||
| throw new NotSupportedException(); | throw new NotSupportedException(); | ||||
| @@ -8,7 +8,6 @@ namespace Discord.Rpc | |||||
| public class RpcChannel : RpcEntity<ulong> | public class RpcChannel : RpcEntity<ulong> | ||||
| { | { | ||||
| public string Name { get; private set; } | public string Name { get; private set; } | ||||
| public bool IsNsfw => ChannelHelper.IsNsfw(Name); | |||||
| public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | ||||
| @@ -16,6 +16,8 @@ namespace Discord.Rpc | |||||
| public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; } | public IReadOnlyCollection<RpcMessage> CachedMessages { get; private set; } | ||||
| public string Mention => MentionUtils.MentionChannel(Id); | 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) | internal RpcTextChannel(DiscordRpcClient discord, ulong id, ulong guildId) | ||||
| : base(discord, id, guildId) | : base(discord, id, guildId) | ||||
| @@ -41,7 +41,6 @@ namespace Discord.WebSocket | |||||
| //IChannel | //IChannel | ||||
| string IChannel.Name => null; | string IChannel.Name => null; | ||||
| bool IChannel.IsNsfw => false; | |||||
| Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
| => Task.FromResult<IUser>(null); //Overridden | => Task.FromResult<IUser>(null); //Overridden | ||||
| @@ -16,7 +16,9 @@ namespace Discord.WebSocket | |||||
| private readonly MessageCache _messages; | private readonly MessageCache _messages; | ||||
| public string Topic { get; private set; } | 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 string Mention => MentionUtils.MentionChannel(Id); | ||||
| public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>(); | public IReadOnlyCollection<SocketMessage> CachedMessages => _messages?.Messages ?? ImmutableArray.Create<SocketMessage>(); | ||||
| @@ -42,7 +44,7 @@ namespace Discord.WebSocket | |||||
| base.Update(state, model); | base.Update(state, model); | ||||
| Topic = model.Topic.Value; | Topic = model.Topic.Value; | ||||
| Nsfw = model.Nsfw.GetValueOrDefault(); | |||||
| _nsfw = model.Nsfw.GetValueOrDefault(); | |||||
| } | } | ||||
| public Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null) | public Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null) | ||||
| @@ -146,8 +148,5 @@ namespace Discord.WebSocket | |||||
| => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); | => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); | ||||
| IDisposable IMessageChannel.EnterTypingState(RequestOptions options) | IDisposable IMessageChannel.EnterTypingState(RequestOptions options) | ||||
| => EnterTypingState(options); | => EnterTypingState(options); | ||||
| // IChannel | |||||
| bool IChannel.IsNsfw => Nsfw || ChannelHelper.IsNsfw(this); | |||||
| } | } | ||||
| } | } | ||||