use of net.dv8tion.jda.bot.sharding.ShardManager 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;
}
Aggregations