Search in sources :

Example 1 with GatewayBotResponse

use of sx.blah.discord.api.internal.json.responses.GatewayBotResponse in project Discord4J by Discord4J.

the class ClientBuilder method build.

/**
 * Creates a {@link IDiscordClient} with the configuration specified by this builder.
 *
 * @return The new client with the configuration specified by this builder.
 */
public IDiscordClient build() {
    if (botToken == null)
        throw new DiscordException("No login info present!");
    if (withRecommendedShardCount && shard != null)
        throw new DiscordException("Cannot use recommend shard count options with a specific shard!");
    if (withRecommendedShardCount) {
        GatewayBotResponse response = Requests.GENERAL_REQUESTS.GET.makeRequest(DiscordEndpoints.GATEWAY + "/bot", GatewayBotResponse.class, new BasicNameValuePair("Authorization", "Bot " + botToken), new BasicNameValuePair("Content-Type", "application/json"));
        shardCount = response.shards;
    }
    final IDiscordClient client = new DiscordClientImpl(botToken, shard != null ? -1 : shardCount, isDaemon, maxMissedPings, maxReconnectAttempts, retryCount, maxCacheCount, provider, shard, backpressureHandler, minimumPoolSize, maximumPoolSize, overflowCapacity, eventThreadTimeout, eventThreadTimeoutUnit, new PresenceUpdateRequest(status, activity, text, streamUrl));
    // Registers events as soon as client is initialized
    final EventDispatcher dispatcher = client.getDispatcher();
    iListeners.forEach(dispatcher::registerListener);
    listeners.forEach(dispatcher::registerListener);
    listenerClasses.forEach(dispatcher::registerListener);
    return client;
}
Also used : EventDispatcher(sx.blah.discord.api.events.EventDispatcher) PresenceUpdateRequest(sx.blah.discord.api.internal.json.requests.PresenceUpdateRequest) GatewayBotResponse(sx.blah.discord.api.internal.json.responses.GatewayBotResponse) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) DiscordException(sx.blah.discord.util.DiscordException) DiscordClientImpl(sx.blah.discord.api.internal.DiscordClientImpl)

Aggregations

BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 EventDispatcher (sx.blah.discord.api.events.EventDispatcher)1 DiscordClientImpl (sx.blah.discord.api.internal.DiscordClientImpl)1 PresenceUpdateRequest (sx.blah.discord.api.internal.json.requests.PresenceUpdateRequest)1 GatewayBotResponse (sx.blah.discord.api.internal.json.responses.GatewayBotResponse)1 DiscordException (sx.blah.discord.util.DiscordException)1