use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method addAttachmentAsSpoiler.
@Override
public void addAttachmentAsSpoiler(Icon icon) {
if (icon == null) {
throw new IllegalArgumentException("icon cannot be null!");
}
attachments.add(new FileContainer(icon, true));
attachmentsChanged = true;
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method addAttachment.
@Override
public void addAttachment(byte[] bytes, String fileName) {
if (bytes == null || fileName == null) {
throw new IllegalArgumentException("bytes and fileName cannot be null!");
}
attachments.add(new FileContainer(bytes, fileName));
attachmentsChanged = true;
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method send.
/**
* Send a message to an incoming webhook.
*
* @param webhookId The id of the webhook to send the message to
* @param webhookToken The token of the webhook to send the message to
* @param displayName The display name the webhook should use
* @param avatarUrl The avatar the webhook should use
* @param wait If the completable future will be completed
* @param api The api instance needed to send and return the message
* @return The sent message
*/
protected CompletableFuture<Message> send(String webhookId, String webhookToken, String displayName, URL avatarUrl, boolean wait, DiscordApi api) {
ObjectNode body = JsonNodeFactory.instance.objectNode();
prepareCommonWebhookMessageBodyParts(body);
if (displayName != null) {
body.put("username", displayName);
}
if (avatarUrl != null) {
body.put("avatar_url", avatarUrl.toExternalForm());
}
prepareComponents(body);
if (strBuilder.length() != 0) {
body.put("content", strBuilder.toString());
}
RestRequest<Message> request = new RestRequest<Message>(api, RestMethod.POST, RestEndpoint.WEBHOOK_SEND).addQueryParameter("wait", Boolean.toString(wait)).setUrlParameters(webhookId, webhookToken);
CompletableFuture<Message> future = new CompletableFuture<>();
if (!attachments.isEmpty() || embeds.stream().anyMatch(EmbedBuilder::requiresAttachments)) {
// We access files etc. so this should be async
api.getThreadPool().getExecutorService().submit(() -> {
try {
List<FileContainer> tempAttachments = new ArrayList<>(attachments);
// Add the attachments required for the embeds
for (EmbedBuilder embed : embeds) {
tempAttachments.addAll(((EmbedBuilderDelegateImpl) embed.getDelegate()).getRequiredAttachments());
}
addMultipartBodyToRequest(request, body, tempAttachments, api);
executeWebhookRest(request, wait, future, api);
} catch (Throwable t) {
future.completeExceptionally(t);
}
});
} else {
request.setBody(body);
executeWebhookRest(request, wait, future, api);
}
return future;
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class EmbedBuilderDelegateImpl method setThumbnail.
@Override
public void setThumbnail(File thumbnail) {
thumbnailUrl = null;
if (thumbnail == null) {
thumbnailContainer = null;
} else {
thumbnailContainer = new FileContainer(thumbnail);
thumbnailContainer.setFileTypeOrName(UUID.randomUUID().toString() + "." + FileUtils.getExtension(thumbnail));
}
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class EmbedBuilderDelegateImpl method setAuthor.
@Override
public void setAuthor(String name, String url, File icon) {
authorName = name;
authorUrl = url;
authorIconUrl = null;
if (icon == null) {
authorIconContainer = null;
} else {
authorIconContainer = new FileContainer(icon);
authorIconContainer.setFileTypeOrName(UUID.randomUUID().toString() + "." + FileUtils.getExtension(icon));
}
}
Aggregations