Ejemplo n.º 1
0
        public static async Task <Model> ModifyAsync(IWebhook webhook, BaseDiscordClient client,
                                                     Action <WebhookProperties> func, RequestOptions options)
        {
            WebhookProperties args = new WebhookProperties();

            func(args);
            ModifyWebhookParams apiArgs = new ModifyWebhookParams
            {
                Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create <ImageModel?>(),
                Name   = args.Name
            };

            if (!apiArgs.Avatar.IsSpecified && webhook.AvatarId != null)
            {
                apiArgs.Avatar = new ImageModel(webhook.AvatarId);
            }

            if (args.Channel.IsSpecified)
            {
                apiArgs.ChannelId = args.Channel.Value.Id;
            }
            else if (args.ChannelId.IsSpecified)
            {
                apiArgs.ChannelId = args.ChannelId.Value;
            }

            return(await client.ApiClient.ModifyWebhookAsync(webhook.Id, apiArgs, options).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        public static async Task <WebhookModel> ModifyAsync(DiscordWebhookClient client,
                                                            Action <WebhookProperties> func, RequestOptions options)
        {
            var args = new WebhookProperties();

            func(args);
            var apiArgs = new ModifyWebhookParams
            {
                Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create <ImageModel?>(),
                Name   = args.Name
            };

            if (!apiArgs.Avatar.IsSpecified && client.Webhook.AvatarId != null)
            {
                apiArgs.Avatar = new ImageModel(client.Webhook.AvatarId);
            }

            return(await client.ApiClient.ModifyWebhookAsync(client.Webhook.Id, apiArgs, options).ConfigureAwait(false));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ModifyWebhookAsync(Snowflake webhookId, [FromQuery] ModifyWebhookParams args)
        {
            args.Validate();

            var webhook = new Webhook
            {
                Id = webhookId
            };

            if (args.Avatar.IsSpecified)
            {
                webhook.Avatar = args.Avatar.Value;
            }
            if (args.ChannelId.IsSpecified)
            {
                webhook.ChannelId = args.ChannelId.Value;
            }
            if (args.Name.IsSpecified)
            {
                webhook.Name = args.Name.Value;
            }

            return(Ok(webhook));
        }