Ejemplo n.º 1
0
        internal static async Task DeleteGlobalCommand(BaseDiscordClient client, RestGlobalCommand command, RequestOptions options = null)
        {
            Preconditions.NotNull(command, nameof(command));
            Preconditions.NotEqual(command.Id, 0, nameof(command.Id));

            await client.ApiClient.DeleteGlobalApplicationCommandAsync(command.Id, options).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public static async Task <IReadOnlyCollection <RestGlobalCommand> > BulkOverwriteGlobalApplicationCommandAsync(BaseDiscordClient client, ApplicationCommandProperties[] properties,
                                                                                                                       RequestOptions options = null)
        {
            var models = await InteractionHelper.BulkOverwriteGlobalCommandsAsync(client, properties, options);

            return(models.Select(x => RestGlobalCommand.Create(client, x)).ToImmutableArray());
        }
Ejemplo n.º 5
0
        internal static RestGlobalCommand Create(BaseDiscordClient client, Model model)
        {
            var entity = new RestGlobalCommand(client, model.Id);

            entity.Update(model);
            return(entity);
        }
Ejemplo n.º 6
0
        public static async Task <RestGlobalCommand> GetGlobalApplicationCommandAsync(BaseDiscordClient client, ulong id,
                                                                                      RequestOptions options = null)
        {
            var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options);

            return(model != null?RestGlobalCommand.Create(client, model) : null);
        }
Ejemplo n.º 7
0
 internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, RestApplicationCommandType type, ulong guildId = 0)
 {
     return(type switch
     {
         RestApplicationCommandType.GlobalCommand => RestGlobalCommand.Create(client, model),
         RestApplicationCommandType.GuildCommand => RestGuildCommand.Create(client, model, guildId),
         _ => null
     });
Ejemplo n.º 8
0
        public static async Task <IReadOnlyCollection <RestGlobalCommand> > GetGlobalApplicationCommands(BaseDiscordClient client, RequestOptions options)
        {
            var response = await client.ApiClient.GetGlobalApplicationCommandsAsync(options).ConfigureAwait(false);

            if (!response.Any())
            {
                return(new RestGlobalCommand[0]);
            }

            return(response.Select(x => RestGlobalCommand.Create(client, x)).ToArray());
        }
Ejemplo n.º 9
0
        internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, RestApplicationCommandType type, ulong guildId = 0)
        {
            if (type == RestApplicationCommandType.GlobalCommand)
            {
                return(RestGlobalCommand.Create(client, model));
            }

            if (type == RestApplicationCommandType.GuildCommand)
            {
                return(RestGuildCommand.Create(client, model, guildId));
            }

            return(null);
        }
Ejemplo n.º 10
0
        internal static async Task <RestGlobalCommand[]> CreateGlobalCommands(BaseDiscordClient client,
                                                                              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 > 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 ApplicationCommandOption(x)).ToArray()
                    : Optional <ApplicationCommandOption[]> .Unspecified
                };

                models.Add(model);
            }

            var cmd = await client.ApiClient.CreateGlobalApplicationCommandsAsync(models, options).ConfigureAwait(false);

            return(cmd.Select(x => RestGlobalCommand.Create(client, x)).ToArray());
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
 internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, ulong?guildId)
 {
     return(guildId.HasValue
         ? RestGuildCommand.Create(client, model, guildId.Value)
         : RestGlobalCommand.Create(client, model));
 }