use of org.javacord.api.entity.webhook.IncomingWebhook in project Javacord by BtoBastian.
the class WebhookBuilderDelegateImpl method create.
@Override
public CompletableFuture<IncomingWebhook> create() {
if (name == null) {
throw new IllegalStateException("Name is no optional parameter!");
}
ObjectNode body = JsonNodeFactory.instance.objectNode();
body.put("name", name);
if (avatar != null) {
return avatar.asByteArray(channel.getApi()).thenAccept(bytes -> {
String base64Avatar = "data:image/" + avatar.getFileType() + ";base64," + Base64.getEncoder().encodeToString(bytes);
body.put("avatar", base64Avatar);
}).thenCompose(aVoid -> new RestRequest<IncomingWebhook>(channel.getApi(), RestMethod.POST, RestEndpoint.CHANNEL_WEBHOOK).setUrlParameters(channel.getIdAsString()).setBody(body).setAuditLogReason(reason).execute(result -> new IncomingWebhookImpl(channel.getApi(), result.getJsonBody())));
}
return new RestRequest<IncomingWebhook>(channel.getApi(), RestMethod.POST, RestEndpoint.CHANNEL_WEBHOOK).setUrlParameters(channel.getIdAsString()).setBody(body).setAuditLogReason(reason).execute(result -> new IncomingWebhookImpl(channel.getApi(), result.getJsonBody()));
}
Aggregations