use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Shadbot by Shadorc.
the class AudioLoadResultListener method intercept.
@Override
public boolean intercept(IMessage message) {
if (!message.getAuthor().equals(guildMusic.getDj())) {
return false;
}
String prefix = Database.getDBGuild(guildMusic.getChannel().getGuild()).getPrefix();
if (message.getContent().equalsIgnoreCase(prefix + "cancel")) {
BotUtils.sendMessage(Emoji.CHECK_MARK + " Choice cancelled.", guildMusic.getChannel());
this.stopWaiting();
return true;
}
// Remove prefix and command names from message content
String content = message.getContent().toLowerCase();
for (String cmdName : CommandManager.getCommand("play").getNames()) {
content = StringUtils.remove(content, prefix, cmdName);
}
content = content.trim();
List<Integer> choices = new ArrayList<>();
for (String str : content.split(",")) {
Integer num = CastUtils.asIntBetween(str, 1, Math.min(5, resultsTracks.size()));
if (num == null) {
return false;
}
if (!choices.contains(num)) {
choices.add(num);
}
}
// If the manager was removed from the list while an user chose a music, we re-add it and join voice channel
GuildMusicManager.GUILD_MUSIC_MAP.putIfAbsent(message.getGuild().getLongID(), guildMusic);
guildMusic.joinVoiceChannel(userVoiceChannel);
// Joining a voice channel can take several seconds to be completed, if in the mean time someone chosen a music, resultsTracks will be empty.
if (resultsTracks.isEmpty()) {
LogUtils.warnf("{Guild ID: %d} Results tracks were empty.", message.getGuild().getLongID());
return true;
}
for (int choice : choices) {
AudioTrack track = resultsTracks.get(choice - 1);
if (guildMusic.getScheduler().isPlaying()) {
BotUtils.sendMessage(Emoji.MUSICAL_NOTE + " **" + FormatUtils.formatTrackName(track.getInfo()) + "** has been added to the playlist.", guildMusic.getChannel());
}
guildMusic.getScheduler().startOrQueue(track, putFirst);
if (guildMusic.getScheduler().getPlaylist().size() >= Config.MAX_PLAYLIST_SIZE - 1 && !PremiumManager.isPremium(guildMusic.getChannel().getGuild(), userDj)) {
BotUtils.sendMessage(TextUtils.PLAYLIST_LIMIT_REACHED, guildMusic.getChannel());
break;
}
}
this.stopWaiting();
return true;
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project PorkBot by DaMatrix.
the class CommandShuffle method execute.
public void execute(MessageReceivedEvent evt, String[] split, String rawContent) {
evt.getTextChannel().sendMessage("Shuffling queue...").queue(message -> {
GuildAudioInfo info = AudioUtils.getGuildAudioPlayer(evt.getGuild(), false);
if (info == null) {
message.editMessage("Not playing!").queue();
} else {
BlockingQueue<AudioTrack> queue = info.manager.scheduler.queue;
ArrayList<AudioTrack> queueTemp;
Collections.shuffle(queueTemp = new ArrayList<>(queue));
queue.clear();
queue.addAll(queueTemp);
message.editMessage("Queue shuffled!").queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project PorkBot by DaMatrix.
the class CommandQueue method execute.
public void execute(MessageReceivedEvent evt, String[] split, String rawContent) {
GuildAudioInfo info = AudioUtils.getGuildAudioPlayer(evt.getGuild(), false);
if (info == null) {
evt.getTextChannel().sendMessage("Not playing!").queue();
} else {
String msg = "Queue: `" + info.manager.scheduler.queue.size() + "` tracks queued\n\nCurrently playing: `" + info.manager.scheduler.player.getPlayingTrack().getInfo().title + "`\n\nQueue:\n";
ArrayList<AudioTrack> tracks = new ArrayList<>(info.manager.scheduler.queue);
for (int i = 0; i < 5 && i < tracks.size(); i++) {
AudioTrack track = tracks.get(i);
long minutes = TimeUnit.MILLISECONDS.toMinutes(track.getInfo().length);
long seconds = TimeUnit.MILLISECONDS.toSeconds(track.getInfo().length);
msg += (i + 1) + ": " + tracks.get(i).getInfo().title + "(`" + minutes + ":" + seconds + "`)\n";
}
MessageUtils.sendMessage(msg, evt.getTextChannel());
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.
the class Music method getDuration.
private static String getDuration(ArrayList<AudioTrack> tracks) {
long length = 0;
for (AudioTrack t : tracks) length += t.getDuration();
int seconds = (int) (length / 1000);
int minutes = seconds / 60;
int hours = minutes / 60;
return "[" + String.format("%02d", (hours % 60)) + ":" + String.format("%02d", (minutes % 60)) + ":" + String.format("%02d", (seconds % 60)) + "]";
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.
the class Music method loadAndPlay.
static void loadAndPlay(Message message, User user, Command command, final TextChannel channel, String trackUrl, final VoiceChannel voiceChannel, boolean search, boolean useEmbedSelect) {
if (trackUrl.contains("spotify.com")) {
String[] parsed = trackUrl.split("/track/");
if (parsed.length == 2) {
final TrackRequest request = spotifyApi.getTrack(parsed[1]).build();
try {
trackUrl = request.get().getName();
} catch (Exception e) {
new BotException(e);
}
}
}
Guild guild = channel.getGuild();
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild(), channel);
String finalTrackUrl = trackUrl;
GuildUtils.getShard(guild).playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
if (!UserUtils.hasTierTwoPermissions(user) && !EntityGuild.get(guild).isPremium()) {
try {
if (!shouldContinue(user, guild, channel, track)) {
return;
}
} catch (Exception e) {
new BotException(e);
}
}
try {
command.sendTranslatedMessage("Adding {0} to the queue".replace("{0}", track.getInfo().title) + " " + getDuration(track), channel, user);
} catch (Exception e) {
new BotException(e);
}
play(user, guild, voiceChannel, musicManager, track, channel);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
if (playlist.isSearchResult()) {
try {
if (!useEmbedSelect) {
AudioTrack[] possible;
if (playlist.getTracks().size() >= 5)
possible = playlist.getTracks().subList(0, 5).toArray(new AudioTrack[5]);
else
possible = playlist.getTracks().toArray(new AudioTrack[playlist.getTracks().size()]);
ArrayList<String> names = new ArrayList<>();
for (AudioTrack audioTrack : possible) {
names.add(audioTrack.getInfo().title);
}
Message embed = command.sendEmbed(command.chooseFromList("Choose Song", guild, user, command, names.toArray(new String[5])), channel, user);
interactiveOperation(channel, message, selectionMessage -> {
try {
AudioTrack selected = possible[Integer.parseInt(selectionMessage.getContent()) - 1];
if (!UserUtils.hasTierTwoPermissions(user) && !EntityGuild.get(guild).isPremium()) {
try {
if (!shouldContinue(user, guild, channel, selected)) {
return;
}
} catch (Exception e) {
new BotException(e);
}
}
try {
embed.delete().queue();
selectionMessage.delete().queue();
} catch (Exception ignored) {
}
play(user, guild, voiceChannel, musicManager, selected, channel);
command.sendTranslatedMessage("Adding {0} to the queue".replace("{0}", selected.getInfo().title) + " " + getDuration(selected), channel, user);
} catch (Exception e) {
command.sendTranslatedMessage("Invalid response", channel, user);
}
});
} else {
AudioTrack track = playlist.getTracks().get(0);
play(user, guild, voiceChannel, musicManager, track, channel);
command.sendTranslatedMessage("Adding {0} to the queue".replace("{0}", track.getInfo().title) + " " + getDuration(track), channel, user);
}
} catch (Exception e) {
new BotException(e);
}
} else {
if (!UserUtils.hasTierTwoPermissions(user) && !EntityGuild.get(guild).isPremium()) {
try {
if (!shouldContinue(user, guild, channel, 1)) {
return;
}
} catch (Exception e) {
new BotException(e);
}
}
try {
command.sendTranslatedMessage("Adding {0} songs to the queue".replace("{0}", String.valueOf(tracks.size())), channel, user);
} catch (Exception e) {
new BotException(e);
}
for (AudioTrack track : tracks) {
play(user, guild, voiceChannel, musicManager, track, channel);
}
}
}
@Override
public void noMatches() {
if (!search) {
loadAndPlay(message, user, command, channel, "ytsearch: " + finalTrackUrl, voiceChannel, true, useEmbedSelect);
} else {
try {
command.sendTranslatedMessage("I couldn't find a song with that name", channel, user);
} catch (Exception e) {
new BotException(e);
}
}
}
@Override
public void loadFailed(FriendlyException exception) {
try {
sendTo(channel, guild).sendMessage("I wasn't able to play that track... **Reason: **" + exception.getLocalizedMessage()).queue();
} catch (Exception e) {
new BotException(e);
}
}
});
}
Aggregations