@@ -12,12 +12,12 @@ namespace Discord | |||||
public static async Task<IDMChannel> GetDMChannelAsync(this IDiscordClient client, ulong id) | public static async Task<IDMChannel> GetDMChannelAsync(this IDiscordClient client, ulong id) | ||||
=> await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IDMChannel; | => await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IDMChannel; | ||||
public static async Task<IEnumerable<IDMChannel>> GetDMChannelsAsync(this IDiscordClient client) | public static async Task<IEnumerable<IDMChannel>> GetDMChannelsAsync(this IDiscordClient client) | ||||
=> (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).Select(x => x as IDMChannel).Where(x => x != null); | |||||
=> (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).OfType<IDMChannel>(); | |||||
public static async Task<IGroupChannel> GetGroupChannelAsync(this IDiscordClient client, ulong id) | public static async Task<IGroupChannel> GetGroupChannelAsync(this IDiscordClient client, ulong id) | ||||
=> await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IGroupChannel; | => await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IGroupChannel; | ||||
public static async Task<IEnumerable<IGroupChannel>> GetGroupChannelsAsync(this IDiscordClient client) | public static async Task<IEnumerable<IGroupChannel>> GetGroupChannelsAsync(this IDiscordClient client) | ||||
=> (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).Select(x => x as IGroupChannel).Where(x => x != null); | |||||
=> (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).OfType<IGroupChannel>(); | |||||
public static async Task<IVoiceRegion> GetOptimalVoiceRegionAsync(this IDiscordClient discord) | public static async Task<IVoiceRegion> GetOptimalVoiceRegionAsync(this IDiscordClient discord) | ||||
{ | { | ||||
@@ -168,7 +168,7 @@ namespace Discord.Rest | |||||
public async Task<IReadOnlyCollection<RestTextChannel>> GetTextChannelsAsync(RequestOptions options = null) | public async Task<IReadOnlyCollection<RestTextChannel>> GetTextChannelsAsync(RequestOptions options = null) | ||||
{ | { | ||||
var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | ||||
return channels.Select(x => x as RestTextChannel).Where(x => x != null).ToImmutableArray(); | |||||
return channels.OfType<RestTextChannel>().ToImmutableArray(); | |||||
} | } | ||||
public async Task<RestVoiceChannel> GetVoiceChannelAsync(ulong id, RequestOptions options = null) | public async Task<RestVoiceChannel> GetVoiceChannelAsync(ulong id, RequestOptions options = null) | ||||
{ | { | ||||
@@ -178,12 +178,12 @@ namespace Discord.Rest | |||||
public async Task<IReadOnlyCollection<RestVoiceChannel>> GetVoiceChannelsAsync(RequestOptions options = null) | public async Task<IReadOnlyCollection<RestVoiceChannel>> GetVoiceChannelsAsync(RequestOptions options = null) | ||||
{ | { | ||||
var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | ||||
return channels.Select(x => x as RestVoiceChannel).Where(x => x != null).ToImmutableArray(); | |||||
return channels.OfType<RestVoiceChannel>().ToImmutableArray(); | |||||
} | } | ||||
public async Task<IReadOnlyCollection<RestCategoryChannel>> GetCategoryChannelsAsync(RequestOptions options = null) | public async Task<IReadOnlyCollection<RestCategoryChannel>> GetCategoryChannelsAsync(RequestOptions options = null) | ||||
{ | { | ||||
var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | var channels = await GuildHelper.GetChannelsAsync(this, Discord, options).ConfigureAwait(false); | ||||
return channels.Select(x => x as RestCategoryChannel).Where(x => x != null).ToImmutableArray(); | |||||
return channels.OfType<RestCategoryChannel>().ToImmutableArray(); | |||||
} | } | ||||
public async Task<RestVoiceChannel> GetAFKChannelAsync(RequestOptions options = null) | public async Task<RestVoiceChannel> GetAFKChannelAsync(RequestOptions options = null) | ||||
@@ -63,9 +63,9 @@ namespace Discord.WebSocket | |||||
public override IReadOnlyCollection<SocketGuild> Guilds => State.Guilds; | public override IReadOnlyCollection<SocketGuild> Guilds => State.Guilds; | ||||
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => State.PrivateChannels; | public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => State.PrivateChannels; | ||||
public IReadOnlyCollection<SocketDMChannel> DMChannels | public IReadOnlyCollection<SocketDMChannel> DMChannels | ||||
=> State.PrivateChannels.Select(x => x as SocketDMChannel).Where(x => x != null).ToImmutableArray(); | |||||
=> State.PrivateChannels.OfType<SocketDMChannel>().ToImmutableArray(); | |||||
public IReadOnlyCollection<SocketGroupChannel> GroupChannels | public IReadOnlyCollection<SocketGroupChannel> GroupChannels | ||||
=> State.PrivateChannels.Select(x => x as SocketGroupChannel).Where(x => x != null).ToImmutableArray(); | |||||
=> State.PrivateChannels.OfType<SocketGroupChannel>().ToImmutableArray(); | |||||
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _voiceRegions.ToReadOnlyCollection(); | public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _voiceRegions.ToReadOnlyCollection(); | ||||
/// <summary> Creates a new REST/WebSocket discord client. </summary> | /// <summary> Creates a new REST/WebSocket discord client. </summary> | ||||
@@ -91,11 +91,11 @@ namespace Discord.WebSocket | |||||
} | } | ||||
} | } | ||||
public IReadOnlyCollection<SocketTextChannel> TextChannels | public IReadOnlyCollection<SocketTextChannel> TextChannels | ||||
=> Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray(); | |||||
=> Channels.OfType<SocketTextChannel>().ToImmutableArray(); | |||||
public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels | public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels | ||||
=> Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray(); | |||||
=> Channels.OfType<SocketVoiceChannel>().ToImmutableArray(); | |||||
public IReadOnlyCollection<SocketCategoryChannel> CategoryChannels | public IReadOnlyCollection<SocketCategoryChannel> CategoryChannels | ||||
=> Channels.Select(x => x as SocketCategoryChannel).Where(x => x != null).ToImmutableArray(); | |||||
=> Channels.OfType<SocketCategoryChannel>().ToImmutableArray(); | |||||
public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; | public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; | ||||
public SocketRole EveryoneRole => GetRole(Id); | public SocketRole EveryoneRole => GetRole(Id); | ||||
public IReadOnlyCollection<SocketGuildChannel> Channels | public IReadOnlyCollection<SocketGuildChannel> Channels | ||||