Search in sources :

Example 1 with AudioManager

use of net.dv8tion.jda.core.managers.AudioManager 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 AudioManager

use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.

the class Pause method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    AudioManager audioManager = guild.getAudioManager();
    Member member = guild.getMember(user);
    if (UserUtils.hasManageServerOrStaff(member) || UserUtils.isBotCommander(member) || (audioManager.isConnected() && audioManager.getConnectedChannel().getMembers().size() == 2)) {
        if (audioManager.isConnected()) {
            GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
            if (!manager.player.isPaused()) {
                sendTranslatedMessage("Paused music playback", channel, user);
                manager.player.setPaused(true);
            } else {
                sendTranslatedMessage("Can't pause an already-paused player!", channel, user);
            }
        } else
            sendTranslatedMessage("I'm not in a voice channel!", channel, user);
    } else
        sendTranslatedMessage("You need the Manage Server permission to do this", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager)

Example 3 with AudioManager

use of net.dv8tion.jda.core.managers.AudioManager in project MantaroBot by Mantaro.

the class AudioCmdUtils method connectToVoiceChannel.

static boolean connectToVoiceChannel(GuildMessageReceivedEvent event) {
    VoiceChannel userChannel = event.getMember().getVoiceState().getChannel();
    if (userChannel == null) {
        event.getChannel().sendMessage("❌ **Please join a voice channel!**").queue();
        return false;
    }
    if (!event.getGuild().getMember(event.getJDA().getSelfUser()).hasPermission(userChannel, Permission.VOICE_CONNECT)) {
        event.getChannel().sendMessage(":heavy_multiplication_x: I cannot connect to this channel due to the lack of permission.").queue();
        return false;
    }
    VoiceChannel guildMusicChannel = null;
    if (MantaroData.db().getGuild(event.getGuild()).getData().getMusicChannel() != null) {
        guildMusicChannel = event.getGuild().getVoiceChannelById(MantaroData.db().getGuild(event.getGuild()).getData().getMusicChannel());
    }
    AudioManager audioManager = event.getGuild().getAudioManager();
    if (guildMusicChannel != null) {
        if (!userChannel.equals(guildMusicChannel)) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "I can only play music on channel **" + guildMusicChannel.getName() + "**!").queue();
            return false;
        }
        if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
            audioManager.openAudioConnection(userChannel);
            event.getChannel().sendMessage(EmoteReference.CORRECT + "Connected to channel **" + userChannel.getName() + "**!").queue();
        }
        return true;
    }
    if (audioManager.isConnected() && !audioManager.getConnectedChannel().equals(userChannel)) {
        event.getChannel().sendMessage(String.format(EmoteReference.WARNING + "I'm already connected on channel **%s**! (Use the `move` command to move me to another channel)", audioManager.getConnectedChannel().getName())).queue();
        return false;
    }
    if (audioManager.isAttemptingToConnect() && !audioManager.getQueuedAudioConnection().equals(userChannel)) {
        event.getChannel().sendMessage(String.format(EmoteReference.ERROR + "I'm already trying to connect to channel **%s**! (Use the `move` command to move me to another channel)", audioManager.getQueuedAudioConnection().getName())).queue();
        return false;
    }
    if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
        openAudioConnection(event, audioManager, userChannel);
    }
    return true;
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Example 4 with AudioManager

use of net.dv8tion.jda.core.managers.AudioManager in project MantaroBot by Mantaro.

the class TrackScheduler method onTrackSchedulerStop.

private void onTrackSchedulerStop() {
    getVoteStop().clear();
    Guild g = getGuild();
    if (g == null)
        return;
    AudioManager m = g.getAudioManager();
    if (m == null)
        return;
    m.closeAudioConnection();
    AudioTrackContext previousTrack;
    try {
        previousTrack = getPreviousTrack();
        if (previousTrack != null && previousTrack.getRequestedChannel() != null && previousTrack.getRequestedChannel().canTalk())
            previousTrack.getRequestedChannel().sendMessage(":mega: Finished playing queue! Hope you enjoyed it.").queue(message -> message.delete().queueAfter(20, TimeUnit.SECONDS));
    }//fuck
     catch (Exception ignored) {
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Getter(lombok.Getter) TextChannel(net.dv8tion.jda.core.entities.TextChannel) MantaroShard(net.kodehawa.mantarobot.MantaroShard) Message(net.dv8tion.jda.core.entities.Message) ArrayList(java.util.ArrayList) MantaroBot(net.kodehawa.mantarobot.MantaroBot) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) AudioTrackEndReason(com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) AudioTrackState(com.sedmelluq.discord.lavaplayer.track.AudioTrackState) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) AudioManager(net.dv8tion.jda.core.managers.AudioManager) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Guild(net.dv8tion.jda.core.entities.Guild) List(java.util.List) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) MantaroData(net.kodehawa.mantarobot.data.MantaroData) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioEventAdapter(com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter) Collections(java.util.Collections) AudioManager(net.dv8tion.jda.core.managers.AudioManager) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) Guild(net.dv8tion.jda.core.entities.Guild) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 5 with AudioManager

use of net.dv8tion.jda.core.managers.AudioManager in project Ardent by adamint.

the class VoteToSkip method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    AudioManager audioManager = guild.getAudioManager();
    VoiceChannel connected = audioManager.getConnectedChannel();
    if (connected != null && connected.getMembers().stream().filter((member -> member.getUser().getId().equals(user.getId()))).collect(Collectors.toList()).size() > 0) {
        GuildMusicManager guildMusicManager = getGuildAudioPlayer(guild, channel);
        ArdentTrack track = guildMusicManager.scheduler.manager.getCurrentlyPlaying();
        if (track == null) {
            sendTranslatedMessage("I'm not playing anything right now!", channel, user);
            return;
        }
        if (track.getVotedToSkip().contains(user.getId())) {
            sendTranslatedMessage("You already voted to skip >.>", channel, user);
            return;
        }
        track.addSkipVote(user);
        if (track.getVotedToSkip().size() >= Math.round(connected.getMembers().size() / 2)) {
            sendTranslatedMessage("Half of the people in the channel voted to skip the current song", channel, user);
            guildMusicManager.scheduler.manager.nextTrack();
        } else
            sendTranslatedMessage("Your vote to skip has been recorded. You need half of the users in the channel to force a " + "skip", channel, user);
    } else
        sendTranslatedMessage("Either I or you aren't in a voice channel", channel, user);
}
Also used : Command(tk.ardentbot.core.executor.Command) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) AudioManager(net.dv8tion.jda.core.managers.AudioManager) Music.getGuildAudioPlayer(tk.ardentbot.commands.music.Music.getGuildAudioPlayer) Collectors(java.util.stream.Collectors) AudioManager(net.dv8tion.jda.core.managers.AudioManager)

Aggregations

AudioManager (net.dv8tion.jda.core.managers.AudioManager)17 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)4 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)3 Command (tk.ardentbot.core.executor.Command)3 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)2 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)2 ArrayList (java.util.ArrayList)2 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)2 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)2 Music (tk.ardentbot.commands.music.Music)2 Music.getGuildAudioPlayer (tk.ardentbot.commands.music.Music.getGuildAudioPlayer)2 GuildUtils (tk.ardentbot.utils.discord.GuildUtils)2 AudioEventAdapter (com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter)1 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioTrackEndReason (com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason)1 AudioTrackState (com.sedmelluq.discord.lavaplayer.track.AudioTrackState)1 RecommendationsRequest (com.wrapper.spotify.methods.RecommendationsRequest)1 TrackSearchRequest (com.wrapper.spotify.methods.TrackSearchRequest)1 Track (com.wrapper.spotify.models.Track)1 Collections (java.util.Collections)1