@@ -17,6 +17,8 @@ namespace Discord | |||
Task<IChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); | |||
Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(CacheMode mode = CacheMode.AllowDownload); | |||
Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(CacheMode mode = CacheMode.AllowDownload); | |||
Task<IReadOnlyCollection<IGroupChannel>> GetGroupChannelsAsync(CacheMode mode = CacheMode.AllowDownload); | |||
Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync(); | |||
@@ -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); | |||
@@ -68,6 +68,10 @@ namespace Discord.WebSocket | |||
public new SocketSelfUser CurrentUser { get { return base.CurrentUser as SocketSelfUser; } private set { base.CurrentUser = value; } } | |||
public IReadOnlyCollection<SocketGuild> Guilds => State.Guilds; | |||
public IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => State.PrivateChannels; | |||
public IReadOnlyCollection<SocketDMChannel> DMChannels | |||
=> State.PrivateChannels.Select(x => x as SocketDMChannel).Where(x => x != null).ToImmutableArray(); | |||
public IReadOnlyCollection<SocketGroupChannel> GroupChannels | |||
=> State.PrivateChannels.Select(x => x as SocketGroupChannel).Where(x => x != null).ToImmutableArray(); | |||
public IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _voiceRegions.ToReadOnlyCollection(); | |||
/// <summary> Creates a new REST/WebSocket discord client. </summary> | |||
@@ -1803,6 +1807,10 @@ namespace Discord.WebSocket | |||
=> Task.FromResult<IChannel>(GetChannel(id)); | |||
Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) | |||
=> Task.FromResult<IReadOnlyCollection<IPrivateChannel>>(PrivateChannels); | |||
Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode) | |||
=> Task.FromResult<IReadOnlyCollection<IDMChannel>>(DMChannels); | |||
Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode) | |||
=> Task.FromResult<IReadOnlyCollection<IGroupChannel>>(GroupChannels); | |||
async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync() | |||
=> await GetConnectionsAsync().ConfigureAwait(false); | |||