* Move invites-related methods from IGuildChannel to INestedChannel * Add missing implementation ...because I somehow forgot it the first time aroundpull/1204/head
@@ -45,45 +45,6 @@ namespace Discord | |||||
IReadOnlyCollection<Overwrite> PermissionOverwrites { get; } | IReadOnlyCollection<Overwrite> PermissionOverwrites { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Creates a new invite to this channel. | |||||
/// </summary> | |||||
/// <example> | |||||
/// The following example creates a new invite to this channel; the invite lasts for 12 hours and can only | |||||
/// be used 3 times throughout its lifespan. | |||||
/// <code language="cs"> | |||||
/// await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3); | |||||
/// </code> | |||||
/// </example> | |||||
/// <param name="maxAge">The time (in seconds) until the invite expires. Set to <c>null</c> to never expire.</param> | |||||
/// <param name="maxUses">The max amount of times this invite may be used. Set to <c>null</c> to have unlimited uses.</param> | |||||
/// <param name="isTemporary">If <c>true</c>, the user accepting this invite will be kicked from the guild after closing their client.</param> | |||||
/// <param name="isUnique">If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use invites).</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous invite creation operation. The task result contains an invite | |||||
/// metadata object containing information for the created invite. | |||||
/// </returns> | |||||
Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); | |||||
/// <summary> | |||||
/// Gets a collection of all invites to this channel. | |||||
/// </summary> | |||||
/// <example> | |||||
/// The following example gets all of the invites that have been created in this channel and selects the | |||||
/// most used invite. | |||||
/// <code language="cs"> | |||||
/// var invites = await channel.GetInvitesAsync(); | |||||
/// if (invites.Count == 0) return; | |||||
/// var invite = invites.OrderByDescending(x => x.Uses).FirstOrDefault(); | |||||
/// </code> | |||||
/// </example> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection | |||||
/// of invite metadata that are created for this channel. | |||||
/// </returns> | |||||
Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null); | |||||
/// <summary> | |||||
/// Modifies this guild channel. | /// Modifies this guild channel. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="func">The delegate containing the properties to modify the channel with.</param> | /// <param name="func">The delegate containing the properties to modify the channel with.</param> | ||||
@@ -1,3 +1,4 @@ | |||||
using System.Collections.Generic; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
@@ -25,10 +26,49 @@ namespace Discord | |||||
/// representing the parent of this channel; <c>null</c> if none is set. | /// representing the parent of this channel; <c>null</c> if none is set. | ||||
/// </returns> | /// </returns> | ||||
Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
/// <summary> | /// <summary> | ||||
/// Syncs the permissions of this nested channel with its parent's. | /// Syncs the permissions of this nested channel with its parent's. | ||||
/// </summary> | /// </summary> | ||||
Task SyncPermissionsAsync(RequestOptions options = null); | Task SyncPermissionsAsync(RequestOptions options = null); | ||||
/// <summary> | |||||
/// Creates a new invite to this channel. | |||||
/// </summary> | |||||
/// <example> | |||||
/// The following example creates a new invite to this channel; the invite lasts for 12 hours and can only | |||||
/// be used 3 times throughout its lifespan. | |||||
/// <code language="cs"> | |||||
/// await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3); | |||||
/// </code> | |||||
/// </example> | |||||
/// <param name="maxAge">The time (in seconds) until the invite expires. Set to <c>null</c> to never expire.</param> | |||||
/// <param name="maxUses">The max amount of times this invite may be used. Set to <c>null</c> to have unlimited uses.</param> | |||||
/// <param name="isTemporary">If <c>true</c>, the user accepting this invite will be kicked from the guild after closing their client.</param> | |||||
/// <param name="isUnique">If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use invites).</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous invite creation operation. The task result contains an invite | |||||
/// metadata object containing information for the created invite. | |||||
/// </returns> | |||||
Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); | |||||
/// <summary> | |||||
/// Gets a collection of all invites to this channel. | |||||
/// </summary>B | |||||
/// <example> | |||||
/// The following example gets all of the invites that have been created in this channel and selects the | |||||
/// most used invite. | |||||
/// <code language="cs"> | |||||
/// var invites = await channel.GetInvitesAsync(); | |||||
/// if (invites.Count == 0) return; | |||||
/// var invite = invites.OrderByDescending(x => x.Uses).FirstOrDefault(); | |||||
/// </code> | |||||
/// </example> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection | |||||
/// of invite metadata that are created for this channel. | |||||
/// </returns> | |||||
Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null); | |||||
} | } | ||||
} | } |
@@ -25,16 +25,6 @@ namespace Discord.Rest | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Category)"; | private string DebuggerDisplay => $"{Name} ({Id}, Category)"; | ||||
// IGuildChannel | |||||
/// <inheritdoc /> | |||||
/// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | |||||
Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
/// <inheritdoc /> | |||||
/// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | |||||
Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
//IChannel | //IChannel | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
/// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | /// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | ||||
@@ -179,32 +179,6 @@ namespace Discord.Rest | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Gets a collection of all invites to this channel. | |||||
/// </summary> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection | |||||
/// of invite metadata that are created for this channel. | |||||
/// </returns> | |||||
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||||
/// <summary> | |||||
/// Creates a new invite to this channel. | |||||
/// </summary> | |||||
/// <param name="maxAge">The time (in seconds) until the invite expires. Set to <c>null</c> to never expire.</param> | |||||
/// <param name="maxUses">The max amount of times this invite may be used. Set to <c>null</c> to have unlimited uses.</param> | |||||
/// <param name="isTemporary">If <c>true</c>, the user accepting this invite will be kicked from the guild after closing their client.</param> | |||||
/// <param name="isUnique">If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use invites).</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous invite creation operation. The task result contains an invite | |||||
/// metadata object containing information for the created invite. | |||||
/// </returns> | |||||
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
/// <summary> | |||||
/// Gets the name of this channel. | /// Gets the name of this channel. | ||||
/// </summary> | /// </summary> | ||||
/// <returns> | /// <returns> | ||||
@@ -225,13 +199,6 @@ namespace Discord.Rest | |||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | |||||
=> await GetInvitesAsync(options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | |||||
=> await CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) | OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) | ||||
=> GetPermissionOverwrite(role); | => GetPermissionOverwrite(role); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -204,6 +204,14 @@ namespace Discord.Rest | |||||
public Task SyncPermissionsAsync(RequestOptions options = null) | public Task SyncPermissionsAsync(RequestOptions options = null) | ||||
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options); | => ChannelHelper.SyncPermissionsAsync(this, Discord, options); | ||||
//Invites | |||||
/// <inheritdoc /> | |||||
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | ||||
//ITextChannel | //ITextChannel | ||||
@@ -57,8 +57,17 @@ namespace Discord.Rest | |||||
/// </returns> | /// </returns> | ||||
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetCategoryAsync(this, Discord, options); | => ChannelHelper.GetCategoryAsync(this, Discord, options); | ||||
public Task SyncPermissionsAsync(RequestOptions options = null) | public Task SyncPermissionsAsync(RequestOptions options = null) | ||||
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options); | => ChannelHelper.SyncPermissionsAsync(this, Discord, options); | ||||
//Invites | |||||
/// <inheritdoc /> | |||||
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | ||||
@@ -77,6 +86,7 @@ namespace Discord.Rest | |||||
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | => AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | ||||
// INestedChannel | // INestedChannel | ||||
/// <inheritdoc /> | |||||
async Task<ICategoryChannel> INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) | async Task<ICategoryChannel> INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options) | ||||
{ | { | ||||
if (CategoryId.HasValue && mode == CacheMode.AllowDownload) | if (CategoryId.HasValue && mode == CacheMode.AllowDownload) | ||||
@@ -67,14 +67,6 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IGuildUser>(GetUser(id)); | => Task.FromResult<IGuildUser>(GetUser(id)); | ||||
/// <inheritdoc /> | |||||
/// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | |||||
Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
/// <inheritdoc /> | |||||
/// <exception cref="NotSupportedException">This method is not supported with category channels.</exception> | |||||
Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | |||||
=> throw new NotSupportedException(); | |||||
//IChannel | //IChannel | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -184,31 +184,6 @@ namespace Discord.WebSocket | |||||
} | } | ||||
} | } | ||||
/// <summary> | |||||
/// Returns a collection of all invites to this channel. | |||||
/// </summary> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection | |||||
/// of invite metadata that are created for this channel. | |||||
/// </returns> | |||||
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||||
/// <summary> | |||||
/// Creates a new invite to this channel. | |||||
/// </summary> | |||||
/// <param name="maxAge">The time (in seconds) until the invite expires. Set to <c>null</c> to never expire.</param> | |||||
/// <param name="maxUses">The max amount of times this invite may be used. Set to <c>null</c> to have unlimited uses.</param> | |||||
/// <param name="isTemporary">If <c>true</c>, the user accepting this invite will be kicked from the guild after closing their client.</param> | |||||
/// <param name="isUnique">If <c>true</c>, don't try to reuse a similar invite (useful for creating many unique one time use invites).</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous invite creation operation. The task result contains an invite | |||||
/// metadata object containing information for the created invite. | |||||
/// </returns> | |||||
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
public new virtual SocketGuildUser GetUser(ulong id) => null; | public new virtual SocketGuildUser GetUser(ulong id) => null; | ||||
/// <summary> | /// <summary> | ||||
@@ -234,13 +209,6 @@ namespace Discord.WebSocket | |||||
ulong IGuildChannel.GuildId => Guild.Id; | ulong IGuildChannel.GuildId => Guild.Id; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options) | |||||
=> await GetInvitesAsync(options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options) | |||||
=> await CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) | OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) | ||||
=> GetPermissionOverwrite(role); | => GetPermissionOverwrite(role); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -126,7 +126,6 @@ namespace Discord.WebSocket | |||||
/// <returns> | /// <returns> | ||||
/// Paged collection of messages. | /// Paged collection of messages. | ||||
/// </returns> | /// </returns> | ||||
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) | public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) | ||||
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); | => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); | ||||
/// <summary> | /// <summary> | ||||
@@ -304,6 +303,14 @@ namespace Discord.WebSocket | |||||
public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetWebhooksAsync(this, Discord, options); | => ChannelHelper.GetWebhooksAsync(this, Discord, options); | ||||
//Invites | |||||
/// <inheritdoc /> | |||||
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | private string DebuggerDisplay => $"{Name} ({Id}, Text)"; | ||||
internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel; | internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel; | ||||
@@ -79,6 +79,14 @@ namespace Discord.WebSocket | |||||
return null; | return null; | ||||
} | } | ||||
//Invites | |||||
/// <inheritdoc /> | |||||
public async Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); | |||||
/// <inheritdoc /> | |||||
public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||||
private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | ||||
internal new SocketVoiceChannel Clone() => MemberwiseClone() as SocketVoiceChannel; | internal new SocketVoiceChannel Clone() => MemberwiseClone() as SocketVoiceChannel; | ||||