Merged GuildExtensions into IGuild

This commit is contained in:
RogueException
2017-01-24 11:41:07 -04:00
parent 7ef48c5ce5
commit 158222bb78
4 changed files with 164 additions and 47 deletions

View File

@@ -77,6 +77,13 @@ namespace Discord
Task<IReadOnlyCollection<IGuildChannel>> GetChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets the channel in this guild with the provided id, or null if not found. </summary>
Task<IGuildChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IReadOnlyCollection<ITextChannel>> GetTextChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<ITextChannel> GetTextChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IReadOnlyCollection<IVoiceChannel>> GetVoiceChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IVoiceChannel> GetVoiceChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IVoiceChannel> GetAFKChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<ITextChannel> GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
Task<IVoiceChannel> GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Creates a new text channel. </summary>
Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null);
/// <summary> Creates a new voice channel. </summary>
@@ -99,6 +106,8 @@ namespace Discord
Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets the current user for this guild. </summary>
Task<IGuildUser> GetCurrentUserAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets the owner of this guild. </summary>
Task<IGuildUser> GetOwnerAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Downloads all users for this guild if the current list is incomplete. </summary>
Task DownloadUsersAsync();
/// <summary> Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. </summary>

View File

@@ -1,38 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Discord
{
public static class GuildExtensions
{
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)
{
var afkId = guild.AFKChannelId;
if (afkId.HasValue)
return await guild.GetChannelAsync(afkId.Value).ConfigureAwait(false) as IVoiceChannel;
return null;
}
public static async Task<ITextChannel> GetDefaultChannelAsync(this IGuild guild)
=> await guild.GetChannelAsync(guild.DefaultChannelId).ConfigureAwait(false) as ITextChannel;
public static async Task<IVoiceChannel> GetEmbedChannelAsync(this IGuild guild)
{
var embedId = guild.EmbedChannelId;
if (embedId.HasValue)
return await guild.GetChannelAsync(embedId.Value).ConfigureAwait(false) as IVoiceChannel;
return null;
}
public static async Task<IGuildUser> GetOwnerAsync(this IGuild guild)
=> await guild.GetUserAsync(guild.OwnerId).ConfigureAwait(false);
}
}