Browse Source

Add maxage check & improve maxage parameter check

pull/1140/head
Still Hsu 7 years ago
parent
commit
50f18c6936
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
1 changed files with 9 additions and 9 deletions
  1. +9
    -9
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs

+ 9
- 9
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -76,15 +76,15 @@ namespace Discord.Rest
public static async Task<RestInviteMetadata> CreateInviteAsync(IGuildChannel channel, BaseDiscordClient client,
int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
{
var args = new CreateChannelInviteParams { IsTemporary = isTemporary, IsUnique = isUnique };
if (maxAge.HasValue)
args.MaxAge = maxAge.Value;
else
args.MaxAge = 0;
if (maxUses.HasValue)
args.MaxUses = maxUses.Value;
else
args.MaxUses = 0;
if (maxAge.HasValue && maxAge > 86400)
throw new InvalidOperationException("The maximum age of an invite must be less than or equal to a day (86400).");
var args = new API.Rest.CreateChannelInviteParams
{
IsTemporary = isTemporary,
IsUnique = isUnique,
MaxAge = maxAge ?? 0,
MaxUses = maxUses ?? 0
};
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);
return RestInviteMetadata.Create(client, null, channel, model);
}


Loading…
Cancel
Save