feature: Add invite maxAge check before attempting to create the invite (#1140)
* Add maxage check & improve maxage parameter check * Change InvalidOperation to ArgumentOoR * Remove HasValue check ...since it does it implicitly already. * Add parameter names & better wording for invite OoR * Move maxAge check to DiscordRestApiClient for consistency
This commit is contained in:
@@ -978,6 +978,8 @@ namespace Discord.API
|
|||||||
Preconditions.NotNull(args, nameof(args));
|
Preconditions.NotNull(args, nameof(args));
|
||||||
Preconditions.AtLeast(args.MaxAge, 0, nameof(args.MaxAge));
|
Preconditions.AtLeast(args.MaxAge, 0, nameof(args.MaxAge));
|
||||||
Preconditions.AtLeast(args.MaxUses, 0, nameof(args.MaxUses));
|
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).");
|
||||||
options = RequestOptions.CreateOrClone(options);
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
|
||||||
var ids = new BucketIds(channelId: channelId);
|
var ids = new BucketIds(channelId: channelId);
|
||||||
|
|||||||
@@ -76,9 +76,13 @@ namespace Discord.Rest
|
|||||||
public static async Task<RestInviteMetadata> CreateInviteAsync(IGuildChannel channel, BaseDiscordClient client,
|
public static async Task<RestInviteMetadata> CreateInviteAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||||
int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
|
int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
|
||||||
{
|
{
|
||||||
var args = new CreateChannelInviteParams { IsTemporary = isTemporary, IsUnique = isUnique };
|
var args = new API.Rest.CreateChannelInviteParams
|
||||||
args.MaxAge = maxAge.GetValueOrDefault(0);
|
{
|
||||||
args.MaxUses = maxUses.GetValueOrDefault(0);
|
IsTemporary = isTemporary,
|
||||||
|
IsUnique = isUnique,
|
||||||
|
MaxAge = maxAge ?? 0,
|
||||||
|
MaxUses = maxUses ?? 0
|
||||||
|
};
|
||||||
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);
|
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||||
return RestInviteMetadata.Create(client, null, channel, model);
|
return RestInviteMetadata.Create(client, null, channel, model);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user