internal static async Task <RestGuildCommand> CreateGuildCommand(BaseDiscordClient client, ulong guildId, SlashCommandCreationProperties args, RequestOptions options = null) { Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); Preconditions.NotNullOrEmpty(args.Description, nameof(args.Description)); if (args.Options.IsSpecified) { if (args.Options.Value.Count > 10) { throw new ArgumentException("Option count must be 10 or less"); } foreach (var item in args.Options.Value) { Preconditions.NotNullOrEmpty(item.Name, nameof(item.Name)); Preconditions.NotNullOrEmpty(item.Description, nameof(item.Description)); } } var model = new CreateApplicationCommandParams() { Name = args.Name, Description = args.Description, Options = args.Options.IsSpecified ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional <Discord.API.ApplicationCommandOption[]> .Unspecified }; var cmd = await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); return(RestGuildCommand.Create(client, cmd, guildId)); }
internal static async Task <RestGlobalCommand> CreateGlobalCommand(BaseDiscordClient client, SlashCommandCreationProperties args, RequestOptions options = null) { if (args.Options.IsSpecified) { if (args.Options.Value.Count > 10) { throw new ArgumentException("Option count must be 10 or less"); } } var model = new CreateApplicationCommandParams() { Name = args.Name, Description = args.Description, Options = args.Options.IsSpecified ? args.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() : Optional <Discord.API.ApplicationCommandOption[]> .Unspecified }; var cmd = await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); return(RestGlobalCommand.Create(client, cmd)); }
public static async Task <ApplicationCommand> CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties arg, RequestOptions options = null) { var model = new CreateApplicationCommandParams { Name = arg.Name.Value, Type = arg.Type, DefaultPermission = arg.IsDefaultPermission.IsSpecified ? arg.IsDefaultPermission.Value : Optional <bool> .Unspecified }; if (arg is SlashCommandProperties slashProps) { Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); model.Description = slashProps.Description.Value; model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified; } return(await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false)); }
public static async Task <ApplicationCommand> CreateGlobalCommandAsync(BaseDiscordClient client, ApplicationCommandProperties arg, RequestOptions options = null) { Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); var model = new CreateApplicationCommandParams { Name = arg.Name.Value, Type = arg.Type, DefaultPermission = arg.IsDefaultPermission.IsSpecified ? arg.IsDefaultPermission.Value : Optional <bool> .Unspecified, // TODO: better conversion to nullable optionals DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), DmPermission = arg.IsDMEnabled.ToNullable() }; if (arg is SlashCommandProperties slashProps) { Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); model.Description = slashProps.Description.Value; model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified; } return(await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false)); }
internal static async Task <RestGuildCommand[]> CreateGuildCommands(BaseDiscordClient client, ulong guildId, List <SlashCommandCreationProperties> argsList, RequestOptions options = null) { Preconditions.NotNull(argsList, nameof(argsList)); Preconditions.NotEqual(argsList.Count, 0, nameof(argsList)); var models = new List <CreateApplicationCommandParams>(argsList.Count); foreach (var args in argsList) { Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); Preconditions.NotNullOrEmpty(args.Description, nameof(args.Description)); if (args.Options.IsSpecified) { if (args.Options.Value.Count > 25) { throw new ArgumentException("Option count must be 25 or less"); } foreach (var item in args.Options.Value) { Preconditions.NotNullOrEmpty(item.Name, nameof(item.Name)); Preconditions.NotNullOrEmpty(item.Description, nameof(item.Description)); } } var model = new CreateApplicationCommandParams { Name = args.Name, Description = args.Description, Options = args.Options.IsSpecified ? args.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified }; models.Add(model); } var cmd = await client.ApiClient.CreateGuildApplicationCommandsAsync(models, guildId, options).ConfigureAwait(false); return(cmd.Select(x => RestGuildCommand.Create(client, x, guildId)).ToArray()); }
public static async Task <IReadOnlyCollection <ApplicationCommand> > BulkOverwriteGuildCommandsAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties[] args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); var models = new List <CreateApplicationCommandParams>(); foreach (var arg in args) { Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); var model = new CreateApplicationCommandParams { Name = arg.Name.Value, Type = arg.Type, DefaultPermission = arg.IsDefaultPermission.IsSpecified ? arg.IsDefaultPermission.Value : Optional <bool> .Unspecified, // TODO: better conversion to nullable optionals DefaultMemberPermission = arg.DefaultMemberPermissions.ToNullable(), DmPermission = arg.IsDMEnabled.ToNullable() }; if (arg is SlashCommandProperties slashProps) { Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); model.Description = slashProps.Description.Value; model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified; } models.Add(model); } return(await client.ApiClient.BulkOverwriteGuildApplicationCommandsAsync(guildId, models.ToArray(), options).ConfigureAwait(false)); }
public static async Task <ApplicationCommand[]> BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client, ApplicationCommandProperties[] args, RequestOptions options = null) { Preconditions.NotNull(args, nameof(args)); var models = new List <CreateApplicationCommandParams>(); foreach (var arg in args) { Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name)); var model = new CreateApplicationCommandParams { Name = arg.Name.Value, Type = arg.Type, DefaultPermission = arg.IsDefaultPermission.IsSpecified ? arg.IsDefaultPermission.Value : Optional <bool> .Unspecified }; if (arg is SlashCommandProperties slashProps) { Preconditions.NotNullOrEmpty(slashProps.Description, nameof(slashProps.Description)); model.Description = slashProps.Description.Value; model.Options = slashProps.Options.IsSpecified ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray() : Optional <ApplicationCommandOption[]> .Unspecified; } models.Add(model); } return(await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false)); }