Implemented new instant invite typespull/1958/head
| @@ -12,7 +12,7 @@ namespace Discord | |||
| /// Gets the parent (category) ID of this channel in the guild's channel list. | |||
| /// </summary> | |||
| /// <returns> | |||
| /// A <see cref="ulong"/> representing the snowflake identifier of the parent of this channel; | |||
| /// A <see cref="ulong"/> representing the snowflake identifier of the parent of this channel; | |||
| /// <c>null</c> if none is set. | |||
| /// </returns> | |||
| ulong? CategoryId { get; } | |||
| @@ -56,6 +56,50 @@ namespace Discord | |||
| /// 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> | |||
| /// Creates a new invite to this channel. | |||
| /// </summary> | |||
| /// <example> | |||
| /// <para>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.</para> | |||
| /// <code language="cs"> | |||
| /// await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3); | |||
| /// </code> | |||
| /// </example> | |||
| /// <param name="applicationId">The id of the embedded application to open for this invite</param> | |||
| /// <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> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge = 86400, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null); | |||
| /// <summary> | |||
| /// Creates a new invite to this channel. | |||
| /// </summary> | |||
| /// <example> | |||
| /// <para>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.</para> | |||
| /// <code language="cs"> | |||
| /// await guildChannel.CreateInviteAsync(maxAge: 43200, maxUses: 3); | |||
| /// </code> | |||
| /// </example> | |||
| /// <param name="user">The id of the user whose stream to display for this invite</param> | |||
| /// <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> CreateInviteToStreamAsync(IUser user, 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 | |||
| @@ -9,6 +9,10 @@ namespace Discord | |||
| /// <summary> | |||
| /// The invite is for a Go Live stream. | |||
| /// </summary> | |||
| Stream = 1 | |||
| Stream = 1, | |||
| /// <summary> | |||
| /// The invite is for embedded application. | |||
| /// </summary> | |||
| EmbeddedApplication = 2 | |||
| } | |||
| } | |||
| @@ -14,5 +14,11 @@ namespace Discord.API.Rest | |||
| public Optional<bool> IsTemporary { get; set; } | |||
| [JsonProperty("unique")] | |||
| public Optional<bool> IsUnique { get; set; } | |||
| [JsonProperty("target_type")] | |||
| public Optional<TargetUserType> TargetType { get; set; } | |||
| [JsonProperty("target_user_id")] | |||
| public Optional<ulong> TargetUserId { get; set; } | |||
| [JsonProperty("target_application_id")] | |||
| public Optional<ulong> TargetApplicationId { get; set; } | |||
| } | |||
| } | |||
| @@ -1079,6 +1079,12 @@ namespace Discord.API | |||
| Preconditions.AtLeast(args.MaxUses, 0, nameof(args.MaxUses)); | |||
| Preconditions.AtMost(args.MaxAge, 86400, nameof(args.MaxAge), | |||
| "The maximum age of an invite must be less than or equal to a day (86400 seconds)."); | |||
| if (args.TargetType.IsSpecified) | |||
| { | |||
| Preconditions.NotEqual((int)args.TargetType.Value, (int)TargetUserType.Undefined, nameof(args.TargetType)); | |||
| if (args.TargetType.Value == TargetUserType.Stream) Preconditions.GreaterThan(args.TargetUserId, 0, nameof(args.TargetUserId)); | |||
| if (args.TargetType.Value == TargetUserType.EmbeddedApplication) Preconditions.GreaterThan(args.TargetApplicationId, 0, nameof(args.TargetUserId)); | |||
| } | |||
| options = RequestOptions.CreateOrClone(options); | |||
| var ids = new BucketIds(channelId: channelId); | |||
| @@ -120,6 +120,54 @@ namespace Discord.Rest | |||
| return RestInviteMetadata.Create(client, null, channel, model); | |||
| } | |||
| /// <exception cref="ArgumentException"> | |||
| /// <paramref name="channel.Id"/> may not be equal to zero. | |||
| /// -and- | |||
| /// <paramref name="maxAge"/> and <paramref name="maxUses"/> must be greater than zero. | |||
| /// -and- | |||
| /// <paramref name="maxAge"/> must be lesser than 86400. | |||
| /// </exception> | |||
| public static async Task<RestInviteMetadata> CreateInviteToStreamAsync(IGuildChannel channel, BaseDiscordClient client, | |||
| int? maxAge, int? maxUses, bool isTemporary, bool isUnique, IUser user, | |||
| RequestOptions options) | |||
| { | |||
| var args = new API.Rest.CreateChannelInviteParams | |||
| { | |||
| IsTemporary = isTemporary, | |||
| IsUnique = isUnique, | |||
| MaxAge = maxAge ?? 0, | |||
| MaxUses = maxUses ?? 0, | |||
| TargetType = TargetUserType.Stream, | |||
| TargetUserId = user.Id | |||
| }; | |||
| var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false); | |||
| return RestInviteMetadata.Create(client, null, channel, model); | |||
| } | |||
| /// <exception cref="ArgumentException"> | |||
| /// <paramref name="channel.Id"/> may not be equal to zero. | |||
| /// -and- | |||
| /// <paramref name="maxAge"/> and <paramref name="maxUses"/> must be greater than zero. | |||
| /// -and- | |||
| /// <paramref name="maxAge"/> must be lesser than 86400. | |||
| /// </exception> | |||
| public static async Task<RestInviteMetadata> CreateInviteToApplicationAsync(IGuildChannel channel, BaseDiscordClient client, | |||
| int? maxAge, int? maxUses, bool isTemporary, bool isUnique, ulong applicationId, | |||
| RequestOptions options) | |||
| { | |||
| var args = new API.Rest.CreateChannelInviteParams | |||
| { | |||
| IsTemporary = isTemporary, | |||
| IsUnique = isUnique, | |||
| MaxAge = maxAge ?? 0, | |||
| MaxUses = maxUses ?? 0, | |||
| TargetType = TargetUserType.EmbeddedApplication, | |||
| TargetApplicationId = applicationId | |||
| }; | |||
| var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false); | |||
| return RestInviteMetadata.Create(client, null, channel, model); | |||
| } | |||
| //Messages | |||
| public static async Task<RestMessage> GetMessageAsync(IMessageChannel channel, BaseDiscordClient client, | |||
| ulong id, RequestOptions options) | |||
| @@ -17,7 +17,7 @@ namespace Discord.Rest | |||
| /// <inheritdoc /> | |||
| public string Topic { get; private set; } | |||
| /// <inheritdoc /> | |||
| public virtual int SlowModeInterval { get; private set; } | |||
| public virtual int SlowModeInterval { get; private set; } | |||
| /// <inheritdoc /> | |||
| public ulong? CategoryId { get; private set; } | |||
| @@ -78,7 +78,7 @@ namespace Discord.Rest | |||
| /// </exception> | |||
| /// <returns> | |||
| /// A paged collection containing a collection of guild users that can access this channel. Flattening the | |||
| /// paginated response into a collection of users with | |||
| /// paginated response into a collection of users with | |||
| /// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the users. | |||
| /// </returns> | |||
| public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null) | |||
| @@ -215,6 +215,10 @@ namespace Discord.Rest | |||
| /// <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); | |||
| public Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => throw new NotImplementedException(); | |||
| public Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => throw new NotImplementedException(); | |||
| /// <inheritdoc /> | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||
| => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||
| @@ -60,12 +60,18 @@ namespace Discord.Rest | |||
| /// <inheritdoc /> | |||
| public Task SyncPermissionsAsync(RequestOptions options = null) | |||
| => 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<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| public async Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||
| => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||
| @@ -258,6 +258,12 @@ namespace Discord.WebSocket | |||
| 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<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| public async Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||
| => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||
| @@ -90,6 +90,12 @@ namespace Discord.WebSocket | |||
| 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<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => await ChannelHelper.CreateInviteToApplicationAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, applicationId, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| public async Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => await ChannelHelper.CreateInviteToStreamAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, user, options).ConfigureAwait(false); | |||
| /// <inheritdoc /> | |||
| public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null) | |||
| => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); | |||
| @@ -46,6 +46,10 @@ namespace Discord | |||
| { | |||
| throw new NotImplementedException(); | |||
| } | |||
| public Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => throw new NotImplementedException(); | |||
| public Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => throw new NotImplementedException(); | |||
| public Task<IWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) | |||
| { | |||
| @@ -47,6 +47,10 @@ namespace Discord | |||
| { | |||
| throw new NotImplementedException(); | |||
| } | |||
| public Task<IInviteMetadata> CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => throw new NotImplementedException(); | |||
| public Task<IInviteMetadata> CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = default(int?), bool isTemporary = false, bool isUnique = false, RequestOptions options = null) | |||
| => throw new NotImplementedException(); | |||
| public Task DeleteAsync(RequestOptions options = null) | |||
| { | |||