Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categoriespull/821/head
@@ -29,6 +29,6 @@ | |||||
/// <summary> | /// <summary> | ||||
/// Sets the category for this channel | /// Sets the category for this channel | ||||
/// </summary> | /// </summary> | ||||
public Optional<ulong?> ParentId { get; set; } | |||||
public Optional<ulong?> CategoryId { get; set; } | |||||
} | } | ||||
} | } |
@@ -6,7 +6,7 @@ using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
//public class GuildChannelCategoryProperties : GuildChannelProperties | |||||
//{ | |||||
//} | |||||
public interface IChannelCategory : IGuildChannel | |||||
{ | |||||
} | |||||
} | } |
@@ -10,9 +10,9 @@ namespace Discord | |||||
int Position { get; } | int Position { get; } | ||||
/// <summary> Gets the parentid (category) of this channel in the guild's channel list. </summary> | /// <summary> Gets the parentid (category) of this channel in the guild's channel list. </summary> | ||||
ulong? ParentId { get; } | |||||
ulong? CategoryId { get; } | |||||
/// <summary> Gets the parent channel (category) of this channel. </summary> | /// <summary> Gets the parent channel (category) of this channel. </summary> | ||||
Task<IGuildChannel> GetParentChannelAsync(); | |||||
Task<IChannelCategory> GetCategory(); | |||||
/// <summary> Gets the guild this channel is a member of. </summary> | /// <summary> Gets the guild this channel is a member of. </summary> | ||||
IGuild Guild { get; } | IGuild Guild { get; } | ||||
/// <summary> Gets the id of the guild this channel is a member of. </summary> | /// <summary> Gets the id of the guild this channel is a member of. </summary> | ||||
@@ -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 | |||||
{ | |||||
///// <summary> Modifies this text channel. </summary> | |||||
//Task ModifyAsync(Action<GuildChannelCategoryProperties> func, RequestOptions options = null); | |||||
} | |||||
} |
@@ -84,7 +84,7 @@ namespace Discord | |||||
Task<IReadOnlyCollection<ITextChannel>> GetTextChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<IReadOnlyCollection<ITextChannel>> GetTextChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<ITextChannel> GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<ITextChannel> GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<IReadOnlyCollection<IVoiceChannel>> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<IReadOnlyCollection<IVoiceChannel>> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<IReadOnlyCollection<IGuildChannelCategory>> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||||
Task<IReadOnlyCollection<IChannelCategory>> GetChannelCategoriesAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||||
Task<IVoiceChannel> GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<IVoiceChannel> GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<IVoiceChannel> GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<IVoiceChannel> GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<ITextChannel> GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<ITextChannel> GetSystemChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
@@ -94,6 +94,8 @@ namespace Discord | |||||
Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null); | Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null); | ||||
/// <summary> Creates a new voice channel. </summary> | /// <summary> Creates a new voice channel. </summary> | ||||
Task<IVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null); | Task<IVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null); | ||||
/// <summary> Creates a new channel category. </summary> | |||||
Task<IChannelCategory> CreateChannelCategoryAsync(string name, RequestOptions options = null); | |||||
Task<IReadOnlyCollection<IGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null); | Task<IReadOnlyCollection<IGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null); | ||||
Task<IGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null); | Task<IGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null); | ||||
@@ -24,7 +24,7 @@ namespace Discord.API | |||||
[JsonProperty("permission_overwrites")] | [JsonProperty("permission_overwrites")] | ||||
public Optional<Overwrite[]> PermissionOverwrites { get; set; } | public Optional<Overwrite[]> PermissionOverwrites { get; set; } | ||||
[JsonProperty("parent_id")] | [JsonProperty("parent_id")] | ||||
public ulong? ParentId { get; set; } | |||||
public ulong? CategoryId { get; set; } | |||||
//TextChannel | //TextChannel | ||||
[JsonProperty("topic")] | [JsonProperty("topic")] | ||||
@@ -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<string> Name { get; set; } | |||||
[JsonProperty("position")] | |||||
public Optional<int> Position { get; set; } | |||||
} | |||||
} |
@@ -11,6 +11,6 @@ namespace Discord.API.Rest | |||||
[JsonProperty("position")] | [JsonProperty("position")] | ||||
public Optional<int> Position { get; set; } | public Optional<int> Position { get; set; } | ||||
[JsonProperty("parent_id")] | [JsonProperty("parent_id")] | ||||
public Optional<ulong?> ParentId { get; set; } | |||||
public Optional<ulong?> CategoryId { get; set; } | |||||
} | } | ||||
} | } |
@@ -28,7 +28,7 @@ namespace Discord.Rest | |||||
{ | { | ||||
Name = args.Name, | Name = args.Name, | ||||
Position = args.Position, | Position = args.Position, | ||||
ParentId = args.ParentId | |||||
CategoryId = args.CategoryId | |||||
}; | }; | ||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | ||||
} | } | ||||
@@ -42,7 +42,7 @@ namespace Discord.Rest | |||||
{ | { | ||||
Name = args.Name, | Name = args.Name, | ||||
Position = args.Position, | Position = args.Position, | ||||
ParentId = args.ParentId, | |||||
CategoryId = args.CategoryId, | |||||
Topic = args.Topic, | Topic = args.Topic, | ||||
IsNsfw = args.IsNsfw | IsNsfw = args.IsNsfw | ||||
}; | }; | ||||
@@ -59,7 +59,7 @@ namespace Discord.Rest | |||||
Bitrate = args.Bitrate, | Bitrate = args.Bitrate, | ||||
Name = args.Name, | Name = args.Name, | ||||
Position = args.Position, | Position = args.Position, | ||||
ParentId = args.ParentId, | |||||
CategoryId = args.CategoryId, | |||||
UserLimit = args.UserLimit.IsSpecified ? (args.UserLimit.Value ?? 0) : Optional.Create<int>() | UserLimit = args.UserLimit.IsSpecified ? (args.UserLimit.Value ?? 0) : Optional.Create<int>() | ||||
}; | }; | ||||
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | ||||
@@ -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<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
//IChannel | |||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
} | |||||
} |
@@ -16,8 +16,8 @@ namespace Discord.Rest | |||||
internal IGuild Guild { get; } | internal IGuild Guild { get; } | ||||
public string Name { get; private set; } | public string Name { get; private set; } | ||||
public int Position { get; private set; } | public int Position { get; private set; } | ||||
public ulong? ParentId { get; private set; } | |||||
public Task<IGuildChannel> GetParentChannelAsync() => ParentId == null ? null : Guild.GetChannelAsync(ParentId.Value); | |||||
public ulong? CategoryId { get; private set; } | |||||
public async Task<IChannelCategory> GetCategory() => CategoryId == null ? null : await Guild.GetChannelAsync(CategoryId.Value) as IChannelCategory; | |||||
public ulong GuildId => Guild.Id; | public ulong GuildId => Guild.Id; | ||||
@@ -34,6 +34,8 @@ namespace Discord.Rest | |||||
return RestTextChannel.Create(discord, guild, model); | return RestTextChannel.Create(discord, guild, model); | ||||
case ChannelType.Voice: | case ChannelType.Voice: | ||||
return RestVoiceChannel.Create(discord, guild, model); | return RestVoiceChannel.Create(discord, guild, model); | ||||
case ChannelType.Category: | |||||
return RestChannelCategory.Create(discord, guild, model); | |||||
default: | default: | ||||
// TODO: Channel categories | // TODO: Channel categories | ||||
return new RestGuildChannel(discord, guild, model.Id); | return new RestGuildChannel(discord, guild, model.Id); | ||||
@@ -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<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); | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | |||||
} | |||||
} |
@@ -157,6 +157,15 @@ namespace Discord.Rest | |||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | ||||
return RestVoiceChannel.Create(client, guild, model); | return RestVoiceChannel.Create(client, guild, model); | ||||
} | } | ||||
public static async Task<RestChannelCategory> 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 | //Integrations | ||||
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client, | public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client, | ||||
@@ -176,10 +176,10 @@ namespace Discord.Rest | |||||
var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | ||||
return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); | return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); | ||||
} | } | ||||
public async Task<IReadOnlyCollection<RestGuildChannelCategory>> GetChannelCategoriesAsync(RequestOptions options = null) | |||||
public async Task<IReadOnlyCollection<RestChannelCategory>> GetChannelCategoriesAsync(RequestOptions options = null) | |||||
{ | { | ||||
var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | 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<RestVoiceChannel> GetAFKChannelAsync(RequestOptions options = null) | public async Task<RestVoiceChannel> GetAFKChannelAsync(RequestOptions options = null) | ||||
@@ -222,6 +222,8 @@ namespace Discord.Rest | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | ||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | ||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | ||||
public Task<RestChannelCategory> CreateChannelCategoryAsync(string name, RequestOptions options = null) | |||||
=> GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); | |||||
//Integrations | //Integrations | ||||
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null) | ||||
@@ -309,7 +311,7 @@ namespace Discord.Rest | |||||
else | else | ||||
return ImmutableArray.Create<IVoiceChannel>(); | return ImmutableArray.Create<IVoiceChannel>(); | ||||
} | } | ||||
async Task<IReadOnlyCollection<IGuildChannelCategory>> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) | |||||
async Task<IReadOnlyCollection<IChannelCategory>> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) | |||||
{ | { | ||||
if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
return await GetChannelCategoriesAsync(options).ConfigureAwait(false); | return await GetChannelCategoriesAsync(options).ConfigureAwait(false); | ||||
@@ -355,6 +357,8 @@ namespace Discord.Rest | |||||
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false); | => await CreateTextChannelAsync(name, options).ConfigureAwait(false); | ||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | ||||
=> await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | ||||
async Task<IChannelCategory> IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) | |||||
=> await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); | |||||
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options) | async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options) | ||||
=> await GetIntegrationsAsync(options).ConfigureAwait(false); | => await GetIntegrationsAsync(options).ConfigureAwait(false); | ||||
@@ -10,7 +10,7 @@ namespace Discord.Rpc | |||||
{ | { | ||||
public ulong GuildId { get; } | public ulong GuildId { get; } | ||||
public int Position { get; private set; } | 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) | internal RpcGuildChannel(DiscordRpcClient discord, ulong id, ulong guildId) | ||||
: base(discord, id) | : base(discord, id) | ||||
@@ -58,7 +58,7 @@ namespace Discord.Rpc | |||||
public override string ToString() => Name; | public override string ToString() => Name; | ||||
//IGuildChannel | //IGuildChannel | ||||
public Task<IGuildChannel> GetParentChannelAsync() | |||||
public Task<IChannelCategory> GetCategory() | |||||
{ | { | ||||
//Always fails | //Always fails | ||||
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); | throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); | ||||
@@ -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<SocketGuildUser> 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<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
//IChannel | |||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
} | |||||
} |
@@ -17,9 +17,9 @@ namespace Discord.WebSocket | |||||
public SocketGuild Guild { get; } | public SocketGuild Guild { get; } | ||||
public string Name { get; private set; } | public string Name { get; private set; } | ||||
public int Position { 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<IGuildChannel> GetParentChannelAsync() => Task.FromResult(ParentChannel); | |||||
public ulong? CategoryId { get; private set; } | |||||
public IChannelCategory Category => CategoryId == null ? null : Guild.GetChannel(CategoryId.Value) as IChannelCategory; | |||||
Task<IChannelCategory> IGuildChannel.GetCategory() => Task.FromResult(Category); | |||||
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites; | public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites; | ||||
public new virtual IReadOnlyCollection<SocketGuildUser> Users => ImmutableArray.Create<SocketGuildUser>(); | public new virtual IReadOnlyCollection<SocketGuildUser> Users => ImmutableArray.Create<SocketGuildUser>(); | ||||
@@ -38,7 +38,7 @@ namespace Discord.WebSocket | |||||
case ChannelType.Voice: | case ChannelType.Voice: | ||||
return SocketVoiceChannel.Create(guild, state, model); | return SocketVoiceChannel.Create(guild, state, model); | ||||
case ChannelType.Category: | case ChannelType.Category: | ||||
return SocketGuildChannelCategory.Create(guild, state, model); | |||||
return SocketChannelCategory.Create(guild, state, model); | |||||
default: | default: | ||||
// TODO: Proper implementation for channel categories | // TODO: Proper implementation for channel categories | ||||
return new SocketGuildChannel(guild.Discord, model.Id, guild); | return new SocketGuildChannel(guild.Discord, model.Id, guild); | ||||
@@ -48,7 +48,7 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
Name = model.Name.Value; | Name = model.Name.Value; | ||||
Position = model.Position.Value; | Position = model.Position.Value; | ||||
ParentId = model.ParentId; | |||||
CategoryId = model.CategoryId; | |||||
var overwrites = model.PermissionOverwrites.Value; | var overwrites = model.PermissionOverwrites.Value; | ||||
var newOverwrites = ImmutableArray.CreateBuilder<Overwrite>(overwrites.Length); | var newOverwrites = ImmutableArray.CreateBuilder<Overwrite>(overwrites.Length); | ||||
@@ -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<SocketGuildUser> 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; | |||||
} | |||||
} |
@@ -94,8 +94,8 @@ namespace Discord.WebSocket | |||||
=> Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); | => Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); | ||||
public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels | public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels | ||||
=> Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); | => Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); | ||||
public IReadOnlyCollection<SocketGuildChannelCategory> ChannelCategories | |||||
=> Channels.Select(x => x as SocketGuildChannelCategory).Where(x => x != null).ToImmutableArray(); | |||||
public IReadOnlyCollection<SocketChannelCategory> 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 SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; | ||||
public SocketRole EveryoneRole => GetRole(Id); | public SocketRole EveryoneRole => GetRole(Id); | ||||
public IReadOnlyCollection<SocketGuildChannel> Channels | public IReadOnlyCollection<SocketGuildChannel> Channels | ||||
@@ -318,6 +318,9 @@ namespace Discord.WebSocket | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | ||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | ||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | ||||
public Task<RestChannelCategory> CreateChannelCategoryAsync(string name, RequestOptions options = null) | |||||
=> GuildHelper.CreateChannelCategoryAsync(this, Discord, name, options); | |||||
internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) | internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) | ||||
{ | { | ||||
var channel = SocketGuildChannel.Create(this, state, model); | var channel = SocketGuildChannel.Create(this, state, model); | ||||
@@ -636,8 +639,8 @@ namespace Discord.WebSocket | |||||
=> Task.FromResult<ITextChannel>(GetTextChannel(id)); | => Task.FromResult<ITextChannel>(GetTextChannel(id)); | ||||
Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) | Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels); | => Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels); | ||||
Task<IReadOnlyCollection<IGuildChannelCategory>> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) | |||||
=> Task.FromResult<IReadOnlyCollection<IGuildChannelCategory>>(ChannelCategories); | |||||
Task<IReadOnlyCollection<IChannelCategory>> IGuild.GetChannelCategoriesAsync(CacheMode mode , RequestOptions options) | |||||
=> Task.FromResult<IReadOnlyCollection<IChannelCategory>>(ChannelCategories); | |||||
Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IVoiceChannel>(GetVoiceChannel(id)); | => Task.FromResult<IVoiceChannel>(GetVoiceChannel(id)); | ||||
Task<IVoiceChannel> IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options) | Task<IVoiceChannel> IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options) | ||||
@@ -652,6 +655,8 @@ namespace Discord.WebSocket | |||||
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false); | => await CreateTextChannelAsync(name, options).ConfigureAwait(false); | ||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | ||||
=> await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | => await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | ||||
async Task<IChannelCategory> IGuild.CreateChannelCategoryAsync(string name, RequestOptions options) | |||||
=> await CreateChannelCategoryAsync(name, options).ConfigureAwait(false); | |||||
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options) | async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options) | ||||
=> await GetIntegrationsAsync(options).ConfigureAwait(false); | => await GetIntegrationsAsync(options).ConfigureAwait(false); | ||||