From e18bd8c799d2327270021c05866cb2e97ad4671b Mon Sep 17 00:00:00 2001 From: pegasy Date: Sun, 24 Sep 2017 15:49:51 +0200 Subject: [PATCH 1/3] Add support for channel categories (as its own channel type) --- .../GuildChannelCategoryProperties.cs | 12 +++++ .../Channels/GuildChannelProperties.cs | 4 ++ .../Entities/Channels/IGuildChannel.cs | 6 ++- .../Channels/IGuildChannelCategory.cs | 14 ++++++ .../Entities/Guilds/IGuild.cs | 1 + src/Discord.Net.Rest/API/Common/Channel.cs | 2 + .../Rest/ModifyGuildChannelCategoryParams.cs | 14 ++++++ .../API/Rest/ModifyGuildChannelParams.cs | 2 + .../Entities/Channels/ChannelHelper.cs | 31 +++++++------ .../Entities/Channels/ChannelType.cs | 3 +- .../Entities/Channels/RestGuildChannel.cs | 18 ++++---- .../Channels/RestGuildChannelCategory.cs | 38 +++++++++++++++ .../Entities/Guilds/RestGuild.cs | 24 +++++++--- .../Entities/Channels/RpcChannelCategory.cs | 38 +++++++++++++++ .../Entities/Channels/RpcGuildChannel.cs | 7 +++ .../Entities/Channels/SocketGuildChannel.cs | 6 +++ .../Channels/SocketGuildChannelCategory.cs | 46 +++++++++++++++++++ .../Entities/Guilds/SocketGuild.cs | 10 ++-- 18 files changed, 243 insertions(+), 33 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs create mode 100644 src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs create mode 100644 src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs create mode 100644 src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs create mode 100644 src/Discord.Net.Rpc/Entities/Channels/RpcChannelCategory.cs create mode 100644 src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs b/src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs new file mode 100644 index 000000000..2678e5eef --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + //public class GuildChannelCategoryProperties : GuildChannelProperties + //{ + //} +} diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs index 0ea196a4a..e580a2e59 100644 --- a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs @@ -26,5 +26,9 @@ /// Move the channel to the following position. This is 0-based! /// public Optional Position { get; set; } + /// + /// Sets the category for this channel + /// + public Optional ParentId { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs index 3d08a8c51..b019fab23 100644 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs @@ -9,6 +9,10 @@ namespace Discord /// Gets the position of this channel in the guild's channel list, relative to others of the same type. int Position { get; } + /// Gets the parentid (category) of this channel in the guild's channel list. + ulong? ParentId { get; } + /// Gets the parent channel (category) of this channel. + Task GetParentChannelAsync(); /// Gets the guild this channel is a member of. IGuild Guild { get; } /// Gets the id of the guild this channel is a member of. @@ -23,7 +27,7 @@ namespace Discord Task CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); /// Returns a collection of all invites to this channel. Task> GetInvitesAsync(RequestOptions options = null); - + /// Modifies this guild channel. Task ModifyAsync(Action func, RequestOptions options = null); diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs new file mode 100644 index 000000000..fa603e87b --- /dev/null +++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord +{ + public interface IGuildChannelCategory : IGuildChannel + { + ///// Modifies this text channel. + //Task ModifyAsync(Action func, RequestOptions options = null); + } +} diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index 3ded9e038..ee65fa3d4 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -84,6 +84,7 @@ namespace Discord Task> GetTextChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); diff --git a/src/Discord.Net.Rest/API/Common/Channel.cs b/src/Discord.Net.Rest/API/Common/Channel.cs index 608ddcf66..f986ab59b 100644 --- a/src/Discord.Net.Rest/API/Common/Channel.cs +++ b/src/Discord.Net.Rest/API/Common/Channel.cs @@ -23,6 +23,8 @@ namespace Discord.API public Optional Position { get; set; } [JsonProperty("permission_overwrites")] public Optional PermissionOverwrites { get; set; } + [JsonProperty("parent_id")] + public ulong? ParentId { get; set; } //TextChannel [JsonProperty("topic")] diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs new file mode 100644 index 000000000..293ade18e --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs @@ -0,0 +1,14 @@ +#pragma warning disable CS1591 +using Newtonsoft.Json; + +namespace Discord.API.Rest +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + internal class ModifyGuildChannelCategoryParams + { + [JsonProperty("name")] + public Optional Name { get; set; } + [JsonProperty("position")] + public Optional Position { get; set; } + } +} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs index b4add2ac9..5bf615d60 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs @@ -10,5 +10,7 @@ namespace Discord.API.Rest public Optional Name { get; set; } [JsonProperty("position")] public Optional Position { get; set; } + [JsonProperty("parent_id")] + public Optional ParentId { get; set; } } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index d61b5d14a..ebfd38e24 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -13,13 +13,13 @@ namespace Discord.Rest internal static class ChannelHelper { //General - public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client, + public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client, RequestOptions options) - { + { await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, - Action func, + public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, + Action func, RequestOptions options) { var args = new GuildChannelProperties(); @@ -27,12 +27,13 @@ namespace Discord.Rest var apiArgs = new API.Rest.ModifyGuildChannelParams { Name = args.Name, - Position = args.Position + Position = args.Position, + ParentId = args.ParentId }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } - public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, - Action func, + public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, + Action func, RequestOptions options) { var args = new TextChannelProperties(); @@ -41,13 +42,14 @@ namespace Discord.Rest { Name = args.Name, Position = args.Position, + ParentId = args.ParentId, Topic = args.Topic, IsNsfw = args.IsNsfw }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, - Action func, + public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, + Action func, RequestOptions options) { var args = new VoiceChannelProperties(); @@ -57,6 +59,7 @@ namespace Discord.Rest Bitrate = args.Bitrate, Name = args.Name, Position = args.Position, + ParentId = args.ParentId, UserLimit = args.UserLimit.IsSpecified ? (args.UserLimit.Value ?? 0) : Optional.Create() }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); @@ -86,7 +89,7 @@ namespace Discord.Rest } //Messages - public static async Task GetMessageAsync(IMessageChannel channel, BaseDiscordClient client, + public static async Task GetMessageAsync(IMessageChannel channel, BaseDiscordClient client, ulong id, RequestOptions options) { var guildId = (channel as IGuildChannel)?.GuildId; @@ -97,7 +100,7 @@ namespace Discord.Rest var author = GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); return RestMessage.Create(client, channel, author, model); } - public static IAsyncEnumerable> GetMessagesAsync(IMessageChannel channel, BaseDiscordClient client, + public static IAsyncEnumerable> GetMessagesAsync(IMessageChannel channel, BaseDiscordClient client, ulong? fromMessageId, Direction dir, int limit, RequestOptions options) { if (dir == Direction.Around) @@ -123,7 +126,7 @@ namespace Discord.Rest foreach (var model in models) { var author = GetAuthor(client, guild, model.Author.Value, model.WebhookId.ToNullable()); - builder.Add(RestMessage.Create(client, channel, author, model)); + builder.Add(RestMessage.Create(client, channel, author, model)); } return builder.ToImmutable(); }, @@ -179,7 +182,7 @@ namespace Discord.Rest var args = new UploadFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS }; var model = await client.ApiClient.UploadFileAsync(channel.Id, args, options).ConfigureAwait(false); return RestUserMessage.Create(client, channel, client.CurrentUser, model); - } + } public static async Task DeleteMessagesAsync(IMessageChannel channel, BaseDiscordClient client, IEnumerable messageIds, RequestOptions options) @@ -276,7 +279,7 @@ namespace Discord.Rest { await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options).ConfigureAwait(false); } - public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client, + public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client, RequestOptions options) => new TypingNotifier(client, channel, options); diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelType.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelType.cs index f05f1598e..e9f069a50 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelType.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelType.cs @@ -5,6 +5,7 @@ Text = 0, DM = 1, Voice = 2, - Group = 3 + Group = 3, + Category = 4 } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 07832a3a9..4524adf27 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -16,6 +16,8 @@ namespace Discord.Rest internal IGuild Guild { get; } public string Name { get; private set; } public int Position { get; private set; } + public ulong? ParentId { get; private set; } + public Task GetParentChannelAsync() => ParentId == null ? null : Guild.GetChannelAsync(ParentId.Value); public ulong GuildId => Guild.Id; @@ -61,7 +63,7 @@ namespace Discord.Rest } public Task DeleteAsync(RequestOptions options = null) => ChannelHelper.DeleteAsync(this, Discord, options); - + public OverwritePermissions? GetPermissionOverwrite(IUser user) { for (int i = 0; i < _overwrites.Length; i++) @@ -139,20 +141,20 @@ namespace Discord.Rest => await GetInvitesAsync(options).ConfigureAwait(false); async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) => await CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); - - OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) + + OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) => GetPermissionOverwrite(role); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) => GetPermissionOverwrite(user); - async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) + async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) => await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false); - async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) + async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) => await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false); - async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) + async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) => await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false); - async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) + async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) => await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false); - + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overriden //Overriden in Text/Voice Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs new file mode 100644 index 000000000..e4a59b30a --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Channel; + +namespace Discord.Rest +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class RestGuildChannelCategory : RestGuildChannel, IGuildChannelCategory + { + public string Mention => MentionUtils.MentionChannel(Id); + + internal RestGuildChannelCategory(BaseDiscordClient discord, IGuild guild, ulong id) + : base(discord, guild, id) + { + } + internal new static RestGuildChannelCategory Create(BaseDiscordClient discord, IGuild guild, Model model) + { + var entity = new RestGuildChannelCategory(discord, guild, model.Id); + entity.Update(model); + return entity; + } + internal override void Update(Model model) + { + base.Update(model); + } + + public Task GetUserAsync(ulong id, RequestOptions options = null) + => ChannelHelper.GetUserAsync(this, Guild, Discord, id, options); + public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) + => ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options); + + private string DebuggerDisplay => $"{Name} ({Id}, Text)"; + } +} diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index aee305951..66e6ba739 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -23,7 +23,7 @@ namespace Discord.Rest public VerificationLevel VerificationLevel { get; private set; } public MfaLevel MfaLevel { get; private set; } public DefaultMessageNotifications DefaultMessageNotifications { get; private set; } - + public ulong? AFKChannelId { get; private set; } public ulong? EmbedChannelId { get; private set; } public ulong? SystemChannelId { get; private set; } @@ -114,7 +114,7 @@ namespace Discord.Rest Update(model); } public async Task ModifyEmbedAsync(Action func, RequestOptions options = null) - { + { var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } @@ -155,7 +155,7 @@ namespace Discord.Rest public Task> GetChannelsAsync(RequestOptions options = null) => GuildHelper.GetChannelsAsync(this, Discord, options); public Task GetChannelAsync(ulong id, RequestOptions options = null) - => GuildHelper.GetChannelAsync(this, Discord, id, options); + => GuildHelper.GetChannelAsync(this, Discord, id, options); public async Task GetTextChannelAsync(ulong id, RequestOptions options = null) { var channel = await GuildHelper.GetChannelAsync(this, Discord, id, options).ConfigureAwait(false); @@ -176,6 +176,11 @@ namespace Discord.Rest var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); } + public async Task> GetChannelCategoriesAsync(RequestOptions options = null) + { + var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); + return channels.Select(x => x as RestGuildChannelCategory).Where(x => x != null).ToImmutableArray(); + } public async Task GetAFKChannelAsync(RequestOptions options = null) { @@ -199,7 +204,7 @@ namespace Discord.Rest public async Task GetEmbedChannelAsync(RequestOptions options = null) { var embedId = EmbedChannelId; - if (embedId.HasValue) + if (embedId.HasValue) return await GuildHelper.GetChannelAsync(this, Discord, embedId.Value, options).ConfigureAwait(false); return null; } @@ -236,7 +241,7 @@ namespace Discord.Rest return null; } - public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), + public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false, RequestOptions options = null) { var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options).ConfigureAwait(false); @@ -304,6 +309,13 @@ namespace Discord.Rest else return ImmutableArray.Create(); } + async Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) + { + if (mode == CacheMode.AllowDownload) + return await GetChannelCategoriesAsync(options).ConfigureAwait(false); + else + return null; + } async Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) @@ -352,7 +364,7 @@ namespace Discord.Rest async Task> IGuild.GetInvitesAsync(RequestOptions options) => await GetInvitesAsync(options).ConfigureAwait(false); - IRole IGuild.GetRole(ulong id) + IRole IGuild.GetRole(ulong id) => GetRole(id); async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) => await CreateRoleAsync(name, permissions, color, isHoisted, options).ConfigureAwait(false); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcChannelCategory.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcChannelCategory.cs new file mode 100644 index 000000000..229753cf4 --- /dev/null +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcChannelCategory.cs @@ -0,0 +1,38 @@ +using Discord.Rest; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Rpc.Channel; + +namespace Discord.Rpc +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class RpcChannelCategory : RpcGuildChannel + { + public IReadOnlyCollection 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 RpcChannelCategory(DiscordRpcClient discord, ulong id, ulong guildId) + : base(discord, id, guildId) + { + } + internal new static RpcChannelCategory Create(DiscordRpcClient discord, Model model) + { + var entity = new RpcChannelCategory(discord, model.Id, model.GuildId.Value); + entity.Update(model); + return entity; + } + internal override void Update(Model model) + { + base.Update(model); + CachedMessages = model.Messages.Select(x => RpcMessage.Create(Discord, Id, x)).ToImmutableArray(); + } + } +} diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs index 48eb8ec3e..02f04df93 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs @@ -10,6 +10,7 @@ namespace Discord.Rpc { public ulong GuildId { get; } public int Position { get; private set; } + public ulong? ParentId { get; private set; } internal RpcGuildChannel(DiscordRpcClient discord, ulong id, ulong guildId) : base(discord, id) @@ -57,6 +58,12 @@ namespace Discord.Rpc public override string ToString() => Name; //IGuildChannel + public Task GetParentChannelAsync() + { + //Always fails + throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); + } + IGuild IGuildChannel.Guild { get diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 1fe9a741f..64233f742 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -17,6 +17,9 @@ namespace Discord.WebSocket public SocketGuild Guild { get; } public string Name { get; private set; } public int Position { get; private set; } + public ulong? ParentId { get; private set; } + public IGuildChannel ParentChannel => ParentId == null ? null : Guild.GetChannel(ParentId.Value); + public Task GetParentChannelAsync() => Task.FromResult(ParentChannel); public IReadOnlyCollection PermissionOverwrites => _overwrites; public new virtual IReadOnlyCollection Users => ImmutableArray.Create(); @@ -34,6 +37,8 @@ namespace Discord.WebSocket return SocketTextChannel.Create(guild, state, model); case ChannelType.Voice: return SocketVoiceChannel.Create(guild, state, model); + case ChannelType.Category: + return SocketGuildChannelCategory.Create(guild, state, model); default: // TODO: Proper implementation for channel categories return new SocketGuildChannel(guild.Discord, model.Id, guild); @@ -43,6 +48,7 @@ namespace Discord.WebSocket { Name = model.Name.Value; Position = model.Position.Value; + ParentId = model.ParentId; var overwrites = model.PermissionOverwrites.Value; var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs new file mode 100644 index 000000000..d23060f78 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord.Audio; +using Discord.Rest; +using Model = Discord.API.Channel; + +namespace Discord.WebSocket +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketGuildChannelCategory : SocketGuildChannel, IGuildChannelCategory + { + public override IReadOnlyCollection Users + => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); + + internal SocketGuildChannelCategory(DiscordSocketClient discord, ulong id, SocketGuild guild) + : base(discord, id, guild) + { + } + internal new static SocketGuildChannelCategory Create(SocketGuild guild, ClientState state, Model model) + { + var entity = new SocketGuildChannelCategory(guild.Discord, model.Id, guild); + entity.Update(state, model); + return entity; + } + internal override void Update(ClientState state, Model model) + { + base.Update(state, model); + } + + public override SocketGuildUser GetUser(ulong id) + { + var user = Guild.GetUser(id); + if (user?.VoiceChannel?.Id == Id) + return user; + return null; + } + + private string DebuggerDisplay => $"{Name} ({Id}, Category)"; + internal new SocketGuildChannelCategory Clone() => MemberwiseClone() as SocketGuildChannelCategory; + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index b47ca84e8..b2529951a 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -74,7 +74,7 @@ namespace Discord.WebSocket return id.HasValue ? GetVoiceChannel(id.Value) : null; } } - public SocketGuildChannel EmbedChannel + public SocketGuildChannel EmbedChannel { get { @@ -94,6 +94,8 @@ namespace Discord.WebSocket => Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); public IReadOnlyCollection VoiceChannels => Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); + public IReadOnlyCollection ChannelCategories + => Channels.Select(x => x as SocketGuildChannelCategory).Where(x => x != null).ToImmutableArray(); public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; public SocketRole EveryoneRole => GetRole(Id); public IReadOnlyCollection Channels @@ -347,7 +349,7 @@ namespace Discord.WebSocket return value; return null; } - public Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), + public Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false, RequestOptions options = null) => GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options); internal SocketRole AddRole(RoleModel model) @@ -577,7 +579,7 @@ namespace Discord.WebSocket try { await RepopulateAudioStreamsAsync().ConfigureAwait(false); - await _audioClient.StartAsync(url, Discord.CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false); + await _audioClient.StartAsync(url, Discord.CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -634,6 +636,8 @@ namespace Discord.WebSocket => Task.FromResult(GetTextChannel(id)); Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(VoiceChannels); + Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) + => Task.FromResult>(ChannelCategories); Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetVoiceChannel(id)); Task IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options) From 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Mon Sep 17 00:00:00 2001 From: pegasy Date: Sun, 24 Sep 2017 19:08:25 +0200 Subject: [PATCH 2/3] removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories --- .../Channels/GuildChannelProperties.cs | 2 +- ...egoryProperties.cs => IChannelCategory.cs} | 6 +-- .../Entities/Channels/IGuildChannel.cs | 4 +- .../Channels/IGuildChannelCategory.cs | 14 ------ .../Entities/Guilds/IGuild.cs | 4 +- src/Discord.Net.Rest/API/Common/Channel.cs | 2 +- .../Rest/ModifyGuildChannelCategoryParams.cs | 14 ------ .../API/Rest/ModifyGuildChannelParams.cs | 2 +- .../Entities/Channels/ChannelHelper.cs | 6 +-- .../Entities/Channels/RestChannelCategory.cs | 45 +++++++++++++++++ .../Entities/Channels/RestGuildChannel.cs | 6 ++- .../Channels/RestGuildChannelCategory.cs | 38 -------------- .../Entities/Guilds/GuildHelper.cs | 9 ++++ .../Entities/Guilds/RestGuild.cs | 10 ++-- .../Entities/Channels/RpcGuildChannel.cs | 4 +- .../Channels/SocketChannelCategory.cs | 50 +++++++++++++++++++ .../Entities/Channels/SocketGuildChannel.cs | 10 ++-- .../Channels/SocketGuildChannelCategory.cs | 46 ----------------- .../Entities/Guilds/SocketGuild.cs | 13 +++-- 19 files changed, 145 insertions(+), 140 deletions(-) rename src/Discord.Net.Core/Entities/Channels/{GuildChannelCategoryProperties.cs => IChannelCategory.cs} (60%) delete mode 100644 src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs delete mode 100644 src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs create mode 100644 src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs delete mode 100644 src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs create mode 100644 src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs delete mode 100644 src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs index e580a2e59..2ac6c8d52 100644 --- a/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs @@ -29,6 +29,6 @@ /// /// Sets the category for this channel /// - public Optional ParentId { get; set; } + public Optional CategoryId { get; set; } } } diff --git a/src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs b/src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs similarity index 60% rename from src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs rename to src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs index 2678e5eef..bd20d7639 100644 --- a/src/Discord.Net.Core/Entities/Channels/GuildChannelCategoryProperties.cs +++ b/src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Discord { - //public class GuildChannelCategoryProperties : GuildChannelProperties - //{ - //} + public interface IChannelCategory : IGuildChannel + { + } } diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs index b019fab23..d2683018f 100644 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs @@ -10,9 +10,9 @@ namespace Discord int Position { get; } /// Gets the parentid (category) of this channel in the guild's channel list. - ulong? ParentId { get; } + ulong? CategoryId { get; } /// Gets the parent channel (category) of this channel. - Task GetParentChannelAsync(); + Task GetCategory(); /// Gets the guild this channel is a member of. IGuild Guild { get; } /// Gets the id of the guild this channel is a member of. diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs deleted file mode 100644 index fa603e87b..000000000 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannelCategory.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Discord -{ - public interface IGuildChannelCategory : IGuildChannel - { - ///// Modifies this text channel. - //Task ModifyAsync(Action func, RequestOptions options = null); - } -} diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index ee65fa3d4..aa61fbd80 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -84,7 +84,7 @@ namespace Discord Task> GetTextChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); - Task> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); @@ -94,6 +94,8 @@ namespace Discord Task CreateTextChannelAsync(string name, RequestOptions options = null); /// Creates a new voice channel. Task CreateVoiceChannelAsync(string name, RequestOptions options = null); + /// Creates a new channel category. + Task CreateChannelCategoryAsync(string name, RequestOptions options = null); Task> GetIntegrationsAsync(RequestOptions options = null); Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null); diff --git a/src/Discord.Net.Rest/API/Common/Channel.cs b/src/Discord.Net.Rest/API/Common/Channel.cs index f986ab59b..97c35a57b 100644 --- a/src/Discord.Net.Rest/API/Common/Channel.cs +++ b/src/Discord.Net.Rest/API/Common/Channel.cs @@ -24,7 +24,7 @@ namespace Discord.API [JsonProperty("permission_overwrites")] public Optional PermissionOverwrites { get; set; } [JsonProperty("parent_id")] - public ulong? ParentId { get; set; } + public ulong? CategoryId { get; set; } //TextChannel [JsonProperty("topic")] diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs deleted file mode 100644 index 293ade18e..000000000 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelCategoryParams.cs +++ /dev/null @@ -1,14 +0,0 @@ -#pragma warning disable CS1591 -using Newtonsoft.Json; - -namespace Discord.API.Rest -{ - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - internal class ModifyGuildChannelCategoryParams - { - [JsonProperty("name")] - public Optional Name { get; set; } - [JsonProperty("position")] - public Optional Position { get; set; } - } -} diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs index 5bf615d60..120eeb3a8 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs @@ -11,6 +11,6 @@ namespace Discord.API.Rest [JsonProperty("position")] public Optional Position { get; set; } [JsonProperty("parent_id")] - public Optional ParentId { get; set; } + public Optional CategoryId { get; set; } } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index ebfd38e24..4c265f3aa 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -28,7 +28,7 @@ namespace Discord.Rest { Name = args.Name, Position = args.Position, - ParentId = args.ParentId + CategoryId = args.CategoryId }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } @@ -42,7 +42,7 @@ namespace Discord.Rest { Name = args.Name, Position = args.Position, - ParentId = args.ParentId, + CategoryId = args.CategoryId, Topic = args.Topic, IsNsfw = args.IsNsfw }; @@ -59,7 +59,7 @@ namespace Discord.Rest Bitrate = args.Bitrate, Name = args.Name, Position = args.Position, - ParentId = args.ParentId, + CategoryId = args.CategoryId, UserLimit = args.UserLimit.IsSpecified ? (args.UserLimit.Value ?? 0) : Optional.Create() }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs new file mode 100644 index 000000000..acea5a981 --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Model = Discord.API.Channel; + +namespace Discord.Rest +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class RestChannelCategory : RestGuildChannel, IChannelCategory + { + public string Mention => MentionUtils.MentionChannel(Id); + + internal RestChannelCategory(BaseDiscordClient discord, IGuild guild, ulong id) + : base(discord, guild, id) + { + } + internal new static RestChannelCategory Create(BaseDiscordClient discord, IGuild guild, Model model) + { + var entity = new RestChannelCategory(discord, guild, model.Id); + entity.Update(model); + return entity; + } + + private string DebuggerDisplay => $"{Name} ({Id}, Category)"; + + // IGuildChannel + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) + => throw new NotSupportedException(); + Task> IGuildChannel.GetInvitesAsync(RequestOptions options) + => throw new NotSupportedException(); + + //IChannel + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + } +} diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 4524adf27..f00755219 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -16,8 +16,8 @@ namespace Discord.Rest internal IGuild Guild { get; } public string Name { get; private set; } public int Position { get; private set; } - public ulong? ParentId { get; private set; } - public Task GetParentChannelAsync() => ParentId == null ? null : Guild.GetChannelAsync(ParentId.Value); + public ulong? CategoryId { get; private set; } + public async Task GetCategory() => CategoryId == null ? null : await Guild.GetChannelAsync(CategoryId.Value) as IChannelCategory; public ulong GuildId => Guild.Id; @@ -34,6 +34,8 @@ namespace Discord.Rest return RestTextChannel.Create(discord, guild, model); case ChannelType.Voice: return RestVoiceChannel.Create(discord, guild, model); + case ChannelType.Category: + return RestChannelCategory.Create(discord, guild, model); default: // TODO: Channel categories return new RestGuildChannel(discord, guild, model.Id); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs deleted file mode 100644 index e4a59b30a..000000000 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannelCategory.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Model = Discord.API.Channel; - -namespace Discord.Rest -{ - [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class RestGuildChannelCategory : RestGuildChannel, IGuildChannelCategory - { - public string Mention => MentionUtils.MentionChannel(Id); - - internal RestGuildChannelCategory(BaseDiscordClient discord, IGuild guild, ulong id) - : base(discord, guild, id) - { - } - internal new static RestGuildChannelCategory Create(BaseDiscordClient discord, IGuild guild, Model model) - { - var entity = new RestGuildChannelCategory(discord, guild, model.Id); - entity.Update(model); - return entity; - } - internal override void Update(Model model) - { - base.Update(model); - } - - public Task GetUserAsync(ulong id, RequestOptions options = null) - => ChannelHelper.GetUserAsync(this, Guild, Discord, id, options); - public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) - => ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options); - - private string DebuggerDisplay => $"{Name} ({Id}, Text)"; - } -} diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 2fa29928c..64c5899e4 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -157,6 +157,15 @@ namespace Discord.Rest var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestVoiceChannel.Create(client, guild, model); } + public static async Task CreateChannelCategoryAsync(IGuild guild, BaseDiscordClient client, + string name, RequestOptions options) + { + if (name == null) throw new ArgumentNullException(nameof(name)); + + var args = new CreateGuildChannelParams(name, ChannelType.Category); + var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); + return RestChannelCategory.Create(client, guild, model); + } //Integrations public static async Task> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client, diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 66e6ba739..101d9ca21 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -176,10 +176,10 @@ namespace Discord.Rest var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); } - public async Task> GetChannelCategoriesAsync(RequestOptions options = null) + public async Task> GetChannelCategoriesAsync(RequestOptions options = null) { var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); - return channels.Select(x => x as RestGuildChannelCategory).Where(x => x != null).ToImmutableArray(); + return channels.Select(x => x as RestChannelCategory).Where(x => x != null).ToImmutableArray(); } public async Task GetAFKChannelAsync(RequestOptions options = null) @@ -222,6 +222,8 @@ namespace Discord.Rest => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); + public Task CreateChannelCategoryAsync(string name, RequestOptions options = null) + => GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); //Integrations public Task> GetIntegrationsAsync(RequestOptions options = null) @@ -309,7 +311,7 @@ namespace Discord.Rest else return ImmutableArray.Create(); } - async Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) + async Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) { if (mode == CacheMode.AllowDownload) return await GetChannelCategoriesAsync(options).ConfigureAwait(false); @@ -355,6 +357,8 @@ namespace Discord.Rest => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) + => await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) => await GetIntegrationsAsync(options).ConfigureAwait(false); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs index 02f04df93..92f5e9013 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs @@ -10,7 +10,7 @@ namespace Discord.Rpc { public ulong GuildId { get; } public int Position { get; private set; } - public ulong? ParentId { get; private set; } + public ulong? CategoryId { get; private set; } internal RpcGuildChannel(DiscordRpcClient discord, ulong id, ulong guildId) : base(discord, id) @@ -58,7 +58,7 @@ namespace Discord.Rpc public override string ToString() => Name; //IGuildChannel - public Task GetParentChannelAsync() + public Task GetCategory() { //Always fails throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs new file mode 100644 index 000000000..e1f764551 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord.Audio; +using Discord.Rest; +using Model = Discord.API.Channel; + +namespace Discord.WebSocket +{ + [DebuggerDisplay(@"{DebuggerDisplay,nq}")] + public class SocketChannelCategory : SocketGuildChannel, IChannelCategory + { + public override IReadOnlyCollection Users + => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); + + internal SocketChannelCategory(DiscordSocketClient discord, ulong id, SocketGuild guild) + : base(discord, id, guild) + { + } + internal new static SocketChannelCategory Create(SocketGuild guild, ClientState state, Model model) + { + var entity = new SocketChannelCategory(guild.Discord, model.Id, guild); + entity.Update(state, model); + return entity; + } + + private string DebuggerDisplay => $"{Name} ({Id}, Category)"; + internal new SocketChannelCategory Clone() => MemberwiseClone() as SocketChannelCategory; + + // IGuildChannel + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) + => throw new NotSupportedException(); + Task> IGuildChannel.GetInvitesAsync(RequestOptions options) + => throw new NotSupportedException(); + + //IChannel + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => throw new NotSupportedException(); + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 64233f742..7255a7fa3 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -17,9 +17,9 @@ namespace Discord.WebSocket public SocketGuild Guild { get; } public string Name { get; private set; } public int Position { get; private set; } - public ulong? ParentId { get; private set; } - public IGuildChannel ParentChannel => ParentId == null ? null : Guild.GetChannel(ParentId.Value); - public Task GetParentChannelAsync() => Task.FromResult(ParentChannel); + public ulong? CategoryId { get; private set; } + public IChannelCategory Category => CategoryId == null ? null : Guild.GetChannel(CategoryId.Value) as IChannelCategory; + Task IGuildChannel.GetCategory() => Task.FromResult(Category); public IReadOnlyCollection PermissionOverwrites => _overwrites; public new virtual IReadOnlyCollection Users => ImmutableArray.Create(); @@ -38,7 +38,7 @@ namespace Discord.WebSocket case ChannelType.Voice: return SocketVoiceChannel.Create(guild, state, model); case ChannelType.Category: - return SocketGuildChannelCategory.Create(guild, state, model); + return SocketChannelCategory.Create(guild, state, model); default: // TODO: Proper implementation for channel categories return new SocketGuildChannel(guild.Discord, model.Id, guild); @@ -48,7 +48,7 @@ namespace Discord.WebSocket { Name = model.Name.Value; Position = model.Position.Value; - ParentId = model.ParentId; + CategoryId = model.CategoryId; var overwrites = model.PermissionOverwrites.Value; var newOverwrites = ImmutableArray.CreateBuilder(overwrites.Length); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs deleted file mode 100644 index d23060f78..000000000 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannelCategory.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Discord.Audio; -using Discord.Rest; -using Model = Discord.API.Channel; - -namespace Discord.WebSocket -{ - [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class SocketGuildChannelCategory : SocketGuildChannel, IGuildChannelCategory - { - public override IReadOnlyCollection Users - => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); - - internal SocketGuildChannelCategory(DiscordSocketClient discord, ulong id, SocketGuild guild) - : base(discord, id, guild) - { - } - internal new static SocketGuildChannelCategory Create(SocketGuild guild, ClientState state, Model model) - { - var entity = new SocketGuildChannelCategory(guild.Discord, model.Id, guild); - entity.Update(state, model); - return entity; - } - internal override void Update(ClientState state, Model model) - { - base.Update(state, model); - } - - public override SocketGuildUser GetUser(ulong id) - { - var user = Guild.GetUser(id); - if (user?.VoiceChannel?.Id == Id) - return user; - return null; - } - - private string DebuggerDisplay => $"{Name} ({Id}, Category)"; - internal new SocketGuildChannelCategory Clone() => MemberwiseClone() as SocketGuildChannelCategory; - } -} diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index b2529951a..9d64db415 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -94,8 +94,8 @@ namespace Discord.WebSocket => Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); public IReadOnlyCollection VoiceChannels => Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); - public IReadOnlyCollection ChannelCategories - => Channels.Select(x => x as SocketGuildChannelCategory).Where(x => x != null).ToImmutableArray(); + public IReadOnlyCollection ChannelCategories + => Channels.Select(x => x as SocketChannelCategory).Where(x => x != null).ToImmutableArray(); public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; public SocketRole EveryoneRole => GetRole(Id); public IReadOnlyCollection Channels @@ -318,6 +318,9 @@ namespace Discord.WebSocket => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); + public Task CreateChannelCategoryAsync(string name, RequestOptions options = null) + => GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); + internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) { var channel = SocketGuildChannel.Create(this, state, model); @@ -636,8 +639,8 @@ namespace Discord.WebSocket => Task.FromResult(GetTextChannel(id)); Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(VoiceChannels); - Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) - => Task.FromResult>(ChannelCategories); + Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) + => Task.FromResult>(ChannelCategories); Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetVoiceChannel(id)); Task IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options) @@ -652,6 +655,8 @@ namespace Discord.WebSocket => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) + => await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) => await GetIntegrationsAsync(options).ConfigureAwait(false); From d59b038efa048b2279602e2015ddd2c185e58d63 Mon Sep 17 00:00:00 2001 From: pegasy Date: Mon, 25 Sep 2017 18:53:23 +0200 Subject: [PATCH 3/3] Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. --- .../{IChannelCategory.cs => ICategoryChannel.cs} | 2 +- .../Entities/Channels/IGuildChannel.cs | 2 +- src/Discord.Net.Core/Entities/Guilds/IGuild.cs | 4 ++-- ...ChannelCategory.cs => RestCategoryChannel.cs} | 8 ++++---- .../Entities/Channels/RestGuildChannel.cs | 4 ++-- .../Entities/Guilds/GuildHelper.cs | 4 ++-- .../Entities/Guilds/RestGuild.cs | 16 ++++++++-------- ...cChannelCategory.cs => RpcCategoryChannel.cs} | 10 ++++------ .../Entities/Channels/RpcGuildChannel.cs | 2 +- ...annelCategory.cs => SocketCategoryChannel.cs} | 10 +++++----- .../Entities/Channels/SocketGuildChannel.cs | 6 +++--- .../Entities/Guilds/SocketGuild.cs | 16 ++++++++-------- 12 files changed, 41 insertions(+), 43 deletions(-) rename src/Discord.Net.Core/Entities/Channels/{IChannelCategory.cs => ICategoryChannel.cs} (74%) rename src/Discord.Net.Rest/Entities/Channels/{RestChannelCategory.cs => RestCategoryChannel.cs} (86%) rename src/Discord.Net.Rpc/Entities/Channels/{RpcChannelCategory.cs => RpcCategoryChannel.cs} (70%) rename src/Discord.Net.WebSocket/Entities/Channels/{SocketChannelCategory.cs => SocketCategoryChannel.cs} (83%) diff --git a/src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs b/src/Discord.Net.Core/Entities/Channels/ICategoryChannel.cs similarity index 74% rename from src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs rename to src/Discord.Net.Core/Entities/Channels/ICategoryChannel.cs index bd20d7639..0f7f5aa62 100644 --- a/src/Discord.Net.Core/Entities/Channels/IChannelCategory.cs +++ b/src/Discord.Net.Core/Entities/Channels/ICategoryChannel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Discord { - public interface IChannelCategory : IGuildChannel + public interface ICategoryChannel : IGuildChannel { } } diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs index d2683018f..6d830672b 100644 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs @@ -12,7 +12,7 @@ namespace Discord /// Gets the parentid (category) of this channel in the guild's channel list. ulong? CategoryId { get; } /// Gets the parent channel (category) of this channel. - Task GetCategory(); + Task GetCategory(); /// Gets the guild this channel is a member of. IGuild Guild { get; } /// Gets the id of the guild this channel is a member of. diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index aa61fbd80..83953cf12 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -84,7 +84,7 @@ namespace Discord Task> GetTextChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); - Task> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetCategoryChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); @@ -95,7 +95,7 @@ namespace Discord /// Creates a new voice channel. Task CreateVoiceChannelAsync(string name, RequestOptions options = null); /// Creates a new channel category. - Task CreateChannelCategoryAsync(string name, RequestOptions options = null); + Task CreateCategoryChannelAsync(string name, RequestOptions options = null); Task> GetIntegrationsAsync(RequestOptions options = null); Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs b/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs similarity index 86% rename from src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs rename to src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs index acea5a981..f0140ed9e 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestChannelCategory.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestCategoryChannel.cs @@ -9,17 +9,17 @@ using Model = Discord.API.Channel; namespace Discord.Rest { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class RestChannelCategory : RestGuildChannel, IChannelCategory + public class RestCategoryChannel : RestGuildChannel, ICategoryChannel { public string Mention => MentionUtils.MentionChannel(Id); - internal RestChannelCategory(BaseDiscordClient discord, IGuild guild, ulong id) + internal RestCategoryChannel(BaseDiscordClient discord, IGuild guild, ulong id) : base(discord, guild, id) { } - internal new static RestChannelCategory Create(BaseDiscordClient discord, IGuild guild, Model model) + internal new static RestCategoryChannel Create(BaseDiscordClient discord, IGuild guild, Model model) { - var entity = new RestChannelCategory(discord, guild, model.Id); + var entity = new RestCategoryChannel(discord, guild, model.Id); entity.Update(model); return entity; } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index f00755219..3484a333e 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -17,7 +17,7 @@ namespace Discord.Rest public string Name { get; private set; } public int Position { get; private set; } public ulong? CategoryId { get; private set; } - public async Task GetCategory() => CategoryId == null ? null : await Guild.GetChannelAsync(CategoryId.Value) as IChannelCategory; + public async Task GetCategory() => CategoryId == null ? null : await Guild.GetChannelAsync(CategoryId.Value) as ICategoryChannel; public ulong GuildId => Guild.Id; @@ -35,7 +35,7 @@ namespace Discord.Rest case ChannelType.Voice: return RestVoiceChannel.Create(discord, guild, model); case ChannelType.Category: - return RestChannelCategory.Create(discord, guild, model); + return RestCategoryChannel.Create(discord, guild, model); default: // TODO: Channel categories return new RestGuildChannel(discord, guild, model.Id); diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 64c5899e4..a33f27243 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -157,14 +157,14 @@ namespace Discord.Rest var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestVoiceChannel.Create(client, guild, model); } - public static async Task CreateChannelCategoryAsync(IGuild guild, BaseDiscordClient client, + public static async Task CreateCategoryChannelAsync(IGuild guild, BaseDiscordClient client, string name, RequestOptions options) { if (name == null) throw new ArgumentNullException(nameof(name)); var args = new CreateGuildChannelParams(name, ChannelType.Category); var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); - return RestChannelCategory.Create(client, guild, model); + return RestCategoryChannel.Create(client, guild, model); } //Integrations diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 101d9ca21..7dcb631f5 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -176,10 +176,10 @@ namespace Discord.Rest var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); } - public async Task> GetChannelCategoriesAsync(RequestOptions options = null) + public async Task> GetCategoryChannelsAsync(RequestOptions options = null) { var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); - return channels.Select(x => x as RestChannelCategory).Where(x => x != null).ToImmutableArray(); + return channels.Select(x => x as RestCategoryChannel).Where(x => x != null).ToImmutableArray(); } public async Task GetAFKChannelAsync(RequestOptions options = null) @@ -222,8 +222,8 @@ namespace Discord.Rest => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); - public Task CreateChannelCategoryAsync(string name, RequestOptions options = null) - => GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); + public Task CreateCategoryChannelAsync(string name, RequestOptions options = null) + => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); //Integrations public Task> GetIntegrationsAsync(RequestOptions options = null) @@ -311,10 +311,10 @@ namespace Discord.Rest else return ImmutableArray.Create(); } - async Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) + async Task> IGuild.GetCategoryChannelsAsync(CacheMode mode , RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetChannelCategoriesAsync(options).ConfigureAwait(false); + return await GetCategoryChannelsAsync(options).ConfigureAwait(false); else return null; } @@ -357,8 +357,8 @@ namespace Discord.Rest => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); - async Task IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) - => await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateCategoryChannelAsync(string name, RequestOptions options) + => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) => await GetIntegrationsAsync(options).ConfigureAwait(false); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcChannelCategory.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcCategoryChannel.cs similarity index 70% rename from src/Discord.Net.Rpc/Entities/Channels/RpcChannelCategory.cs rename to src/Discord.Net.Rpc/Entities/Channels/RpcCategoryChannel.cs index 229753cf4..cac766f92 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcChannelCategory.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcCategoryChannel.cs @@ -11,21 +11,19 @@ using Model = Discord.API.Rpc.Channel; namespace Discord.Rpc { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class RpcChannelCategory : RpcGuildChannel + public class RpcCategoryChannel : RpcGuildChannel, ICategoryChannel { public IReadOnlyCollection 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 RpcChannelCategory(DiscordRpcClient discord, ulong id, ulong guildId) + internal RpcCategoryChannel(DiscordRpcClient discord, ulong id, ulong guildId) : base(discord, id, guildId) { } - internal new static RpcChannelCategory Create(DiscordRpcClient discord, Model model) + internal new static RpcCategoryChannel Create(DiscordRpcClient discord, Model model) { - var entity = new RpcChannelCategory(discord, model.Id, model.GuildId.Value); + var entity = new RpcCategoryChannel(discord, model.Id, model.GuildId.Value); entity.Update(model); return entity; } diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs index 92f5e9013..47eb5cc80 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs @@ -58,7 +58,7 @@ namespace Discord.Rpc public override string ToString() => Name; //IGuildChannel - public Task GetCategory() + public Task GetCategory() { //Always fails throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs similarity index 83% rename from src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs rename to src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs index e1f764551..905b219d8 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelCategory.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs @@ -12,24 +12,24 @@ using Model = Discord.API.Channel; namespace Discord.WebSocket { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public class SocketChannelCategory : SocketGuildChannel, IChannelCategory + public class SocketCategoryChannel : SocketGuildChannel, ICategoryChannel { public override IReadOnlyCollection Users => Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray(); - internal SocketChannelCategory(DiscordSocketClient discord, ulong id, SocketGuild guild) + internal SocketCategoryChannel(DiscordSocketClient discord, ulong id, SocketGuild guild) : base(discord, id, guild) { } - internal new static SocketChannelCategory Create(SocketGuild guild, ClientState state, Model model) + internal new static SocketCategoryChannel Create(SocketGuild guild, ClientState state, Model model) { - var entity = new SocketChannelCategory(guild.Discord, model.Id, guild); + var entity = new SocketCategoryChannel(guild.Discord, model.Id, guild); entity.Update(state, model); return entity; } private string DebuggerDisplay => $"{Name} ({Id}, Category)"; - internal new SocketChannelCategory Clone() => MemberwiseClone() as SocketChannelCategory; + internal new SocketCategoryChannel Clone() => MemberwiseClone() as SocketCategoryChannel; // IGuildChannel IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 7255a7fa3..8eed157cc 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -18,8 +18,8 @@ namespace Discord.WebSocket public string Name { get; private set; } public int Position { get; private set; } public ulong? CategoryId { get; private set; } - public IChannelCategory Category => CategoryId == null ? null : Guild.GetChannel(CategoryId.Value) as IChannelCategory; - Task IGuildChannel.GetCategory() => Task.FromResult(Category); + public ICategoryChannel Category => CategoryId == null ? null : Guild.GetChannel(CategoryId.Value) as ICategoryChannel; + Task IGuildChannel.GetCategory() => Task.FromResult(Category); public IReadOnlyCollection PermissionOverwrites => _overwrites; public new virtual IReadOnlyCollection Users => ImmutableArray.Create(); @@ -38,7 +38,7 @@ namespace Discord.WebSocket case ChannelType.Voice: return SocketVoiceChannel.Create(guild, state, model); case ChannelType.Category: - return SocketChannelCategory.Create(guild, state, model); + return SocketCategoryChannel.Create(guild, state, model); default: // TODO: Proper implementation for channel categories return new SocketGuildChannel(guild.Discord, model.Id, guild); diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 9d64db415..657bf5335 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -94,8 +94,8 @@ namespace Discord.WebSocket => Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); public IReadOnlyCollection VoiceChannels => Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); - public IReadOnlyCollection ChannelCategories - => Channels.Select(x => x as SocketChannelCategory).Where(x => x != null).ToImmutableArray(); + public IReadOnlyCollection CategoryChannels + => Channels.Select(x => x as SocketCategoryChannel).Where(x => x != null).ToImmutableArray(); public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; public SocketRole EveryoneRole => GetRole(Id); public IReadOnlyCollection Channels @@ -318,8 +318,8 @@ namespace Discord.WebSocket => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); - public Task CreateChannelCategoryAsync(string name, RequestOptions options = null) - => GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); + public Task CreateCategoryChannelAsync(string name, RequestOptions options = null) + => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) { @@ -639,8 +639,8 @@ namespace Discord.WebSocket => Task.FromResult(GetTextChannel(id)); Task> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(VoiceChannels); - Task> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) - => Task.FromResult>(ChannelCategories); + Task> IGuild.GetCategoryChannelsAsync(CacheMode mode , RequestOptions options) + => Task.FromResult>(CategoryChannels); Task IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetVoiceChannel(id)); Task IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options) @@ -655,8 +655,8 @@ namespace Discord.WebSocket => await CreateTextChannelAsync(name, options).ConfigureAwait(false); async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); - async Task IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) - => await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); + async Task IGuild.CreateCategoryChannelAsync(string name, RequestOptions options) + => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); async Task> IGuild.GetIntegrationsAsync(RequestOptions options) => await GetIntegrationsAsync(options).ConfigureAwait(false);