Search in sources :

Example 6 with EventDispatcher

use of sx.blah.discord.api.events.EventDispatcher 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

EventDispatcher (sx.blah.discord.api.events.EventDispatcher)6 DiscordException (sx.blah.discord.util.DiscordException)3 File (java.io.File)2 ConsoleCommandExecutor (com.cloudcraftgaming.discal.bot.internal.consolecommand.ConsoleCommandExecutor)1 ReadyEventListener (com.cloudcraftgaming.discal.bot.listeners.ReadyEventListener)1 Config (com.github.vaerys.pogos.Config)1 GlobalData (com.github.vaerys.pogos.GlobalData)1 DiscordListener (com.solinia.solinia.Listeners.DiscordListener)1 MessageListener (io.github.spugn.Sargo.Listeners.MessageListener)1 ReadyListener (io.github.spugn.Sargo.Listeners.ReadyListener)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 IDiscordClient (sx.blah.discord.api.IDiscordClient)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