use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method addAttachmentAsSpoiler.
@Override
public void addAttachmentAsSpoiler(URL url) {
if (url == null) {
throw new IllegalArgumentException("url cannot be null!");
}
attachments.add(new FileContainer(url, true));
attachmentsChanged = true;
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method checkForAttachmentsAndExecuteRequest.
// //////////////////////////////////////////////////////////////////////////////
// Internal MessageBuilder utility methods
// //////////////////////////////////////////////////////////////////////////////
private CompletableFuture<Message> checkForAttachmentsAndExecuteRequest(TextChannel channel, ObjectNode body, RestRequest<Message> request, boolean clearAttachmentsIfAppropriate) {
if (attachments.isEmpty() && embeds.stream().noneMatch(EmbedBuilder::requiresAttachments)) {
if (clearAttachmentsIfAppropriate) {
body.set("attachments", JsonNodeFactory.instance.objectNode().arrayNode());
}
return executeRequestWithoutAttachments(channel, body, request);
}
CompletableFuture<Message> future = new CompletableFuture<>();
// We access files etc. so this should be async
channel.getApi().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, channel.getApi());
request.execute(result -> ((DiscordApiImpl) channel.getApi()).getOrCreateMessage(channel, result.getJsonBody())).whenComplete((newMessage, throwable) -> {
if (throwable != null) {
future.completeExceptionally(throwable);
} else {
future.complete(newMessage);
}
});
} catch (Throwable t) {
future.completeExceptionally(t);
}
});
return future;
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method addAttachmentAsSpoiler.
@Override
public void addAttachmentAsSpoiler(File file) {
if (file == null) {
throw new IllegalArgumentException("file cannot be null!");
}
attachments.add(new FileContainer(file, true));
attachmentsChanged = true;
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method addAttachment.
@Override
public void addAttachment(File file) {
if (file == null) {
throw new IllegalArgumentException("file cannot be null!");
}
attachments.add(new FileContainer(file));
attachmentsChanged = true;
}
use of org.javacord.core.util.FileContainer in project Javacord by BtoBastian.
the class MessageBuilderBaseDelegateImpl method addAttachment.
@Override
public void addAttachment(URL url) {
if (url == null) {
throw new IllegalArgumentException("url cannot be null!");
}
attachments.add(new FileContainer(url));
attachmentsChanged = true;
}
Aggregations