Search in sources :

Example 1 with ServerApplicationCommandPermissions

use of org.javacord.api.interaction.ServerApplicationCommandPermissions 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)

Example 2 with ServerApplicationCommandPermissions

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

the class ApplicationCommandPermissionsUpdaterDelegateImpl method update.

@Override
public CompletableFuture<ServerApplicationCommandPermissions> update(long commandId) {
    ObjectNode body = JsonNodeFactory.instance.objectNode();
    ArrayNode array = body.putArray("permissions");
    for (ApplicationCommandPermissions permission : permissions) {
        array.add(((ApplicationCommandPermissionsImpl) permission).toJsonNode());
    }
    return new RestRequest<ServerApplicationCommandPermissions>(server.getApi(), RestMethod.PUT, RestEndpoint.APPLICATION_COMMAND_PERMISSIONS).setUrlParameters(String.valueOf(server.getApi().getClientId()), server.getIdAsString(), String.valueOf(commandId)).setBody(body).execute(result -> new ServerApplicationCommandPermissionsImpl((DiscordApiImpl) server.getApi(), result.getJsonBody()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DiscordApiImpl(org.javacord.core.DiscordApiImpl) ApplicationCommandPermissions(org.javacord.api.interaction.ApplicationCommandPermissions) ServerApplicationCommandPermissions(org.javacord.api.interaction.ServerApplicationCommandPermissions) ServerApplicationCommandPermissions(org.javacord.api.interaction.ServerApplicationCommandPermissions) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

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