Search in sources :

Example 1 with DefaultShardManagerBuilder

use of net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder in project FlareBot by FlareBot.

the class FlareBot method init.

public void init() throws InterruptedException {
    LOGGER.info("Starting init!");
    manager = new FlareBotManager();
    Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
    Metrics.setup();
    RestAction.DEFAULT_FAILURE = t -> {
        if (t instanceof ErrorResponseException) {
            ErrorResponseException e = (ErrorResponseException) t;
            Metrics.failedRestActions.labels(String.valueOf(e.getErrorCode())).inc();
            if (// Socket timeout
            e.getErrorCode() == -1)
                return;
        }
        LOGGER.warn("Failed RestAction", t);
    };
    events = new Events(this);
    LOGGER.info("Starting builders");
    try {
        shardManager = new DefaultShardManagerBuilder().addEventListeners(events).addEventListeners(new ModlogEvents()).addEventListeners(Metrics.instance().jdaEventMetricsListener).addEventListeners(new NINOListener()).setToken(config.getString("bot.token").get()).setAudioSendFactory(new NativeAudioSendFactory()).setWebsocketFactory(new WebSocketFactory(new WebSocketListener())).setShardsTotal(-1).setHttpClientBuilder(client.newBuilder()).setBulkDeleteSplittingEnabled(false).build();
        commandManager = new CommandManager();
    } catch (Exception e) {
        LOGGER.error("Could not log in!", e);
        Thread.sleep(500);
        System.exit(1);
        return;
    }
    System.setErr(new PrintStream(new OutputStream() {

        // Nothing really so all good.
        @Override
        public void write(int b) {
        }
    }));
    // No operation STDERR. Will not do much of anything, except to filter out some Jsoup spam
    manager = new FlareBotManager();
    manager.executeCreations();
}
Also used : WebSocketListener(stream.flarebot.flarebot.ws.WebSocketListener) PrintStream(java.io.PrintStream) NativeAudioSendFactory(com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) ErrorResponseException(net.dv8tion.jda.core.exceptions.ErrorResponseException) IOException(java.io.IOException) UnknownBindingException(com.arsenarsen.lavaplayerbridge.libraries.UnknownBindingException) DefaultShardManagerBuilder(net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder) WebSocketFactory(stream.flarebot.flarebot.ws.WebSocketFactory) ErrorResponseException(net.dv8tion.jda.core.exceptions.ErrorResponseException) NINOListener(stream.flarebot.flarebot.mod.nino.NINOListener)

Example 2 with DefaultShardManagerBuilder

use of net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder in project FredBoat by Frederikam.

the class ShardManagerConfiguration method buildShardManager.

// we manage the lifecycle ourselves tyvm, see shutdown hook below
@Bean(destroyMethod = "")
public ShardManager buildShardManager(ConfigPropertiesProvider configProvider, EventListenerBoat mainEventListener, AudioConnectionFacade audioConnectionFacade, SessionController sessionController, EventLogger eventLogger, JdaEventsMetricsListener jdaEventsMetricsListener, ShardReviveHandler shardReviveHandler, MusicPersistenceHandler musicPersistenceHandler, ShutdownHandler shutdownHandler) {
    DefaultShardManagerBuilder builder = new DefaultShardManagerBuilder().setToken(configProvider.getCredentials().getBotToken()).setGame(Game.playing(configProvider.getAppConfig().getStatus())).setBulkDeleteSplittingEnabled(false).setEnableShutdownHook(false).setAudioEnabled(true).setAutoReconnect(true).setSessionController(sessionController).setContextEnabled(false).setHttpClientBuilder(Http.DEFAULT_BUILDER.newBuilder().eventListener(new OkHttpEventMetrics("jda", Metrics.httpEventCounter))).addEventListeners(mainEventListener).addEventListeners(jdaEventsMetricsListener).addEventListeners(eventLogger).addEventListeners(shardReviveHandler).addEventListeners(musicPersistenceHandler).addEventListeners(audioConnectionFacade).setShardsTotal(configProvider.getCredentials().getRecommendedShardCount());
    if (!System.getProperty("os.arch").equalsIgnoreCase("arm") && !System.getProperty("os.arch").equalsIgnoreCase("arm-linux")) {
        builder.setAudioSendFactory(new NativeAudioSendFactory(800));
    }
    ShardManager shardManager;
    try {
        shardManager = builder.build();
    } catch (LoginException e) {
        throw new RuntimeException("Failed to log in to Discord! Is your token invalid?", e);
    }
    Runtime.getRuntime().addShutdownHook(new Thread(createShardManagerShutdownHook(shutdownHandler, musicPersistenceHandler, shardManager), "shardmanager-shutdown-hook"));
    return shardManager;
}
Also used : NativeAudioSendFactory(com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory) DefaultShardManagerBuilder(net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder) LoginException(javax.security.auth.login.LoginException) ShardManager(net.dv8tion.jda.bot.sharding.ShardManager) OkHttpEventMetrics(fredboat.metrics.OkHttpEventMetrics) Bean(org.springframework.context.annotation.Bean)

Aggregations

NativeAudioSendFactory (com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory)2 DefaultShardManagerBuilder (net.dv8tion.jda.bot.sharding.DefaultShardManagerBuilder)2 UnknownBindingException (com.arsenarsen.lavaplayerbridge.libraries.UnknownBindingException)1 OkHttpEventMetrics (fredboat.metrics.OkHttpEventMetrics)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 LoginException (javax.security.auth.login.LoginException)1 ShardManager (net.dv8tion.jda.bot.sharding.ShardManager)1 ErrorResponseException (net.dv8tion.jda.core.exceptions.ErrorResponseException)1 Bean (org.springframework.context.annotation.Bean)1 NINOListener (stream.flarebot.flarebot.mod.nino.NINOListener)1 WebSocketFactory (stream.flarebot.flarebot.ws.WebSocketFactory)1 WebSocketListener (stream.flarebot.flarebot.ws.WebSocketListener)1