diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs index bc521784d..342e57717 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs @@ -6,7 +6,7 @@ using Model = Discord.API.Channel; namespace Discord.Rest { - public abstract class RestChannel : RestEntity, IChannel, IUpdateable + public class RestChannel : RestEntity, IChannel, IUpdateable { public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); @@ -25,7 +25,7 @@ namespace Discord.Rest case ChannelType.Group: return CreatePrivate(discord, model) as RestChannel; default: - throw new InvalidOperationException($"Unexpected channel type: {model.Type}"); + return new RestChannel(discord, model.Id); } } internal static IRestPrivateChannel CreatePrivate(BaseDiscordClient discord, Model model) @@ -40,9 +40,9 @@ namespace Discord.Rest throw new InvalidOperationException($"Unexpected channel type: {model.Type}"); } } - internal abstract void Update(Model model); + internal virtual void Update(Model model) { } - public abstract Task UpdateAsync(RequestOptions options = null); + public virtual Task UpdateAsync(RequestOptions options = null) => Task.Delay(0); //IChannel string IChannel.Name => null; diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 114c886c4..07832a3a9 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -7,7 +7,7 @@ using Model = Discord.API.Channel; namespace Discord.Rest { - public abstract class RestGuildChannel : RestChannel, IGuildChannel, IUpdateable + public class RestGuildChannel : RestChannel, IGuildChannel, IUpdateable { private ImmutableArray _overwrites; @@ -33,7 +33,8 @@ namespace Discord.Rest case ChannelType.Voice: return RestVoiceChannel.Create(discord, guild, model); default: - throw new InvalidOperationException("Unknown guild channel type"); + // TODO: Channel categories + return new RestGuildChannel(discord, guild, model.Id); } } internal override void Update(Model model) diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 0e7cfde82..1fe9a741f 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -10,7 +10,7 @@ using Model = Discord.API.Channel; namespace Discord.WebSocket { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] - public abstract class SocketGuildChannel : SocketChannel, IGuildChannel + public class SocketGuildChannel : SocketChannel, IGuildChannel { private ImmutableArray _overwrites; @@ -19,7 +19,7 @@ namespace Discord.WebSocket public int Position { get; private set; } public IReadOnlyCollection PermissionOverwrites => _overwrites; - public new abstract IReadOnlyCollection Users { get; } + public new virtual IReadOnlyCollection Users => ImmutableArray.Create(); internal SocketGuildChannel(DiscordSocketClient discord, ulong id, SocketGuild guild) : base(discord, id) @@ -35,7 +35,8 @@ namespace Discord.WebSocket case ChannelType.Voice: return SocketVoiceChannel.Create(guild, state, model); default: - throw new InvalidOperationException("Unknown guild channel type"); + // TODO: Proper implementation for channel categories + return new SocketGuildChannel(guild.Discord, model.Id, guild); } } internal override void Update(ClientState state, Model model) @@ -49,7 +50,7 @@ namespace Discord.WebSocket newOverwrites.Add(overwrites[i].ToEntity()); _overwrites = newOverwrites.ToImmutable(); } - + public Task ModifyAsync(Action func, RequestOptions options = null) => ChannelHelper.ModifyAsync(this, Discord, func, options); public Task DeleteAsync(RequestOptions options = null) @@ -115,7 +116,7 @@ namespace Discord.WebSocket public async Task CreateInviteAsync(int? maxAge = 3600, 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 new abstract SocketGuildUser GetUser(ulong id); + public new virtual SocketGuildUser GetUser(ulong id) => null; public override string ToString() => Name; internal new SocketGuildChannel Clone() => MemberwiseClone() as SocketGuildChannel; @@ -145,7 +146,7 @@ namespace Discord.WebSocket => await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false); async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) => await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false); - + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)