Search in sources :

Example 21 with RestRequest

use of org.javacord.core.util.rest.RestRequest in project Javacord by BtoBastian.

the class CustomEmojiUpdaterDelegateImpl method update.

@Override
public CompletableFuture<Void> update() {
    // Server settings
    boolean patchEmoji = false;
    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (name != null) {
        body.put("name", name);
        patchEmoji = true;
    }
    if (updateWhitelist) {
        if (whitelist == null) {
            body.putNull("roles");
        } else {
            ArrayNode jsonRoles = body.putArray("roles");
            whitelist.stream().map(Role::getIdAsString).forEach(jsonRoles::add);
        }
        patchEmoji = true;
    }
    // Only make a REST call, if we really want to update something
    if (patchEmoji) {
        return new RestRequest<Void>(emoji.getApi(), RestMethod.PATCH, RestEndpoint.CUSTOM_EMOJI).setUrlParameters(emoji.getServer().getIdAsString(), emoji.getIdAsString()).setBody(body).setAuditLogReason(reason).execute(result -> null);
    }
    return CompletableFuture.completedFuture(null);
}
Also used : RestRequest(org.javacord.core.util.rest.RestRequest) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 22 with RestRequest

use of org.javacord.core.util.rest.RestRequest in project Javacord by BtoBastian.

the class RoleBuilderDelegateImpl method create.

@Override
public CompletableFuture<Role> create() {
    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (name != null) {
        body.put("name", name);
    }
    if (permissions != null) {
        body.put("permissions", permissions.getAllowedBitmask());
    }
    if (color != null) {
        body.put("color", color.getRGB() & 0xFFFFFF);
    }
    body.put("mentionable", mentionable);
    body.put("hoist", displaySeparately);
    return new RestRequest<Role>(server.getApi(), RestMethod.POST, RestEndpoint.ROLE).setUrlParameters(server.getIdAsString()).setBody(body).setAuditLogReason(reason).execute(result -> server.getOrCreateRole(result.getJsonBody()));
}
Also used : RestRequest(org.javacord.core.util.rest.RestRequest) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Aggregations

RestRequest (org.javacord.core.util.rest.RestRequest)22 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)16 CompletableFuture (java.util.concurrent.CompletableFuture)13 RestEndpoint (org.javacord.core.util.rest.RestEndpoint)11 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)9 FileContainer (org.javacord.core.util.FileContainer)9 RestMethod (org.javacord.core.util.rest.RestMethod)9 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 ArrayList (java.util.ArrayList)7 DiscordApiImpl (org.javacord.core.DiscordApiImpl)7 BufferedImage (java.awt.image.BufferedImage)6 File (java.io.File)6 InputStream (java.io.InputStream)6 URL (java.net.URL)6 Icon (org.javacord.api.entity.Icon)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Base64 (java.util.Base64)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Message (org.javacord.api.entity.message.Message)5