use of org.javacord.api.entity.webhook.Webhook in project Javacord by BtoBastian.
the class WebhookUpdaterDelegateImpl method update.
@Override
public CompletableFuture<Webhook> update() {
boolean patchWebhook = false;
ObjectNode body = JsonNodeFactory.instance.objectNode();
if (name != null) {
body.put("name", name);
patchWebhook = true;
}
if (channel != null) {
body.put("channel_id", channel.getIdAsString());
patchWebhook = true;
}
if (updateAvatar) {
if (avatar == null) {
body.putNull("avatar");
}
patchWebhook = true;
}
if (patchWebhook) {
if (avatar != null) {
return avatar.asByteArray(webhook.getApi()).thenAccept(bytes -> {
String base64Avatar = "data:image/" + avatar.getFileType() + ";base64," + Base64.getEncoder().encodeToString(bytes);
body.put("avatar", base64Avatar);
}).thenCompose(aVoid -> setUrlParameters(new RestRequest<>(webhook.getApi(), RestMethod.PATCH, RestEndpoint.WEBHOOK)).setBody(body).setAuditLogReason(reason).execute(result -> WebhookImpl.createWebhook(webhook.getApi(), result.getJsonBody())));
}
return setUrlParameters(new RestRequest<>(webhook.getApi(), RestMethod.PATCH, RestEndpoint.WEBHOOK)).setBody(body).setAuditLogReason(reason).execute(result -> WebhookImpl.createWebhook(webhook.getApi(), result.getJsonBody()));
} else {
return CompletableFuture.completedFuture(webhook);
}
}
Aggregations