public static async Task <GuildApplicationCommandPermission> ModifyGuildCommandPermissionsAsync(BaseDiscordClient client, ulong guildId, ulong commandId, ApplicationCommandPermission[] args, RequestOptions options) { Preconditions.NotNull(args, nameof(args)); Preconditions.AtMost(args.Length, 10, nameof(args)); Preconditions.AtLeast(args.Length, 0, nameof(args)); var permissionsList = new List <ApplicationCommandPermissions>(); foreach (var arg in args) { var permissions = new ApplicationCommandPermissions { Id = arg.TargetId, Permission = arg.Permission, Type = arg.TargetType }; permissionsList.Add(permissions); } var model = new ModifyGuildApplicationCommandPermissionsParams { Permissions = permissionsList.ToArray() }; var apiModel = await client.ApiClient.ModifyApplicationCommandPermissionsAsync(model, guildId, commandId, options); return(new GuildApplicationCommandPermission(apiModel.Id, apiModel.ApplicationId, guildId, apiModel.Permissions.Select( x => new ApplicationCommandPermission(x.Id, x.Type, x.Permission)).ToArray())); }
public void Validate() { Preconditions.NotNegative(Limit, nameof(Limit)); Preconditions.AtLeast(Limit, Guild.MinGetGuildsLimit, nameof(Limit)); Preconditions.AtMost(Limit, Guild.MaxGetMembersLimit, nameof(Limit)); }
public void Validate() { if (!Id.IsSpecified && !BroadcasterId.IsSpecified && !GameId.IsSpecified) { throw new ArgumentException($"At least one of the listed parameters must have a value for this request: {nameof(Id)}, {nameof(BroadcasterId)}, or {nameof(GameId)}"); } if (Id.IsSpecified) { Preconditions.NotNullOrWhitespace(Id.ToString(), nameof(Id)); } if (First.IsSpecified) { Preconditions.AtLeast(First, 1, nameof(First)); Preconditions.AtMost(First, 100, nameof(First)); } if (After.IsSpecified) { Preconditions.NotNullOrWhitespace(After.ToString(), nameof(After)); } if (Before.IsSpecified) { Preconditions.NotNullOrWhitespace(Before.ToString(), nameof(Before)); } }
public void Validate() { if (!VideoIds.IsSpecified && !UserId.IsSpecified && !GameId.IsSpecified) { throw new ArgumentException($"At least one of the following parameters must be specified: {nameof(VideoIds)}, {nameof(UserId)}, or {nameof(GameId)}"); } if (VideoIds.IsSpecified) { Preconditions.CountGreaterThan(VideoIds, 100, nameof(VideoIds)); Preconditions.CountLessThan(VideoIds, 1, nameof(VideoIds)); } if (First.IsSpecified) { Preconditions.AtLeast(First, 1, nameof(First)); Preconditions.AtMost(First, 100, nameof(First)); } if (After.IsSpecified) { Preconditions.NotNullOrWhitespace(After.ToString(), nameof(After)); } if (Before.IsSpecified) { Preconditions.NotNullOrWhitespace(Before.ToString(), nameof(Before)); } }
public void Validate() { Preconditions.NotNull(MessageIds, nameof(MessageIds)); Preconditions.AtLeast(MessageIds.GetLength(0), Channel.MinBulkMessageDeleteAmount, nameof(MessageIds)); Preconditions.AtMost(MessageIds.GetLength(0), Channel.MaxBulkMessageDeleteAmount, nameof(MessageIds)); Preconditions.YoungerThan(MessageIds, TimeSpan.FromDays(14), nameof(MessageIds)); }
public void Validate() { Preconditions.AtLeast(DeleteMessageDays, Ban.MinMessagePruneDays, nameof(DeleteMessageDays)); Preconditions.AtMost(DeleteMessageDays, Ban.MaxMessagePruneDays, nameof(DeleteMessageDays)); Preconditions.NotNullOrWhitespace(Reason, nameof(Reason)); }
public async Task UnsubscribeChannel(ulong channelId, params RpcChannelEvent[] events) { Preconditions.AtLeast(events?.Length ?? 0, 1, nameof(events)); for (int i = 0; i < events.Length; i++) { await ApiClient.SendChannelUnsubscribeAsync(GetEventName(events[i]), channelId); } }
public void Validate() { if (Count.IsSpecified) { Preconditions.AtLeast(Count, 1, nameof(Count)); Preconditions.AtMost(Count, 100, nameof(Count)); } }
public void Validate() { Preconditions.NotNullOrWhitespace(Name, nameof(Name)); Preconditions.LengthAtLeast(Name, Guild.MinNameLength, nameof(Name)); Preconditions.LengthAtMost(Name, Guild.MaxNameLength, nameof(Name)); Preconditions.NotNullOrWhitespace(Region, nameof(Region)); Preconditions.AtLeast(AfkTimeout, Channel.MinAfkTimeoutDuration, nameof(AfkTimeout)); Preconditions.AtMost(AfkTimeout, Channel.MaxAFkTimeoutDuration, nameof(AfkTimeout)); }
public void Validate() { if (First.IsSpecified) { Preconditions.AtLeast(First, 1, nameof(First)); Preconditions.AtMost(First, 100, nameof(First)); } if (After.IsSpecified) { Preconditions.NotNullOrWhitespace(After.ToString(), nameof(After)); } }
public void Validate() { Preconditions.NotNullOrWhitespace(Name, nameof(Name)); Preconditions.LengthAtLeast(Name, Channel.MinChannelNameLength, nameof(Name)); Preconditions.LengthAtMost(Name, Channel.MaxChannelNameLength, nameof(Name)); Preconditions.NotNull(PermissionOverwrites, nameof(PermissionOverwrites)); Preconditions.NotNull(Topic, nameof(Topic)); Preconditions.LengthAtLeast(Topic, Channel.MinChannelTopicLength, nameof(Topic)); Preconditions.LengthAtMost(Topic, Channel.MaxChannelTopicLength, nameof(Topic)); Preconditions.AtLeast(Bitrate, Channel.MinBitrate, nameof(Bitrate)); Preconditions.AtMost(Bitrate, Channel.MaxBitrate, nameof(Bitrate)); Preconditions.AtLeast(UserLimit, Channel.MinUserLimit, nameof(UserLimit)); Preconditions.AtMost(UserLimit, Channel.MaxUserLimit, nameof(UserLimit)); }
public void Validate() { if (!FromId.IsSpecified && !ToId.IsSpecified) { throw new ArgumentException($"At least one of the following parameters must be specified: {nameof(FromId)} or {nameof(ToId)}"); } if (First.IsSpecified) { Preconditions.AtLeast(First, 20, nameof(First)); Preconditions.AtMost(First, 100, nameof(First)); } if (After.IsSpecified) { Preconditions.NotNullOrWhitespace(After.ToString(), nameof(After)); } }
/// <summary> /// Adds an option to the current slash command. /// </summary> /// <param name="Name">The name of the option to add.</param> /// <param name="Type">The type of this option.</param> /// <param name="Description">The description of this option.</param> /// <param name="Required">If this option is required for this command.</param> /// <param name="Default">If this option is the default option.</param> /// <param name="Options">The options of the option to add.</param> /// <param name="Choices">The choices of this option.</param> /// <returns>The current builder.</returns> public SlashCommandBuilder AddOption(string Name, ApplicationCommandOptionType Type, string Description, bool Required = true, bool Default = false, List <SlashCommandOptionBuilder> Options = null, params ApplicationCommandOptionChoiceProperties[] Choices) { // Make sure the name matches the requirements from discord Preconditions.NotNullOrEmpty(Name, nameof(Name)); Preconditions.AtLeast(Name.Length, 3, nameof(Name)); Preconditions.AtMost(Name.Length, MaxNameLength, nameof(Name)); // Discord updated the docs, this regex prevents special characters like @!$%( and s p a c e s.. etc, // https://discord.com/developers/docs/interactions/slash-commands#applicationcommand if (!Regex.IsMatch(Name, @"^[\w-]{3,32}$")) { throw new ArgumentException("Command name cannot contian any special characters or whitespaces!", nameof(Name)); } // same with description Preconditions.NotNullOrEmpty(Description, nameof(Description)); Preconditions.AtLeast(Description.Length, 3, nameof(Description)); Preconditions.AtMost(Description.Length, MaxDescriptionLength, nameof(Description)); // make sure theres only one option with default set to true if (Default) { if (this.Options != null) { if (this.Options.Any(x => x.Default)) { throw new ArgumentException("There can only be one command option with default set to true!", nameof(Default)); } } } SlashCommandOptionBuilder option = new SlashCommandOptionBuilder(); option.Name = Name; option.Description = Description; option.Required = Required; option.Default = Default; option.Options = Options; option.Choices = Choices != null ? new List <ApplicationCommandOptionChoiceProperties>(Choices) : null; return(AddOption(option)); }
public static async Task <ApplicationCommand> ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, ApplicationCommandProperties args, RequestOptions options = null) { if (args.Name.IsSpecified) { Preconditions.AtMost(args.Name.Value.Length, 32, nameof(args.Name)); Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name)); } var model = new ModifyApplicationCommandParams { Name = args.Name, DefaultPermission = args.IsDefaultPermission.IsSpecified ? args.IsDefaultPermission.Value : Optional <bool> .Unspecified }; if (args is SlashCommandProperties slashProps) { if (slashProps.Description.IsSpecified) { Preconditions.AtMost(slashProps.Description.Value.Length, 100, nameof(slashProps.Description)); Preconditions.AtLeast(slashProps.Description.Value.Length, 1, nameof(slashProps.Description)); } if (slashProps.Options.IsSpecified) { if (slashProps.Options.Value.Count > 10) { throw new ArgumentException("Option count must be 10 or less"); } } model.Description = slashProps.Description; model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified; } return(await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false)); }
public void Validate() { if (CommunityIds.IsSpecified) { Preconditions.CountGreaterThan(CommunityIds, 100, nameof(CommunityIds)); Preconditions.CountLessThan(CommunityIds, 1, nameof(CommunityIds)); } if (GameIds.IsSpecified) { Preconditions.CountGreaterThan(GameIds, 100, nameof(GameIds)); Preconditions.CountLessThan(GameIds, 1, nameof(GameIds)); } if (Languages.IsSpecified) { Preconditions.CountGreaterThan(Languages, 100, nameof(Languages)); Preconditions.CountLessThan(Languages, 1, nameof(Languages)); } if (UserIds.IsSpecified) { Preconditions.CountGreaterThan(UserIds, 100, nameof(UserIds)); Preconditions.CountLessThan(UserIds, 1, nameof(UserIds)); } if (UserNames.IsSpecified) { Preconditions.CountGreaterThan(UserNames, 100, nameof(UserNames)); Preconditions.CountLessThan(UserNames, 1, nameof(UserNames)); } if (First.IsSpecified) { Preconditions.AtLeast(First, 1, nameof(First)); Preconditions.AtMost(First, 100, nameof(First)); } if (After.IsSpecified) { Preconditions.NotNullOrWhitespace(After.ToString(), nameof(After)); } if (Before.IsSpecified) { Preconditions.NotNullOrWhitespace(Before.ToString(), nameof(Before)); } }
public void Validate() { int specified = 0; if (UserId.IsSpecified) { specified++; Preconditions.NotZero(UserId, nameof(UserId)); } if (VideoId.IsSpecified) { specified++; Preconditions.NotZero(VideoId, nameof(VideoId)); } if (specified > 1) { throw new ArgumentException($"Only one of {nameof(UserId)} or {nameof(VideoId)} can be specified for this request."); } if (specified == 0) { throw new ArgumentException($"Either {nameof(UserId)} or {nameof(VideoId)} must be specified for this request."); } if (First.IsSpecified) { Preconditions.AtLeast(First, 1, nameof(First)); Preconditions.AtMost(First, 100, nameof(First)); } if (After.IsSpecified) { Preconditions.NotNullOrWhitespace(After.ToString(), nameof(After)); } if (Before.IsSpecified) { Preconditions.NotNullOrWhitespace(Before.ToString(), nameof(Before)); } }
public void Validate() { Preconditions.AtLeast(Limit, Guild.MinGetGuildsLimit, nameof(Limit)); Preconditions.AtMost(Limit, Guild.MaxGetGuildsLimit, nameof(Limit)); Preconditions.Exclusive(new[] { Before, After }, new[] { nameof(Before), nameof(After) }); }
public void Validate() { Preconditions.NotZero(UserId, nameof(UserId)); Preconditions.AtLeast(Limit, AuditLog.MinimumGetEntryAmount, nameof(Limit)); Preconditions.AtMost(Limit, AuditLog.MaximumGetEntryAmount, nameof(Limit)); }