Files
Discord.Net/experiment/Discord.Net.Rpc/Entities/Channels/RpcGuildChannel.cs
Christopher F 030422fa1d 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)
2018-01-06 22:27:51 -05:00

110 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Model = Discord.API.Rpc.Channel;
using Discord.Rest;
namespace Discord.Rpc
{
public class RpcGuildChannel : RpcChannel, IGuildChannel
{
public ulong GuildId { get; }
public int Position { get; private set; }
public ulong? CategoryId { get; private set; }
internal RpcGuildChannel(DiscordRpcClient discord, ulong id, ulong guildId)
: base(discord, id)
{
GuildId = guildId;
}
internal new static RpcGuildChannel Create(DiscordRpcClient discord, Model model)
{
switch (model.Type)
{
case ChannelType.Text:
return RpcTextChannel.Create(discord, model);
case ChannelType.Voice:
return RpcVoiceChannel.Create(discord, model);
default:
throw new InvalidOperationException("Unknown guild channel type");
}
}
internal override void Update(Model model)
{
base.Update(model);
if (model.Position.IsSpecified)
Position = model.Position.Value;
}
public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
public Task DeleteAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);
public Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
=> ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options);
public Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
=> ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options);
public Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
=> ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options);
public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
=> ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options);
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
public override string ToString() => Name;
//IGuildChannel
public Task<ICategoryChannel> GetCategoryAsync()
{
//Always fails
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
}
IGuild IGuildChannel.Guild
{
get
{
//Always fails
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
}
}
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)
=> await CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
IReadOnlyCollection<Overwrite> IGuildChannel.PermissionOverwrites { get { throw new NotSupportedException(); } }
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
{
throw new NotSupportedException();
}
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
{
throw new NotSupportedException();
}
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();
}
//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();
}
}
}