Fixed crash, added DM/Group channel helpers

This commit is contained in:
RogueException
2017-02-07 21:10:30 -04:00
parent d9fd0c34e4
commit 0cf5493c61
5 changed files with 49 additions and 3 deletions

View File

@@ -134,6 +134,10 @@ namespace Discord.Rest
=> Task.FromResult<IChannel>(null);
Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode)
=> Task.FromResult<IReadOnlyCollection<IPrivateChannel>>(ImmutableArray.Create<IPrivateChannel>());
Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode)
=> Task.FromResult<IReadOnlyCollection<IDMChannel>>(ImmutableArray.Create<IDMChannel>());
Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode)
=> Task.FromResult<IReadOnlyCollection<IGroupChannel>>(ImmutableArray.Create<IGroupChannel>());
Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync()
=> Task.FromResult<IReadOnlyCollection<IConnection>>(ImmutableArray.Create<IConnection>());

View File

@@ -24,10 +24,24 @@ namespace Discord.Rest
return RestChannel.Create(client, model);
return null;
}
public static async Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(BaseDiscordClient client)
public static async Task<IReadOnlyCollection<IRestPrivateChannel>> GetPrivateChannelsAsync(BaseDiscordClient client)
{
var models = await client.ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false);
return models.Select(x => RestDMChannel.Create(client, x)).ToImmutableArray();
return models.Select(x => RestChannel.CreatePrivate(client, x)).ToImmutableArray();
}
public static async Task<IReadOnlyCollection<RestDMChannel>> GetDMChannelsAsync(BaseDiscordClient client)
{
var models = await client.ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false);
return models
.Where(x => x.Type == ChannelType.DM)
.Select(x => RestDMChannel.Create(client, x)).ToImmutableArray();
}
public static async Task<IReadOnlyCollection<RestGroupChannel>> GetGroupChannelsAsync(BaseDiscordClient client)
{
var models = await client.ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false);
return models
.Where(x => x.Type == ChannelType.Group)
.Select(x => RestGroupChannel.Create(client, x)).ToImmutableArray();
}
public static async Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync(BaseDiscordClient client)

View File

@@ -39,8 +39,12 @@ namespace Discord.Rest
public Task<RestChannel> GetChannelAsync(ulong id)
=> ClientHelper.GetChannelAsync(this, id);
/// <inheritdoc />
public Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync()
public Task<IReadOnlyCollection<IRestPrivateChannel>> GetPrivateChannelsAsync()
=> ClientHelper.GetPrivateChannelsAsync(this);
public Task<IReadOnlyCollection<RestDMChannel>> GetDMChannelsAsync()
=> ClientHelper.GetDMChannelsAsync(this);
public Task<IReadOnlyCollection<RestGroupChannel>> GetGroupChannelsAsync()
=> ClientHelper.GetGroupChannelsAsync(this);
/// <inheritdoc />
public Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync()
@@ -98,6 +102,20 @@ namespace Discord.Rest
else
return ImmutableArray.Create<IPrivateChannel>();
}
async Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode)
{
if (mode == CacheMode.AllowDownload)
return await GetDMChannelsAsync().ConfigureAwait(false);
else
return ImmutableArray.Create<IDMChannel>();
}
async Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode)
{
if (mode == CacheMode.AllowDownload)
return await GetGroupChannelsAsync().ConfigureAwait(false);
else
return ImmutableArray.Create<IGroupChannel>();
}
async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync()
=> await GetConnectionsAsync().ConfigureAwait(false);