Add support for channel categories (#907)
commit a85c5814a74e473e95fe172f0379cbc7f9f951d8
Author: Christopher F <computerizedtaco@gmail.com>
Date: Sat Jan 6 22:25:48 2018 -0500
Code cleanup
commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1
Author: Christopher F <computerizedtaco@gmail.com>
Date: Sat Jan 6 22:08:28 2018 -0500
Add support for channel categories (#907)
commit 41ed9106f2b05530acbf06b245c9aa618011d815
Author: mrspits4ever <spits.lucas@gmail.com>
Date: Thu Dec 14 20:02:57 2017 +0100
removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel
commit 71142c310847886dff80c49e9357dd0786d67a1b
Merge: 4589d731 678a7238
Author: mrspits4ever <spits.lucas@gmail.com>
Date: Wed Dec 13 21:17:53 2017 +0100
Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories
commit 4589d73187871c98485ed25c6d223706927af7ec
Author: mrspits4ever <spits.lucas@gmail.com>
Date: Wed Dec 13 21:17:46 2017 +0100
adressed requested changes
commit d59b038efa048b2279602e2015ddd2c185e58d63
Author: pegasy <pegasy@users.noreply.github.com>
Date: Mon Sep 25 18:53:23 2017 +0200
Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named.
commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f
Author: pegasy <pegasy@users.noreply.github.com>
Date: Sun Sep 24 19:08:25 2017 +0200
removed Guild from class name for ChannelCategory
Renamed all properties to use Category instead of Parent
Throw exception on GetUsers / GetInvites etc for categories
commit e18bd8c799d2327270021c05866cb2e97ad4671b
Author: pegasy <pegasy@users.noreply.github.com>
Date: Sun Sep 24 15:49:51 2017 +0200
Add support for channel categories (as its own channel type)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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 SocketCategoryChannel : SocketGuildChannel, ICategoryChannel
|
||||
{
|
||||
public override IReadOnlyCollection<SocketGuildUser> Users
|
||||
=> Guild.Users.Where(x => x.VoiceChannel?.Id == Id).ToImmutableArray();
|
||||
|
||||
public IReadOnlyCollection<SocketGuildChannel> Channels
|
||||
=> Guild.Channels.Where(x => x.CategoryId == CategoryId).ToImmutableArray();
|
||||
|
||||
internal SocketCategoryChannel(DiscordSocketClient discord, ulong id, SocketGuild guild)
|
||||
: base(discord, id, guild)
|
||||
{
|
||||
}
|
||||
internal new static SocketCategoryChannel Create(SocketGuild guild, ClientState state, Model model)
|
||||
{
|
||||
var entity = new SocketCategoryChannel(guild.Discord, model.Id, guild);
|
||||
entity.Update(state, model);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Id}, Category)";
|
||||
internal new SocketCategoryChannel Clone() => MemberwiseClone() as SocketCategoryChannel;
|
||||
|
||||
// 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,6 +17,9 @@ namespace Discord.WebSocket
|
||||
public SocketGuild Guild { get; }
|
||||
public string Name { get; private set; }
|
||||
public int Position { get; private set; }
|
||||
public ulong? CategoryId { get; private set; }
|
||||
public ICategoryChannel Category
|
||||
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
|
||||
|
||||
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
|
||||
public new virtual IReadOnlyCollection<SocketGuildUser> Users => ImmutableArray.Create<SocketGuildUser>();
|
||||
@@ -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 SocketCategoryChannel.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;
|
||||
CategoryId = model.CategoryId;
|
||||
|
||||
var overwrites = model.PermissionOverwrites.Value;
|
||||
var newOverwrites = ImmutableArray.CreateBuilder<Overwrite>(overwrites.Length);
|
||||
@@ -129,6 +135,9 @@ namespace Discord.WebSocket
|
||||
IGuild IGuildChannel.Guild => Guild;
|
||||
ulong IGuildChannel.GuildId => Guild.Id;
|
||||
|
||||
Task<ICategoryChannel> IGuildChannel.GetCategoryAsync()
|
||||
=> Task.FromResult(Category);
|
||||
|
||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options)
|
||||
=> await GetInvitesAsync(options).ConfigureAwait(false);
|
||||
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Discord.WebSocket
|
||||
return id.HasValue ? GetVoiceChannel(id.Value) : null;
|
||||
}
|
||||
}
|
||||
public SocketGuildChannel EmbedChannel
|
||||
public SocketGuildChannel EmbedChannel
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -95,6 +95,8 @@ namespace Discord.WebSocket
|
||||
=> Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray();
|
||||
public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels
|
||||
=> Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray();
|
||||
public IReadOnlyCollection<SocketCategoryChannel> 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<SocketGuildChannel> Channels
|
||||
@@ -317,6 +319,9 @@ namespace Discord.WebSocket
|
||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options);
|
||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null)
|
||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options);
|
||||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null)
|
||||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options);
|
||||
|
||||
internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model)
|
||||
{
|
||||
var channel = SocketGuildChannel.Create(this, state, model);
|
||||
@@ -348,7 +353,7 @@ namespace Discord.WebSocket
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
public Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
|
||||
public Task<RestRole> 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)
|
||||
@@ -594,7 +599,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)
|
||||
{
|
||||
@@ -651,6 +656,8 @@ namespace Discord.WebSocket
|
||||
=> Task.FromResult<ITextChannel>(GetTextChannel(id));
|
||||
Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels);
|
||||
Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode , RequestOptions options)
|
||||
=> Task.FromResult<IReadOnlyCollection<ICategoryChannel>>(CategoryChannels);
|
||||
Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IVoiceChannel>(GetVoiceChannel(id));
|
||||
Task<IVoiceChannel> IGuild.GetAFKChannelAsync(CacheMode mode, RequestOptions options)
|
||||
@@ -665,6 +672,8 @@ namespace Discord.WebSocket
|
||||
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false);
|
||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options)
|
||||
=> await CreateVoiceChannelAsync(name, options).ConfigureAwait(false);
|
||||
async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options)
|
||||
=> await CreateCategoryChannelAsync(name, options).ConfigureAwait(false);
|
||||
|
||||
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
|
||||
=> await GetIntegrationsAsync(options).ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user