Exemplo n.º 1
0
        internal static async Task <RestGlobalCommand> ModifyGlobalCommand(BaseDiscordClient client, RestGlobalCommand command,
                                                                           Action <ApplicationCommandProperties> func, RequestOptions options = null)
        {
            ApplicationCommandProperties args = new ApplicationCommandProperties();

            func(args);

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

            var model = new Discord.API.Rest.ModifyApplicationCommandParams()
            {
                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 msg = await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false);

            command.Update(msg);
            return(command);
        }
Exemplo n.º 2
0
        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,

                // 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.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false));
        }
Exemplo n.º 3
0
        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
            };

            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));
        }
        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));
        }
Exemplo n.º 6
0
        public static async Task <RestGlobalCommand> CreateGlobalApplicationCommandAsync(BaseDiscordClient client, ApplicationCommandProperties properties,
                                                                                         RequestOptions options = null)
        {
            var model = await InteractionHelper.CreateGlobalCommandAsync(client, properties, options);

            return(RestGlobalCommand.Create(client, model));
        }
Exemplo n.º 7
0
        public static async Task <RestGuildCommand> CreateGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId, ApplicationCommandProperties properties,
                                                                                       RequestOptions options = null)
        {
            var model = await InteractionHelper.CreateGuildCommandAsync(client, guildId, properties, options);

            return(RestGuildCommand.Create(client, model, guildId));
        }
 public Task <IApplicationCommand> CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions?options = null)
 {
     return(((IGuild)_socketGuild).CreateApplicationCommandAsync(properties, options));
 }
Exemplo n.º 9
0
 Task <IApplicationCommand> IDiscordClient.CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options)
 => Task.FromResult <IApplicationCommand>(null);
 public Task <IApplicationCommand> CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions?options = null)
 {
     return(CreateGlobalApplicationCommand(properties, options));
 }