Removed IChannel#Nsfw, added to ITextChannel
This commit is contained in:
@@ -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."));
|
||||
|
||||
@@ -8,9 +8,6 @@ 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);
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user