Search in sources :

Example 1 with SkipCommand

use of main.commands.prefixcommands.audio.SkipCommand 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);
    }
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DeezerApi(api.deezer.DeezerApi) Getter(lombok.Getter) DefaultShardManagerBuilder(net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder) BaringoApiException(com.github.kskelm.baringo.util.BaringoApiException) LoggerFactory(org.slf4j.LoggerFactory) ChangeLogConfig(main.utils.json.changelog.ChangeLogConfig) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) LavalinkLoadBalancer(lavalink.client.io.LavalinkLoadBalancer) SlashCommandManager(main.commands.slashcommands.SlashCommandManager) GuildDBCache(main.utils.database.mongodb.cache.GuildDBCache) GatewayIntent(net.dv8tion.jda.api.requests.GatewayIntent) RobertifyAudioManager(main.audiohandlers.RobertifyAudioManager) SpotifyHttpManager(se.michaelthelin.spotify.SpotifyHttpManager) SkipCommand(main.commands.prefixcommands.audio.SkipCommand) AbstractJSONFile(main.utils.json.AbstractJSONFile) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ReportsEvents(main.commands.prefixcommands.util.reports.ReportsEvents) DiscordBotListAPI(org.discordbots.api.client.DiscordBotListAPI) SuggestionCategoryDeletionEvents(main.events.SuggestionCategoryDeletionEvents) CacheFlag(net.dv8tion.jda.api.utils.cache.CacheFlag) LogChannelEvents(main.events.LogChannelEvents) SpotifyAuthorizationUtils(main.utils.spotify.SpotifyAuthorizationUtils) DedicatedChannelEvents(main.commands.slashcommands.commands.management.dedicatedchannel.DedicatedChannelEvents) MemberCachePolicy(net.dv8tion.jda.api.utils.MemberCachePolicy) ShardManager(net.dv8tion.jda.api.sharding.ShardManager) Logger(org.slf4j.Logger) PollEvents(main.commands.slashcommands.commands.misc.poll.PollEvents) AbstractMongoDatabase(main.utils.database.mongodb.AbstractMongoDatabase) GatewayEncoding(net.dv8tion.jda.api.GatewayEncoding) AnnouncementChannelEvents(main.events.AnnouncementChannelEvents) JdaLavalink(lavalink.client.io.jda.JdaLavalink) Activity(net.dv8tion.jda.api.entities.Activity) GuildMusicManager(main.audiohandlers.GuildMusicManager) MenuPaginationTestCommand(main.commands.prefixcommands.dev.test.MenuPaginationTestCommand) VoiceChannelEvents(main.events.VoiceChannelEvents) Executors(java.util.concurrent.Executors) ResumeUtils(main.utils.resume.ResumeUtils) SpotifyApi(se.michaelthelin.spotify.SpotifyApi) TimeUnit(java.util.concurrent.TimeUnit) Base64(java.util.Base64) DBLApi(main.utils.votes.api.discordbotlist.DBLApi) BaringoClient(com.github.kskelm.baringo.BaringoClient) PaginationEvents(main.utils.pagination.PaginationEvents) ENV(main.constants.ENV) WebUtils(me.duncte123.botcommons.web.WebUtils) ChunkingFilter(net.dv8tion.jda.api.utils.ChunkingFilter) ChangeLogConfig(main.utils.json.changelog.ChangeLogConfig) DefaultShardManagerBuilder(net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder) ReportsEvents(main.commands.prefixcommands.util.reports.ReportsEvents) SpotifyApi(se.michaelthelin.spotify.SpotifyApi) SuggestionCategoryDeletionEvents(main.events.SuggestionCategoryDeletionEvents) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) VoiceChannelEvents(main.events.VoiceChannelEvents) DeezerApi(api.deezer.DeezerApi) LogChannelEvents(main.events.LogChannelEvents) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GuildMusicManager(main.audiohandlers.GuildMusicManager) SkipCommand(main.commands.prefixcommands.audio.SkipCommand) MenuPaginationTestCommand(main.commands.prefixcommands.dev.test.MenuPaginationTestCommand) DedicatedChannelEvents(main.commands.slashcommands.commands.management.dedicatedchannel.DedicatedChannelEvents) AnnouncementChannelEvents(main.events.AnnouncementChannelEvents) BaringoApiException(com.github.kskelm.baringo.util.BaringoApiException) BaringoClient(com.github.kskelm.baringo.BaringoClient) JdaLavalink(lavalink.client.io.jda.JdaLavalink) PollEvents(main.commands.slashcommands.commands.misc.poll.PollEvents) PaginationEvents(main.utils.pagination.PaginationEvents) SlashCommandManager(main.commands.slashcommands.SlashCommandManager) BaringoApiException(com.github.kskelm.baringo.util.BaringoApiException)

Example 2 with SkipCommand

use of main.commands.prefixcommands.audio.SkipCommand in project Robertify-Bot by bombies.

the class SkipSlashCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    if (!nameCheck(event))
        return;
    if (!banCheck(event))
        return;
    if (!restrictedChannelCheck(event))
        return;
    event.deferReply().queue();
    final var selfVoiceState = event.getGuild().getSelfMember().getVoiceState();
    final var memberVoiceState = event.getMember().getVoiceState();
    if (!musicCommandDJCheck(event)) {
        if (!selfVoiceState.inVoiceChannel()) {
            event.getHook().sendMessageEmbeds(RobertifyEmbedUtils.embedMessage(event.getGuild(), "I must be in a voice channel before this command can be executed!").build()).setEphemeral(true).queue();
            return;
        }
        if (selfVoiceState.getChannel().getMembers().size() != 2) {
            MessageEmbed embed = new SkipCommand().handleVoteSkip(event.getTextChannel(), selfVoiceState, memberVoiceState);
            if (embed != null) {
                event.getHook().sendMessageEmbeds(embed).setEphemeral(false).queue();
            } else {
                event.getHook().sendMessageEmbeds(RobertifyEmbedUtils.embedMessage(event.getGuild(), "Started a vote skip!").build()).setEphemeral(true).queue();
            }
            sendRandomMessage(event);
            return;
        }
    }
    if (event.getOptions().isEmpty()) {
        event.getHook().sendMessageEmbeds(new SkipCommand().handleSkip(selfVoiceState, memberVoiceState)).setEphemeral(false).queue();
    } else {
        final var musicManager = RobertifyAudioManager.getInstance().getMusicManager(event.getGuild());
        final ConcurrentLinkedQueue<AudioTrack> queue = musicManager.getScheduler().queue;
        final int tracksToSkip = GeneralUtils.longToInt(event.getOption("trackstoskip").getAsLong());
        event.getHook().sendMessageEmbeds(new SkipToCommand().handleSkip(event.getUser(), queue, musicManager, tracksToSkip).build()).setEphemeral(false).queue();
    }
    sendRandomMessage(event);
}
Also used : MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) SkipCommand(main.commands.prefixcommands.audio.SkipCommand) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) SkipToCommand(main.commands.prefixcommands.audio.SkipToCommand)

Aggregations

SkipCommand (main.commands.prefixcommands.audio.SkipCommand)2 DeezerApi (api.deezer.DeezerApi)1 BaringoClient (com.github.kskelm.baringo.BaringoClient)1 BaringoApiException (com.github.kskelm.baringo.util.BaringoApiException)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 Base64 (java.util.Base64)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 LavalinkLoadBalancer (lavalink.client.io.LavalinkLoadBalancer)1 JdaLavalink (lavalink.client.io.jda.JdaLavalink)1 Getter (lombok.Getter)1 GuildMusicManager (main.audiohandlers.GuildMusicManager)1 RobertifyAudioManager (main.audiohandlers.RobertifyAudioManager)1 SkipToCommand (main.commands.prefixcommands.audio.SkipToCommand)1 MenuPaginationTestCommand (main.commands.prefixcommands.dev.test.MenuPaginationTestCommand)1 ReportsEvents (main.commands.prefixcommands.util.reports.ReportsEvents)1 SlashCommandManager (main.commands.slashcommands.SlashCommandManager)1