internal static RestGuildTemplate Create(BaseDiscordClient discord, Model model, bool withSnapshot)
        {
            RestGuildTemplate entity = new RestGuildTemplate();

            entity.Update(discord, model, withSnapshot);
            return(entity);
        }
Example #2
0
        public static async Task <RestGuildTemplate> CreateTemplateAsync(IGuild guild, BaseDiscordClient client, string name, Optional <string> description, bool withSnapshot, RequestOptions options)
        {
            CreateTemplateParams apiargs = new CreateTemplateParams
            {
                Name = name
            };

            if (description.IsSpecified)
            {
                apiargs.Description = description.Value;
            }

            if (withSnapshot)
            {
                GuildTemplateSnapshotJson model = await client.ApiClient.CreateTemplateAsync <API.GuildTemplateSnapshotJson>(guild.Id, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
            else
            {
                GuildTemplateJson model = await client.ApiClient.CreateTemplateAsync <API.GuildTemplateJson>(guild.Id, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
        }
Example #3
0
        public static async Task <RestGuildTemplate> DeleteTemplateAsync(IGuild guild, BaseDiscordClient client, string code, bool withSnapshot, RequestOptions options)
        {
            if (withSnapshot)
            {
                GuildTemplateSnapshotJson model = await client.ApiClient.DeleteTemplateAsync <API.GuildTemplateSnapshotJson>(guild.Id, code, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
            else
            {
                GuildTemplateJson model = await client.ApiClient.DeleteTemplateAsync <API.GuildTemplateJson>(guild.Id, code, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
        }
Example #4
0
        //Templates
        public static async Task <IReadOnlyCollection <RestGuildTemplate> > GetTemplatesAsync(IGuild guild, BaseDiscordClient client, bool withSnapshot, RequestOptions options)
        {
            if (withSnapshot)
            {
                IReadOnlyCollection <GuildTemplateSnapshotJson> models = await client.ApiClient.GetGuildTemplatesAsync <GuildTemplateSnapshotJson>(guild.Id, options).ConfigureAwait(false);

                return(models.Select(x => RestGuildTemplate.Create(client, x, withSnapshot)).ToImmutableArray());
            }
            else
            {
                IReadOnlyCollection <GuildTemplateJson> models = await client.ApiClient.GetGuildTemplatesAsync <GuildTemplateJson>(guild.Id, options).ConfigureAwait(false);

                return(models.Select(x => RestGuildTemplate.Create(client, x, withSnapshot)).ToImmutableArray());
            }
        }
Example #5
0
        public static async Task <RestGuildTemplate> ModifyTemplateAsync(IGuild guild, BaseDiscordClient client, string code, Action <TemplateProperties> func, bool withSnapshot, RequestOptions options)
        {
            if (func == null)
            {
                throw new ArgumentNullException(paramName: nameof(func));
            }
            TemplateProperties props = new TemplateProperties();

            func(props);

            CreateTemplateParams apiargs = new CreateTemplateParams();

            if (props.Name.IsSpecified)
            {
                apiargs.Name = props.Name.Value;
            }

            if (props.Description.IsSpecified)
            {
                apiargs.Description = props.Description.Value;
            }


            if (withSnapshot)
            {
                GuildTemplateSnapshotJson model = await client.ApiClient.ModifyTemplateAsync <API.GuildTemplateSnapshotJson>(guild.Id, code, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
            else
            {
                GuildTemplateJson model = await client.ApiClient.ModifyTemplateAsync <API.GuildTemplateJson>(guild.Id, code, apiargs, options).ConfigureAwait(false);

                return(RestGuildTemplate.Create(client, model, withSnapshot));
            }
        }