Search in sources :

Example 1 with GatewayJSON

use of io.discloader.discloader.network.json.GatewayJSON in project DiscLoader by R3alCl0ud.

the class DiscLoader method login.

/**
 * Connects the current instance of the {@link DiscLoader loader} into Discord's
 * gateway servers
 *
 * @param token
 *            your API token
 * @return A CompletableFuture that completes with {@code this} if successful.
 */
public CompletableFuture<DiscLoader> login(String token) {
    if (rf != null && rf.isCompletedExceptionally())
        return rf;
    LOG.info("Attempting to login");
    rf = new CompletableFuture<>();
    Command.registerCommands();
    this.token = token;
    CompletableFuture<GatewayJSON> cf = rest.request(Methods.GET, Endpoints.gateway, new RESTOptions(), GatewayJSON.class);
    cf.thenAcceptAsync(gateway -> {
        try {
            socket.connectSocket(gateway.url + DLUtil.GatewaySuffix);
        } catch (Exception e) {
            rf.completeExceptionally(e);
        }
    });
    cf.exceptionally(e -> {
        rf.completeExceptionally(e);
        return null;
    });
    return rf;
}
Also used : RESTOptions(io.discloader.discloader.network.rest.RESTOptions) GatewayJSON(io.discloader.discloader.network.json.GatewayJSON) GuildSyncException(io.discloader.discloader.common.exceptions.GuildSyncException) UnauthorizedException(io.discloader.discloader.common.exceptions.UnauthorizedException) AccountTypeException(io.discloader.discloader.common.exceptions.AccountTypeException)

Aggregations

AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 GuildSyncException (io.discloader.discloader.common.exceptions.GuildSyncException)1 UnauthorizedException (io.discloader.discloader.common.exceptions.UnauthorizedException)1 GatewayJSON (io.discloader.discloader.network.json.GatewayJSON)1 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)1