示例#1
0
        internal static async Task <RestGlobalCommand> ModifyGlobalCommand(BaseDiscordClient client, RestGlobalCommand command,
                                                                           Action <ApplicationCommandProperties> func, RequestOptions options = null)
        {
            var args = new ApplicationCommandProperties();

            func(args);

            if (args.Options.IsSpecified)
            {
                if (args.Options.Value.Count > 25)
                {
                    throw new ArgumentException("Option count must be 25 or less");
                }
            }

            var model = new ModifyApplicationCommandParams
            {
                Name        = args.Name,
                Description = args.Description,
                Options     = args.Options.IsSpecified
                    ? args.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
                    : Optional <ApplicationCommandOption[]> .Unspecified
            };

            var msg = await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false);

            command.Update(msg);
            return(command);
        }
        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 static async Task <ApplicationCommand> ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
                                                                              ApplicationCommandProperties arg, RequestOptions options = null)
        {
            var model = new ModifyApplicationCommandParams
            {
                Name = arg.Name,
                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.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false));
        }