Search in sources :

Example 1 with AudioPlayer

use of com.sedmelluq.discord.lavaplayer.player.AudioPlayer in project Ardent by adamint.

the class Volume method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    AudioManager audioManager = guild.getAudioManager();
    if (audioManager.isConnected()) {
        GuildMusicManager guildMusicManager = getGuildAudioPlayer(guild, channel);
        AudioPlayer player = guildMusicManager.player;
        if (args.length == 1) {
            sendTranslatedMessage("The current player volume is " + player.getVolume(), sendTo(channel, guild), user);
        } else {
            if (UserUtils.hasTierOnePermissions(user) || EntityGuild.get(guild).isPremium()) {
                try {
                    int volume = Integer.parseInt(args[1]);
                    player.setVolume(volume);
                    sendTranslatedMessage("Set player volume to " + volume, sendTo(channel, guild), user);
                } catch (NumberFormatException ex) {
                    sendTranslatedMessage("That's not a number!", channel, user);
                }
            } else
                sendTranslatedMessage("You must be a patron to do this! To help us out and get this perk, pledge even " + "a dollar a month at https://patreon.com/ardent", channel, user);
        }
    } else
        sendTranslatedMessage("I'm not in a voice channel!", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Music.getGuildAudioPlayer(tk.ardentbot.commands.music.Music.getGuildAudioPlayer)

Example 2 with AudioPlayer

use of com.sedmelluq.discord.lavaplayer.player.AudioPlayer in project Ardent by adamint.

the class Music method checkMusicConnections.

public static void checkMusicConnections() {
    for (Shard shard : ShardManager.getShards()) {
        shard.executorService.scheduleAtFixedRate(() -> {
            try {
                for (Guild guild : shard.jda.getGuilds()) {
                    GuildMusicManager manager = getGuildAudioPlayer(guild, null, shard);
                    if (manager != null) {
                        GuildVoiceState voiceState = guild.getSelfMember().getVoiceState();
                        if (voiceState.inVoiceChannel()) {
                            TextChannel channel = manager.scheduler.manager.getChannel();
                            if (channel == null)
                                channel = guild.getPublicChannel();
                            if (channel != null) {
                                if (channel.canTalk()) {
                                    VoiceChannel voiceChannel = voiceState.getChannel();
                                    AudioPlayer player = manager.player;
                                    if (voiceState.isGuildMuted()) {
                                        shard.help.sendTranslatedMessage("Pausing player now because I'm muted", channel, null);
                                        player.setPaused(true);
                                    }
                                    if (voiceChannel.getMembers().size() == 1 && !EntityGuild.get(guild).isPremium()) {
                                        shard.help.sendTranslatedMessage("Left {0} because no one was in the channel!".replace("{0}", voiceChannel.getName()), channel, null);
                                        guild.getAudioManager().closeAudioConnection();
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                new BotException(ex);
            }
        }, 5, 5, TimeUnit.MINUTES);
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) BotException(tk.ardentbot.core.misc.logging.BotException) Shard(tk.ardentbot.main.Shard) EntityGuild(tk.ardentbot.utils.rpg.EntityGuild) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) SQLException(java.sql.SQLException) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 3 with AudioPlayer

use of com.sedmelluq.discord.lavaplayer.player.AudioPlayer in project MantaroBot by Mantaro.

the class VoiceLeave method run.

@Override
public void run() {
    MantaroBot.getInstance().getAudioManager().getMusicManagers().forEach((guildId, manager) -> {
        try {
            Guild guild = MantaroBot.getInstance().getGuildById(guildId);
            if (guild == null)
                return;
            GuildVoiceState voiceState = guild.getSelfMember().getVoiceState();
            if (voiceState == null)
                return;
            if (voiceState.inVoiceChannel()) {
                TextChannel channel = guild.getPublicChannel();
                if (channel != null) {
                    if (channel.canTalk()) {
                        VoiceChannel voiceChannel = voiceState.getChannel();
                        AudioPlayer player = manager.getAudioPlayer();
                        GuildMusicManager mm = MantaroBot.getInstance().getAudioManager().getMusicManager(guild);
                        if (player == null || mm == null || voiceChannel == null)
                            return;
                        if (mm.getTrackScheduler().getCurrentTrack().getRequestedChannel() != null) {
                            channel = mm.getTrackScheduler().getCurrentTrack().getRequestedChannel();
                        }
                        if (voiceState.isGuildMuted()) {
                            channel.sendMessage(EmoteReference.SAD + "Pausing player because I got muted :(").queue();
                            player.setPaused(true);
                        }
                        if (voiceChannel.getMembers().size() == 1) {
                            channel.sendMessage(EmoteReference.THINKING + "I decided to leave **" + voiceChannel.getName() + "** " + "because I was left all " + "alone :<").queue();
                            if (mm.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null) {
                                mm.getTrackScheduler().getAudioPlayer().getPlayingTrack().stop();
                                mm.getTrackScheduler().getQueue().clear();
                                mm.getTrackScheduler().next(true);
                            } else {
                                guild.getAudioManager().closeAudioConnection();
                            }
                        }
                    }
                }
            }
        } catch (Exception ignored) {
        }
    });
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) GuildVoiceState(net.dv8tion.jda.core.entities.GuildVoiceState) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Guild(net.dv8tion.jda.core.entities.Guild)

Example 4 with AudioPlayer

use of com.sedmelluq.discord.lavaplayer.player.AudioPlayer in project Ardent by adamint.

the class StuckVoiceConnection method run.

@Override
public void run() {
    for (Shard shard : getShards()) {
        for (Guild guild : shard.jda.getGuilds()) {
            GuildMusicManager guildMusicManager = Music.getGuildAudioPlayer(guild, null, shard);
            AudioPlayer player = guildMusicManager.player;
            if (!player.isPaused() && guild.getAudioManager().getConnectedChannel() != null && guild.getAudioManager().getConnectedChannel().getMembers().size() > 1) {
                AudioTrack playingTrack = player.getPlayingTrack();
                if (playingTrack != null) {
                    long position = playingTrack.getPosition();
                    if (position == 0 || (position > 0 && !guild.getAudioManager().isConnected())) {
                        String textChannelId = voiceChannelsAtZeroDuration.get(guild.getId());
                        if (textChannelId == null) {
                            ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
                            TextChannel channel = ardentMusicManager.getChannel();
                            voiceChannelsAtZeroDuration.put(guild.getId(), channel.getId());
                        } else {
                            TextChannel channel = guild.getTextChannelById(textChannelId);
                            ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
                            if (ardentMusicManager != null) {
                                List<ArdentTrack> queue = ardentMusicManager.getQueueAsList();
                                shard.musicManagers.remove(Long.parseLong(guild.getId()));
                                GuildMusicManager manager = Music.getGuildAudioPlayer(guild, channel, shard);
                                for (ArdentTrack track : queue) {
                                    manager.scheduler.manager.addToQueue(new ArdentTrack(track.getAuthor(), track.getAddedFrom(), track.getTrack().makeClone()));
                                }
                            } else
                                shard.musicManagers.remove(Long.parseLong(guild.getId()));
                            if (channel == null)
                                channel = guild.getPublicChannel();
                            try {
                                channel.sendMessage("I detected that my audio connection was stuck and reset my player. #BlameDiscord").queue();
                            } catch (Exception e) {
                                new BotException(e);
                            }
                        }
                    }
                } else {
                    voiceChannelsAtZeroDuration.remove(guild.getId());
                }
            }
        }
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Guild(net.dv8tion.jda.core.entities.Guild) BotException(tk.ardentbot.core.misc.logging.BotException) TextChannel(net.dv8tion.jda.core.entities.TextChannel) BotException(tk.ardentbot.core.misc.logging.BotException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Shard(tk.ardentbot.main.Shard)

Aggregations

AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)4 Guild (net.dv8tion.jda.core.entities.Guild)2 TextChannel (net.dv8tion.jda.core.entities.TextChannel)2 BotException (tk.ardentbot.core.misc.logging.BotException)2 Shard (tk.ardentbot.main.Shard)2 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 SQLException (java.sql.SQLException)1 GuildVoiceState (net.dv8tion.jda.core.entities.GuildVoiceState)1 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)1 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)1 AudioManager (net.dv8tion.jda.core.managers.AudioManager)1 GuildMusicManager (net.kodehawa.mantarobot.commands.music.GuildMusicManager)1 Music.getGuildAudioPlayer (tk.ardentbot.commands.music.Music.getGuildAudioPlayer)1 EntityGuild (tk.ardentbot.utils.rpg.EntityGuild)1