Fixed crash, added DM/Group channel helpers
This commit is contained in:
@@ -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>());
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user