@@ -1,4 +1,4 @@ | |||
using Discord.Rest; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
@@ -6,7 +6,20 @@ namespace Discord | |||
{ | |||
public static class DiscordClientExtensions | |||
{ | |||
public static async Task<IVoiceRegion> GetOptimalVoiceRegionAsync(this DiscordRestClient discord) | |||
public static async Task<IPrivateChannel> GetPrivateChannelAsync(this IDiscordClient client, ulong id) | |||
=> await client.GetChannelAsync(id).ConfigureAwait(false) as IPrivateChannel; | |||
public static async Task<IDMChannel> GetDMChannelAsync(this IDiscordClient client, ulong id) | |||
=> await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IDMChannel; | |||
public static async Task<IEnumerable<IDMChannel>> GetDMChannelsAsync(this IDiscordClient client, ulong id) | |||
=> (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).Select(x => x as IDMChannel).Where(x => x != null); | |||
public static async Task<IGroupChannel> GetGroupChannelAsync(this IDiscordClient client, ulong id) | |||
=> await client.GetPrivateChannelAsync(id).ConfigureAwait(false) as IGroupChannel; | |||
public static async Task<IEnumerable<IGroupChannel>> GetGroupChannelsAsync(this IDiscordClient client, ulong id) | |||
=> (await client.GetPrivateChannelsAsync().ConfigureAwait(false)).Select(x => x as IGroupChannel).Where(x => x != null); | |||
public static async Task<IVoiceRegion> GetOptimalVoiceRegionAsync(this IDiscordClient discord) | |||
{ | |||
var regions = await discord.GetVoiceRegionsAsync().ConfigureAwait(false); | |||
return regions.FirstOrDefault(x => x.IsOptimal); | |||
@@ -1,4 +1,6 @@ | |||
using System.Threading.Tasks; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Discord | |||
{ | |||
@@ -6,8 +8,13 @@ namespace Discord | |||
{ | |||
public static async Task<ITextChannel> GetTextChannelAsync(this IGuild guild, ulong id) | |||
=> await guild.GetChannelAsync(id).ConfigureAwait(false) as ITextChannel; | |||
public static async Task<IEnumerable<ITextChannel>> GetTextChannelsAsync(this IGuild guild) | |||
=> (await guild.GetChannelsAsync().ConfigureAwait(false)).Select(x => x as ITextChannel).Where(x => x != null); | |||
public static async Task<IVoiceChannel> GetVoiceChannelAsync(this IGuild guild, ulong id) | |||
=> await guild.GetChannelAsync(id).ConfigureAwait(false) as IVoiceChannel; | |||
public static async Task<IEnumerable<IVoiceChannel>> GetVoiceChannelsAsync(this IGuild guild) | |||
=> (await guild.GetChannelsAsync().ConfigureAwait(false)).Select(x => x as IVoiceChannel).Where(x => x != null); | |||
public static async Task<IVoiceChannel> GetAFKChannelAsync(this IGuild guild) | |||
{ | |||
@@ -3,43 +3,49 @@ using System.Linq; | |||
namespace Discord.WebSocket | |||
{ | |||
public static class SocketClientExtensions | |||
public static class DiscordClientExtensions | |||
{ | |||
public static IPrivateChannel GetPrivateChannel(this DiscordSocketClient client, ulong id) | |||
=> client.GetChannel(id) as IPrivateChannel; | |||
public static IDMChannel GetDMChannel(this DiscordSocketClient client, ulong id) | |||
=> client.GetPrivateChannelAsync(id) as IDMChannel; | |||
public static IEnumerable<IDMChannel> GetDMChannels(this DiscordSocketClient client, ulong id) | |||
=> client.GetPrivateChannels().Select(x => x as IDMChannel).Where(x => x != null); | |||
public static IGroupChannel GetGroupChannel(this DiscordSocketClient client, ulong id) | |||
=> client.GetPrivateChannel(id) as IGroupChannel; | |||
public static IEnumerable<IGroupChannel> GetGroupChannels(this DiscordSocketClient client, ulong id) | |||
=> client.GetPrivateChannels().Select(x => x as IGroupChannel).Where(x => x != null); | |||
public static IVoiceRegion GetVoiceRegion(this DiscordSocketClient client, string id) | |||
{ | |||
var region = client.VoiceRegions.FirstOrDefault(r => r.Id == id); | |||
return region; | |||
} | |||
=> client.VoiceRegions.FirstOrDefault(r => r.Id == id); | |||
public static IReadOnlyCollection<IVoiceRegion> GetVoiceRegions(this DiscordSocketClient client) => | |||
client.VoiceRegions; | |||
public static IVoiceRegion GetOptimalVoiceRegion(this DiscordSocketClient client) | |||
=> client.VoiceRegions.FirstOrDefault(x => x.IsOptimal); | |||
public static IGuild GetGuild(this DiscordSocketClient client, ulong id) => | |||
client.DataStore.GetGuild(id); | |||
public static GuildEmbed? GetGuildEmbed(this DiscordSocketClient client, ulong id) | |||
{ | |||
var guild = client.DataStore.GetGuild(id); | |||
if (guild != null) | |||
return new GuildEmbed(guild.IsEmbeddable, guild.EmbedChannelId); | |||
return null; | |||
} | |||
} | |||
public static IReadOnlyCollection<IGuild> GetGuilds(this DiscordSocketClient client) => | |||
client.Guilds; | |||
public static IChannel GetChannel(this DiscordSocketClient client, ulong id) => | |||
client.DataStore.GetChannel(id); | |||
public static IReadOnlyCollection<IPrivateChannel> GetPrivateChannels(this DiscordSocketClient client) => | |||
client.DataStore.PrivateChannels; | |||
public static IUser GetUser(this DiscordSocketClient client, ulong id) => | |||
client.DataStore.GetUser(id); | |||
public static IUser GetUser(this DiscordSocketClient client, string username, string discriminator) => | |||
client.DataStore.Users.Where(x => x.Discriminator == discriminator && x.Username == username).FirstOrDefault(); | |||
public static ISelfUser GetCurrentUser(this DiscordSocketClient client) => | |||
client.CurrentUser; | |||
@@ -8,31 +8,25 @@ namespace Discord.WebSocket | |||
public static class GuildExtensions | |||
{ | |||
// Channels | |||
public static IGuildChannel GetChannel(this IGuild guild, ulong id) => | |||
GetSocketGuild(guild).GetChannel(id); | |||
public static IReadOnlyCollection<IGuildChannel> GetChannels(this IGuild guild) => | |||
GetSocketGuild(guild).Channels; | |||
public static ITextChannel GetTextChannel(this IGuild guild, ulong id) => | |||
GetSocketGuild(guild).GetChannel(id) as ITextChannel; | |||
public static IEnumerable<ITextChannel> GetTextChannels(this IGuild guild) => | |||
GetSocketGuild(guild).Channels.Select(c => c as ITextChannel).Where(c => c != null); | |||
public static IVoiceChannel GetVoiceChannel(this IGuild guild, ulong id) => | |||
GetSocketGuild(guild).GetChannel(id) as IVoiceChannel; | |||
public static IEnumerable<IVoiceChannel> GetVoiceChannels(this IGuild guild) => | |||
GetSocketGuild(guild).Channels.Select(c => c as IVoiceChannel).Where(c => c != null); | |||
// Users | |||
public static IGuildUser GetCurrentUser(this IGuild guild) => | |||
GetSocketGuild(guild).CurrentUser; | |||
public static IGuildUser GetUser(this IGuild guild, ulong id) => | |||
GetSocketGuild(guild).GetUser(id); | |||
@@ -41,10 +35,10 @@ namespace Discord.WebSocket | |||
public static int GetUserCount(this IGuild guild) => | |||
GetSocketGuild(guild).MemberCount; | |||
public static int GetCachedUserCount(this IGuild guild) => | |||
GetSocketGuild(guild).DownloadedMemberCount; | |||
//Helpers | |||
internal static SocketGuild GetSocketGuild(IGuild guild) | |||
{ | |||
var socketGuild = guild as SocketGuild; | |||