use of lavalink.client.io.jda.JdaLavalink in project Bean by Xirado.
the class JDAReadyListener method onGuildReady.
@Override
public void onGuildReady(@NotNull GuildReadyEvent event) {
if (ready)
return;
ready = true;
Bean.getInstance().getExecutor().submit(() -> {
LOGGER.info("Successfully started {} shards!", Bean.getInstance().getShardManager().getShards().size());
Bean.getInstance().getInteractionCommandHandler().initialize();
if (Bean.getInstance().isDebug())
LOGGER.warn("Development mode enabled.");
Bean.getInstance().initCommandCheck();
JdaLavalink lavalink = Bean.getInstance().getLavalink();
lavalink.setJdaProvider((shard) -> Bean.getInstance().getShardManager().getShardById(shard));
lavalink.setUserId(event.getJDA().getSelfUser().getId());
DataObject config = Bean.getInstance().getConfig();
DataArray nodes = config.optArray("lavalink_nodes").orElse(DataArray.empty());
nodes.stream(DataArray::getObject).forEach(node -> {
String url = node.getString("url");
String password = node.getString("password");
try {
lavalink.addNode(new URI(url), password);
} catch (URISyntaxException e) {
LOGGER.error("Could not add Lavalink node!", e);
}
});
});
}
use of lavalink.client.io.jda.JdaLavalink in project Robertify-Bot by bombies.
the class Robertify method main.
public static void main(String[] args) {
WebUtils.setUserAgent("Mozilla/Robertify / bombies#4445");
try {
lavalink = new JdaLavalink(getIdFromToken(Config.getBotToken()), Config.getShardCount(), shardId -> Robertify.getShardManager().getShardById(shardId));
for (var node : Config.getLavaNodes()) lavalink.addNode(node.getURI(), node.getPassword());
lavalink.getLoadBalancer().addPenalty(LavalinkLoadBalancer.Penalties::getPlayerPenalty);
lavalink.getLoadBalancer().addPenalty(LavalinkLoadBalancer.Penalties::getCpuPenalty);
var thread = new ThreadFactoryBuilder().setNameFormat("RobertifyShutdownHook").build();
Runtime.getRuntime().addShutdownHook(thread.newThread(() -> {
logger.info("Destroying all players (If any left)");
shardManager.getGuildCache().stream().filter(guild -> guild.getSelfMember().getVoiceState().inVoiceChannel()).forEach(guild -> {
GuildMusicManager musicManager = RobertifyAudioManager.getInstance().getMusicManager(guild);
ResumeUtils.getInstance().saveInfo(guild, guild.getSelfMember().getVoiceState().getChannel());
musicManager.getScheduler().scheduleDisconnect(false, 0, TimeUnit.SECONDS);
});
shardManager.shutdown();
}));
DefaultShardManagerBuilder jdaBuilder = DefaultShardManagerBuilder.createDefault(Config.getBotToken(), GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES).setShardsTotal(Config.getShardCount()).setBulkDeleteSplittingEnabled(false).setChunkingFilter(ChunkingFilter.NONE).setMemberCachePolicy(MemberCachePolicy.VOICE).addEventListeners(lavalink, VoiceChannelEvents.waiter, commandWaiter, new Listener(), new VoiceChannelEvents(), new DedicatedChannelEvents(), new PollEvents(), new SuggestionCategoryDeletionEvents(), new ReportsEvents(), new AnnouncementChannelEvents(), new LogChannelEvents(), new SkipCommand()).setVoiceDispatchInterceptor(lavalink.getVoiceInterceptor()).addEventListeners(new MenuPaginationTestCommand()).addEventListeners(new PaginationEvents()).enableCache(CacheFlag.VOICE_STATE).disableCache(CacheFlag.ACTIVITY, CacheFlag.EMOTE, CacheFlag.CLIENT_STATUS, CacheFlag.ROLE_TAGS, CacheFlag.ONLINE_STATUS).disableIntents(GatewayIntent.DIRECT_MESSAGE_TYPING, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_INVITES, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_TYPING, GatewayIntent.GUILD_PRESENCES, GatewayIntent.DIRECT_MESSAGE_REACTIONS).setGatewayEncoding(GatewayEncoding.ETF).setActivity(Activity.listening("Starting up..."));
// Register all slash commands
SlashCommandManager slashCommandManager = new SlashCommandManager();
for (var cmd : slashCommandManager.getCommands()) jdaBuilder.addEventListeners(cmd);
for (var cmd : slashCommandManager.getDevCommands()) jdaBuilder.addEventListeners(cmd);
// Initialize the JSON directory
// This is a deprecated feature and is marked for removal
// Until everything is fully removed, this method needs to be enabled
// For a proper first-boot.
AbstractJSONFile.initDirectory();
AbstractMongoDatabase.initAllCaches();
logger.info("Initialized all caches");
new ChangeLogConfig().initConfig();
GuildDBCache.getInstance().loadAllGuilds();
logger.info("All guilds have been loaded into cache");
shardManager = jdaBuilder.build();
spotifyApi = new SpotifyApi.Builder().setClientId(Config.get(ENV.SPOTIFY_CLIENT_ID)).setClientSecret(Config.get(ENV.SPOTIFY_CLIENT_SECRET)).setRedirectUri(SpotifyHttpManager.makeUri("http://localhost/callback/")).build();
deezerApi = new DeezerApi();
initVoteSiteAPIs();
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(SpotifyAuthorizationUtils.doTokenRefresh(), 0, 1, TimeUnit.HOURS);
try {
baringo = new BaringoClient.Builder().clientAuth(Config.get(ENV.IMGUR_CLIENT), Config.get(ENV.IMGUR_SECRET)).build();
} catch (BaringoApiException e) {
logger.error("[ERROR] There was an issue building the Baringo client!", e);
}
} catch (Exception e) {
logger.error("[FATAL ERROR] An unexpected error occurred!", e);
}
}
use of lavalink.client.io.jda.JdaLavalink in project SkyBot by duncte123.
the class LavalinkManager method start.
public void start(DunctebotConfig config, AudioUtils audioUtils) {
this.config = config;
this.audioUtils = audioUtils;
if (!isEnabled()) {
return;
}
final String userId = getIdFromToken(this.config.discord.token);
lavalink = new JdaLavalink(userId, this.config.discord.totalShards, shardId -> SkyBot.getInstance().getShardManager().getShardById(shardId));
loadNodes();
}
use of lavalink.client.io.jda.JdaLavalink in project SkyBot by DuncteBot.
the class LavalinkManager method start.
public void start(DunctebotConfig config, AudioUtils audioUtils) {
this.config = config;
this.audioUtils = audioUtils;
if (!isEnabled()) {
return;
}
final String userId = getIdFromToken(this.config.discord.token);
lavalink = new JdaLavalink(userId, this.config.discord.totalShards, shardId -> SkyBot.getInstance().getShardManager().getShardById(shardId));
loadNodes();
}
Aggregations