-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cafa537
Fix #995 ICategoryChannel.CategoryID throws NotSupportedException
Chris-Johnston 0613b8d
Add tests
Chris-Johnston dca85f1
change run mode of TestChannelCategories
Chris-Johnston 6ca9632
Add throw for GetCategoryAsync
Chris-Johnston f9c6707
Add xml doc explaining why exception is thrown
Chris-Johnston cb392db
Add test coverage for text and voice channel categories
Chris-Johnston 8bb92cc
initial implementation of INestedChannel
Chris-Johnston de84fcf
more implementation of INestedChannel design
Chris-Johnston ba2a589
Add case in RestChannel Create for Category type
Chris-Johnston 52739e4
set the CategoryID for RestVoiceChannel
Chris-Johnston bf7c4dc
rewrite channel category tests to work with existing pattern
Chris-Johnston 3ed1148
remove outdated todo
Chris-Johnston bb51b66
Make IVoiceChannel implement INestedChannel
Chris-Johnston f6f8576
remove redundant interface implementation
Chris-Johnston 252932c
Add c#7 feature from feedback
Chris-Johnston e9ef02e
Remove redundant GetCategoryAsync methods from socket entities
Chris-Johnston bb6b879
Added configureawait to async methods
Chris-Johnston cd37d63
change signature of interface GetCategoryAsync
Chris-Johnston 36f49e1
Add check for cachemode in rest channel GetCategory
Chris-Johnston 3cf417a
remove redundant IGuildChannel interface from ITextChannel and IVoice…
Chris-Johnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(CacheMode mode, RequestOptions options) | ||
{ | ||
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 && mode == CacheMode.AllowDownload) | ||
return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel; | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 believe this would be a better way (to not rely on the Guild on Rest):
This is what I meant with "follow the same pattern as other rest entities and call the inner
GetCategoryAsync
" in my last review.See:https://github.com/RogueException/Discord.Net/blob/dev/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs#L141
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.
This is implemented, but isn't showing as outdated in Github.