Reworked IChannel.IsNsfw to support the new API flag (#771)

IChannel.IsNsfw will now return false when being used on any channel
that is not an ITextChannel. When being used on an ITextChannel, this
will now account for the API flag, and fall back to the channel name.

(this is gross design, thanks discord)
This commit is contained in:
Christopher F
2017-08-28 16:45:53 -04:00
committed by GitHub
parent 361bfc1a90
commit 182f00f8ce
6 changed files with 15 additions and 4 deletions

View File

@@ -29,6 +29,8 @@ namespace Discord.API
public Optional<string> Topic { get; set; }
[JsonProperty("last_pin_timestamp")]
public Optional<DateTimeOffset?> LastPinTimestamp { get; set; }
[JsonProperty("nsfw")]
public Optional<bool> Nsfw { get; set; }
//VoiceChannel
[JsonProperty("bitrate")]

View File

@@ -290,8 +290,8 @@ namespace Discord.Rest
return author;
}
public static bool IsNsfw(IChannel channel) =>
IsNsfw(channel.Name);
public static bool IsNsfw(IChannel channel)
=> IsNsfw(channel.Name);
public static bool IsNsfw(string channelName) =>
channelName == "nsfw" || channelName.StartsWith("nsfw-");
}

View File

@@ -46,7 +46,7 @@ namespace Discord.Rest
//IChannel
string IChannel.Name => null;
bool IChannel.IsNsfw => ChannelHelper.IsNsfw(this);
bool IChannel.IsNsfw => false;
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overriden

View File

@@ -15,6 +15,8 @@ namespace Discord.Rest
public string Mention => MentionUtils.MentionChannel(Id);
internal bool Nsfw { get; private set; }
internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id)
: base(discord, guild, id)
{
@@ -30,6 +32,7 @@ namespace Discord.Rest
base.Update(model);
Topic = model.Topic.Value;
Nsfw = model.Nsfw.GetValueOrDefault();
}
public async Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null)
@@ -149,5 +152,6 @@ namespace Discord.Rest
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
}
bool IChannel.IsNsfw => Nsfw || ChannelHelper.IsNsfw(this);
}
}