Browse Source

Fixed SO in RestChannel.Create

tags/1.0-rc
RogueException 8 years ago
parent
commit
8b24b01718
2 changed files with 33 additions and 18 deletions
  1. +1
    -2
      src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
  2. +32
    -16
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs

+ 1
- 2
src/Discord.Net.Rest/Entities/Channels/RestChannel.cs View File

@@ -17,9 +17,8 @@ namespace Discord.Rest
switch (model.Type)
{
case ChannelType.Text:
return RestTextChannel.Create(discord, model);
case ChannelType.Voice:
return RestVoiceChannel.Create(discord, model);
return RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model);
case ChannelType.DM:
case ChannelType.Group:
return CreatePrivate(discord, model) as RestChannel;


+ 32
- 16
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -72,22 +72,6 @@ namespace Discord.Rest

private string DebuggerDisplay => $"{Name} ({Id}, Text)";

//IGuildChannel
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetUserAsync(id, options).ConfigureAwait(false);
else
return null;
}
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetUsersAsync(options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overriden
}

//IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
@@ -128,5 +112,37 @@ namespace Discord.Rest
=> await SendMessageAsync(text, isTTS, options).ConfigureAwait(false);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);

//IGuildChannel
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetUserAsync(id, options).ConfigureAwait(false);
else
return null;
}
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetUsersAsync(options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
}

//IChannel
async Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetUserAsync(id, options).ConfigureAwait(false);
else
return null;
}
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetUsersAsync(options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
}
}
}

Loading…
Cancel
Save