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