-
-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #995, Move Category Implementation from IGuildChannel to INestedChannel #1004
Changes from 15 commits
cafa537
0613b8d
dca85f1
6ca9632
f9c6707
cb392db
8bb92cc
de84fcf
ba2a589
52739e4
bf7c4dc
3ed1148
bb51b66
f6f8576
252932c
e9ef02e
bb6b879
cd37d63
36f49e1
3cf417a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// A type of guild channel that can be nested within a category. | ||
/// Contains a CategoryId that is set to the parent category, if it is set. | ||
/// </summary> | ||
public interface INestedChannel : IGuildChannel | ||
{ | ||
/// <summary> Gets the parentid (category) of this channel in the guild's channel list. </summary> | ||
ulong? CategoryId { get; } | ||
/// <summary> Gets the parent channel (category) of this channel, if it is set. If unset, returns null.</summary> | ||
Task<ICategoryChannel> GetCategoryAsync(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ namespace Discord.Rest | |
public class RestTextChannel : RestGuildChannel, IRestMessageChannel, ITextChannel | ||
{ | ||
public string Topic { get; private set; } | ||
public ulong? CategoryId { get; private set; } | ||
|
||
public string Mention => MentionUtils.MentionChannel(Id); | ||
|
||
|
@@ -31,7 +32,7 @@ internal RestTextChannel(BaseDiscordClient discord, IGuild guild, ulong id) | |
internal override void Update(Model model) | ||
{ | ||
base.Update(model); | ||
|
||
CategoryId = model.CategoryId; | ||
Topic = model.Topic.Value; | ||
_nsfw = model.Nsfw.GetValueOrDefault(); | ||
} | ||
|
@@ -46,7 +47,7 @@ public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null) | |
=> ChannelHelper.GetUserAsync(this, Guild, Discord, id, options); | ||
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null) | ||
=> ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options); | ||
|
||
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null) | ||
=> ChannelHelper.GetMessageAsync(this, Discord, id, options); | ||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) | ||
|
@@ -83,6 +84,9 @@ public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null | |
=> ChannelHelper.GetWebhookAsync(this, Discord, id, options); | ||
public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) | ||
=> ChannelHelper.GetWebhooksAsync(this, Discord, options); | ||
|
||
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | ||
=> ChannelHelper.GetCategoryAsync(this, Discord, options); | ||
|
||
private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | ||
|
||
|
@@ -109,6 +113,7 @@ IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync | |
else | ||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); | ||
} | ||
|
||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) | ||
{ | ||
if (mode == CacheMode.AllowDownload) | ||
|
@@ -168,5 +173,13 @@ IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mo | |
else | ||
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | ||
} | ||
|
||
// INestedChannel | ||
async Task<ICategoryChannel> INestedChannel.GetCategoryAsync() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to change this signature (add CacheMode and RequestOptions) to follow the same pattern as other rest entities and call the inner See: |
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this would be a better way (to not rely on the Guild on Rest): if (mode == CacheMode.AllowDownload)
return await GetCategoryAsync(options).ConfigureAwait(false);
else
return null; This is what I meant with "follow the same pattern as other rest entities and call the inner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is implemented, but isn't showing as outdated in Github. |
||
if (CategoryId.HasValue) | ||
return (await Guild.GetChannelAsync(CategoryId.Value).ConfigureAwait(false)) as ICategoryChannel; | ||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using Discord.Audio; | ||
using Discord.Audio; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
|
@@ -13,6 +13,7 @@ public class RestVoiceChannel : RestGuildChannel, IVoiceChannel, IRestAudioChann | |
{ | ||
public int Bitrate { get; private set; } | ||
public int? UserLimit { get; private set; } | ||
public ulong? CategoryId { get; private set; } | ||
|
||
internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id) | ||
: base(discord, guild, id) | ||
|
@@ -27,7 +28,7 @@ internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id) | |
internal override void Update(Model model) | ||
{ | ||
base.Update(model); | ||
|
||
CategoryId = model.CategoryId; | ||
Bitrate = model.Bitrate.Value; | ||
UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null; | ||
} | ||
|
@@ -38,6 +39,9 @@ public async Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOption | |
Update(model); | ||
} | ||
|
||
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | ||
=> ChannelHelper.GetCategoryAsync(this, Discord, options); | ||
|
||
private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | ||
|
||
//IAudioChannel | ||
|
@@ -48,5 +52,13 @@ Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOpt | |
=> Task.FromResult<IGuildUser>(null); | ||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | ||
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | ||
|
||
// INestedChannel | ||
async Task<ICategoryChannel> INestedChannel.GetCategoryAsync() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing as above. |
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
if (CategoryId.HasValue) | ||
return (await Guild.GetChannelAsync(CategoryId.Value).ConfigureAwait(false)) as ICategoryChannel; | ||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ public class SocketTextChannel : SocketGuildChannel, ITextChannel, ISocketMessag | |
private readonly MessageCache _messages; | ||
|
||
public string Topic { get; private set; } | ||
public ulong? CategoryId { get; private set; } | ||
public ICategoryChannel Category | ||
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; | ||
|
||
private bool _nsfw; | ||
public bool IsNsfw => _nsfw || ChannelHelper.IsNsfw(this); | ||
|
@@ -42,7 +45,7 @@ internal SocketTextChannel(DiscordSocketClient discord, ulong id, SocketGuild gu | |
internal override void Update(ClientState state, Model model) | ||
{ | ||
base.Update(state, model); | ||
|
||
CategoryId = model.CategoryId; | ||
Topic = model.Topic.Value; | ||
_nsfw = model.Nsfw.GetValueOrDefault(); | ||
} | ||
|
@@ -121,6 +124,10 @@ public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null | |
public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) | ||
=> ChannelHelper.GetWebhooksAsync(this, Discord, options); | ||
|
||
// Categories | ||
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this and leave only Same pattern as how we deal to retrieve users. |
||
=> ChannelHelper.GetCategoryAsync(this, Discord, options); | ||
|
||
private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | ||
internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel; | ||
|
||
|
@@ -164,5 +171,9 @@ async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTT | |
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); | ||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options) | ||
=> EnterTypingState(options); | ||
|
||
// INestedChannel | ||
Task<ICategoryChannel> INestedChannel.GetCategoryAsync() | ||
=> Task.FromResult(Category); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should we deal with redundant interfaces?
INestedChannel
inheritsIGuildChannel
already.IGuildChannel
from here (and other redundant places) and keepINestedChannel
(I prefer this one)INestedChannel
not inheritIGuildChannel
(makes hard accessing specific properties when casting, dont recommend)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with option # 2 for now.