Search in sources :

Example 6 with AudioManager

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

the class Stop 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.getPlayingTrack() != null)
                manager.player.stopTrack();
            manager.scheduler.manager.resetQueue();
            getShard().musicManagers.remove(Long.parseLong(guild.getId()));
            sendTranslatedMessage("Stopped playback and cleared songs in the queue", sendTo(channel, guild), 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 7 with AudioManager

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

the class Play method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length > 1) {
        AudioManager audioManager = guild.getAudioManager();
        String url = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
        boolean shouldDeleteMessage = shouldDeleteMessages(guild);
        boolean implement = false;
        if (!audioManager.isConnected()) {
            VoiceChannel success = joinChannel(guild, guild.getMember(user), this, audioManager, channel);
            if (success != null) {
                loadAndPlay(message, user, this, (TextChannel) channel, url, success, false, true);
                implement = true;
            }
        } else {
            loadAndPlay(message, user, this, (TextChannel) sendTo(channel, guild), url, audioManager.getConnectedChannel(), false, true);
            implement = true;
        }
        if (implement) {
            if (shouldDeleteMessage) {
                try {
                    message.delete().queue();
                } catch (PermissionException ex) {
                    guild.getOwner().getUser().openPrivateChannel().queue(privateChannel -> {
                        privateChannel.sendMessage("Auto-deleting music play messages is enabled, " + "but you need to give me the `MANAGE MESSAGES` permission so I can " + "actually delete the messages.").queue();
                    });
                }
            }
        }
    } else
        sendTranslatedMessage("You need to include a song name or URL", channel, user);
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildUtils(tk.ardentbot.utils.discord.GuildUtils) Command(tk.ardentbot.core.executor.Command) Music(tk.ardentbot.commands.music.Music) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioManager(net.dv8tion.jda.core.managers.AudioManager)

Example 8 with AudioManager

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

the class Recommend method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length > 1) {
        AudioManager audioManager = guild.getAudioManager();
        if (audioManager.isConnected()) {
            VoiceChannel connected = audioManager.getConnectedChannel();
            try {
                int amount = Integer.parseInt(args[1]);
                if (amount <= 0 || amount > 10) {
                    sendTranslatedMessage("You can only get 10 recommended songs at a time!", channel, user);
                    return;
                }
                GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
                ArdentTrack ardentTrack = manager.scheduler.manager.getCurrentlyPlaying();
                if (ardentTrack == null) {
                    sendTranslatedMessage("I'm not playing anything right now!", channel, user);
                    return;
                }
                String[] nameArgs = StringUtils.removeBracketsParentheses(ardentTrack.getTrack().getInfo().title).split(" ");
                StringBuilder name = new StringBuilder();
                for (String arg : nameArgs) {
                    if (!arg.contains(".") && !arg.contains("+") && !arg.contains(":") && !arg.contains("//")) {
                        name.append(arg);
                    }
                    name.append(" ");
                }
                TrackSearchRequest trackSearchRequest = spotifyApi.searchTracks(name.toString()).build();
                try {
                    Page<Track> tracks = trackSearchRequest.get();
                    String id = tracks.getItems().get(0).getId();
                    ArrayList<String> ids = new ArrayList<>();
                    ids.add(id);
                    RecommendationsRequest recommendationsRequest = spotifyApi.getRecommendations().tracks(ids).build();
                    List<Track> recommendations = recommendationsRequest.get();
                    for (int i = 0; i < amount; i++) {
                        loadAndPlay(message, user, this, (TextChannel) sendTo(channel, guild), recommendations.get(i).getName(), connected, false, true);
                    }
                } catch (Exception e) {
                    channel.sendMessage("There were no recommendations available, sorry!").queue();
                }
            } catch (NumberFormatException e) {
                sendTranslatedMessage("That's not a number!", channel, user);
            }
        } else {
            sendTranslatedMessage("I'm not in a voice channel", channel, user);
        }
    } else
        sendTranslatedMessage("Invalid arguments", channel, user);
}
Also used : TrackSearchRequest(com.wrapper.spotify.methods.TrackSearchRequest) ArrayList(java.util.ArrayList) AudioManager(net.dv8tion.jda.core.managers.AudioManager) RecommendationsRequest(com.wrapper.spotify.methods.RecommendationsRequest) Track(com.wrapper.spotify.models.Track)

Example 9 with AudioManager

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

the class Remove method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length > 1) {
        AudioManager audioManager = guild.getAudioManager();
        Member member = guild.getMember(user);
        if (audioManager.isConnected()) {
            try {
                GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
                BlockingQueue<ArdentTrack> queue = manager.scheduler.manager.getQueue();
                int numberToRemove = Integer.parseInt(args[1]) - 1;
                if (numberToRemove >= queue.size() || numberToRemove < 0)
                    sendTranslatedMessage("Invalid arguments", channel, user);
                else {
                    Iterator<ArdentTrack> iterator = queue.iterator();
                    int current = 0;
                    while (iterator.hasNext()) {
                        ArdentTrack ardentTrack = iterator.next();
                        AudioTrack track = ardentTrack.getTrack();
                        String name = track.getInfo().title;
                        if (current == numberToRemove) {
                            if (UserUtils.hasManageServerOrStaff(member) || ardentTrack.getAuthor().equalsIgnoreCase(user.getId()) || UserUtils.isBotCommander(member)) {
                                queue.remove(ardentTrack);
                                sendTranslatedMessage("Removed {0} from the queue".replace("{0}", name), sendTo(channel, guild), user);
                            } else {
                                sendTranslatedMessage("You need to have queued the song or have the Manage Server " + "permission", sendTo(channel, guild), user);
                            }
                        }
                        current++;
                    }
                }
            } catch (NumberFormatException ex) {
                sendTranslatedMessage("Invalid arguments", channel, user);
            }
        } else
            sendTranslatedMessage("I'm not in a voice channel!", channel, user);
    } else
        sendTranslatedMessage("That's not a number!", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 10 with AudioManager

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

the class Restart method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    GuildMusicManager musicManager = getGuildAudioPlayer(guild, channel);
    ArdentMusicManager player = musicManager.scheduler.manager;
    ArdentTrack current = player.getCurrentlyPlaying();
    if (current != null) {
        AudioManager audioManager = guild.getAudioManager();
        if (UserUtils.hasManageServerOrStaff(guild.getMember(user)) || user.getId().equalsIgnoreCase(current.getAuthor()) || UserUtils.isBotCommander(guild.getMember(user)) || (audioManager.isConnected() && audioManager.getConnectedChannel().getMembers().size() == 2)) {
            AudioTrack track = current.getTrack();
            track.setPosition(0);
            sendTranslatedMessage("Restarted the current track", channel, user);
        } else {
            sendTranslatedMessage("You need to have queued the song or have the Manage Server permission", sendTo(channel, guild), user);
        }
    } else
        sendTranslatedMessage("I'm not playing anything right now!", channel, user);
}
Also used : AudioManager(net.dv8tion.jda.core.managers.AudioManager) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

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