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);
}
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()));
}
Aggregations