Search in sources :

Example 1 with ServerApplicationCommandPermissionsBuilder

use of org.javacord.api.interaction.ServerApplicationCommandPermissionsBuilder in project Javacord by BtoBastian.

the class DiscordApiImpl method batchUpdateApplicationCommandPermissions.

@Override
public CompletableFuture<List<ServerApplicationCommandPermissions>> batchUpdateApplicationCommandPermissions(Server server, List<ServerApplicationCommandPermissionsBuilder> slashCommandPermissionsBuilders) {
    ArrayNode body = JsonNodeFactory.instance.arrayNode();
    for (ServerApplicationCommandPermissionsBuilder permission : slashCommandPermissionsBuilders) {
        ObjectNode node = JsonNodeFactory.instance.objectNode();
        node.put("id", permission.getCommandId());
        ArrayNode array = node.putArray("permissions");
        for (ApplicationCommandPermissions permissionPermission : permission.getPermissions()) {
            array.add(((ApplicationCommandPermissionsImpl) permissionPermission).toJsonNode());
        }
        body.add(node);
    }
    return new RestRequest<List<ServerApplicationCommandPermissions>>(server.getApi(), RestMethod.PUT, RestEndpoint.SERVER_APPLICATION_COMMAND_PERMISSIONS).setUrlParameters(String.valueOf(server.getApi().getClientId()), server.getIdAsString()).setBody(body).execute(result -> jsonToServerApplicationCommandPermissionsList(result.getJsonBody()));
}
Also used : ServerApplicationCommandPermissionsBuilder(org.javacord.api.interaction.ServerApplicationCommandPermissionsBuilder) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ServerApplicationCommandPermissions(org.javacord.api.interaction.ServerApplicationCommandPermissions) ApplicationCommandPermissions(org.javacord.api.interaction.ApplicationCommandPermissions) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ApplicationCommandPermissions (org.javacord.api.interaction.ApplicationCommandPermissions)1 ServerApplicationCommandPermissions (org.javacord.api.interaction.ServerApplicationCommandPermissions)1 ServerApplicationCommandPermissionsBuilder (org.javacord.api.interaction.ServerApplicationCommandPermissionsBuilder)1