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 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> GetInvitesAsync(RequestOptions options = null) => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); public async Task 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 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> IGuildChannel.GetInvitesAsync(RequestOptions options) => 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); IReadOnlyCollection IGuildChannel.PermissionOverwrites { get { throw new NotSupportedException(); } } OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) { throw new NotSupportedException(); } OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) { throw new NotSupportedException(); } IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) { throw new NotSupportedException(); } Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, 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(); } } }