Esempio n. 1
0
        internal static async Task DeleteGuildCommand(BaseDiscordClient client, RestGuildCommand command, RequestOptions options = null)
        {
            Preconditions.NotNull(command, nameof(command));
            Preconditions.NotEqual(command.Id, 0, nameof(command.Id));

            await client.ApiClient.DeleteGuildApplicationCommandAsync(command.GuildId, command.Id, options).ConfigureAwait(false);
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        public static async Task <IReadOnlyCollection <RestGuildCommand> > BulkOverwriteGuildApplicationCommandAsync(BaseDiscordClient client, ulong guildId,
                                                                                                                     ApplicationCommandProperties[] properties, RequestOptions options = null)
        {
            var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(client, guildId, properties, options);

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

            entity.Update(model);
            return(entity);
        }
Esempio n. 6
0
        public static async Task <RestGuildCommand> GetGuildApplicationCommandAsync(BaseDiscordClient client, ulong id, ulong guildId,
                                                                                    RequestOptions options = null)
        {
            var model = await client.ApiClient.GetGuildApplicationCommandAsync(guildId, id, options);

            return(model != null?RestGuildCommand.Create(client, model, guildId) : null);
        }
Esempio 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
     });
Esempio n. 8
0
        public static async Task <IReadOnlyCollection <RestGuildCommand> > GetGuildApplicationCommands(BaseDiscordClient client, ulong guildId, RequestOptions options)
        {
            var response = await client.ApiClient.GetGuildApplicationCommandAsync(guildId, options).ConfigureAwait(false);

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

            return(response.Select(x => RestGuildCommand.Create(client, x, guildId)).ToImmutableArray());
        }
Esempio 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);
        }
Esempio n. 10
0
        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());
        }
Esempio n. 11
0
        internal static async Task <RestGuildCommand> ModifyGuildCommand(BaseDiscordClient client, RestGuildCommand 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.ModifyGuildApplicationCommandAsync(model, command.GuildId, command.Id, options).ConfigureAwait(false);

            command.Update(msg);
            return(command);
        }
Esempio 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));
 }