All Downloads are FREE. Search and download functionalities are using the official Maven repository.

discord4j.rest.service.ApplicationService Maven / Gradle / Ivy

/*
 * This file is part of Discord4J.
 *
 * Discord4J is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Discord4J is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Discord4J.  If not, see .
 */
package discord4j.rest.service;

import discord4j.discordjson.json.*;
import discord4j.rest.request.Router;
import discord4j.rest.route.Routes;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

public class ApplicationService extends RestService {

    public ApplicationService(Router router) {
        super(router);
    }

    public Mono getCurrentApplicationInfo() {
        return Routes.APPLICATION_INFO_GET.newRequest()
                .exchange(getRouter())
                .bodyToMono(ApplicationInfoData.class);
    }

    public Flux getGlobalApplicationCommands(long applicationId) {
        return Routes.GLOBAL_APPLICATION_COMMANDS_GET.newRequest(applicationId)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData[].class)
            .flatMapMany(Flux::fromArray);
    }

    public Mono createGlobalApplicationCommand(long applicationId, ApplicationCommandRequest request) {
        return Routes.GLOBAL_APPLICATION_COMMANDS_CREATE.newRequest(applicationId)
            .body(request)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData.class);
    }

    public Flux bulkOverwriteGlobalApplicationCommand(long applicationId, List requests) {
        return Routes.GLOBAL_APPLICATION_COMMANDS_BULK_OVERWRITE.newRequest(applicationId)
                .body(requests)
                .exchange(getRouter())
                .bodyToMono(ApplicationCommandData[].class)
                .flatMapMany(Flux::fromArray);
    }

    public Mono getGlobalApplicationCommand(long applicationId, long commandId) {
        return Routes.GLOBAL_APPLICATION_COMMAND_GET.newRequest(applicationId, commandId)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData.class);
    }

    public Mono modifyGlobalApplicationCommand(long applicationId, long commandId,
                                                                       ApplicationCommandRequest request) {
        return Routes.GLOBAL_APPLICATION_COMMAND_MODIFY.newRequest(applicationId, commandId)
            .body(request)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData.class);
    }

    public Mono deleteGlobalApplicationCommand(long applicationId, long commandId) {
        return Routes.GLOBAL_APPLICATION_COMMAND_DELETE.newRequest(applicationId, commandId)
            .exchange(getRouter())
            .bodyToMono(Void.class);
    }

    public Flux getGuildApplicationCommands(long applicationId, long guildId) {
        return Routes.GUILD_APPLICATION_COMMANDS_GET.newRequest(applicationId, guildId)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData[].class)
            .flatMapMany(Flux::fromArray);
    }

    public Mono createGuildApplicationCommand(long applicationId, long guildId,
                                                                      ApplicationCommandRequest request) {
        return Routes.GUILD_APPLICATION_COMMANDS_CREATE.newRequest(applicationId, guildId)
            .body(request)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData.class);
    }

    public Flux bulkOverwriteGuildApplicationCommand(long applicationId, long guildId,
                                                                             List requests) {
        return Routes.GUILD_APPLICATION_COMMANDS_BULK_OVERWRITE.newRequest(applicationId, guildId)
                .body(requests)
                .exchange(getRouter())
                .bodyToMono(ApplicationCommandData[].class)
                .flatMapMany(Flux::fromArray);
    }

    public Mono getGuildApplicationCommand(long applicationId, long guildId, long commandId) {
        return Routes.GUILD_APPLICATION_COMMAND_GET.newRequest(applicationId, guildId, commandId)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData.class);
    }

    public Mono modifyGuildApplicationCommand(long applicationId, long guildId, long commandId,
                                                                      ApplicationCommandRequest request) {
        return Routes.GUILD_APPLICATION_COMMAND_MODIFY.newRequest(applicationId, guildId, commandId)
            .body(request)
            .exchange(getRouter())
            .bodyToMono(ApplicationCommandData.class);
    }

    public Mono deleteGuildApplicationCommand(long applicationId, long guildId, long commandId) {
        return Routes.GUILD_APPLICATION_COMMAND_DELETE.newRequest(applicationId, guildId, commandId)
            .exchange(getRouter())
            .bodyToMono(Void.class);
    }

    public Flux getGuildApplicationCommandPermissions(long applicationId,
                                                                                              long guildId) {
        return Routes.GUILD_APPLICATION_COMMAND_PERMISSIONS_GET.newRequest(applicationId, guildId)
                .exchange(getRouter())
                .bodyToMono(GuildApplicationCommandPermissionsData[].class)
                .flatMapMany(Flux::fromArray);
    }

    public Mono getApplicationCommandPermissions(long applicationId, long guildId,
                                                                                         long commandId) {
        return Routes.APPLICATION_COMMAND_PERMISSIONS_GET.newRequest(applicationId, guildId, commandId)
                .exchange(getRouter())
                .bodyToMono(GuildApplicationCommandPermissionsData.class);
    }

    public Mono modifyApplicationCommandPermissions(long applicationId, long guildId,
                                                          long commandId,
                                                          ApplicationCommandPermissionsRequest request) {
        return Routes.APPLICATION_COMMAND_PERMISSIONS_MODIFY.newRequest(applicationId, guildId, commandId)
                .body(request)
                .exchange(getRouter())
                .bodyToMono(GuildApplicationCommandPermissionsData.class);
    }

    public Flux bulkModifyApplicationCommandPermissions(long applicationId, long guildId,
                                                              List permissions) {
        return Routes.APPLICATION_COMMAND_PERMISSIONS_BULK_MODIFY.newRequest(applicationId, guildId)
            .body(permissions)
            .exchange(getRouter())
            .bodyToMono(GuildApplicationCommandPermissionsData[].class)
            .flatMapMany(Flux::fromArray);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy