use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project MantaroBot by Mantaro.
the class AudioRequester method loadSingle.
private void loadSingle(AudioTrack audioTrack, boolean silent) {
AudioTrackInfo trackInfo = audioTrack.getInfo();
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
String title = trackInfo.title;
long length = trackInfo.length;
long queueLimit = !Optional.ofNullable(dbGuild.getData().getMusicQueueSizeLimit()).isPresent() ? MAX_QUEUE_LENGTH : dbGuild.getData().getMusicQueueSizeLimit();
int fqSize = guildData.getMaxFairQueue();
if (getMusicManager().getTrackScheduler().getQueue().size() > queueLimit && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
if (!silent)
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Surpassed queue song limit!", title)).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
if (musicManager.getTrackScheduler().isStopped())
event.getGuild().getAudioManager().closeAudioConnection();
return;
}
if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 21 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
if (musicManager.getTrackScheduler().isStopped())
//do you?
event.getGuild().getAudioManager().closeAudioConnection();
return;
}
//Comparing if the URLs are the same to be 100% sure they're just not spamming the same url over and over again.
if (musicManager.getTrackScheduler().getQueue().stream().filter(track -> track.getInfo().uri.equals(audioTrack.getInfo().uri)).count() > fqSize) {
event.getChannel().sendMessage(EmoteReference.ERROR + String.format("**Surpassed fair queue level of %d (Too many songs which are exactly equal)**", fqSize + 1)).queue();
return;
}
musicManager.getTrackScheduler().queue(new AudioTrackContext(event.getAuthor(), event.getChannel(), audioTrack.getSourceManager() instanceof YoutubeAudioSourceManager ? "https://www.youtube.com/watch?v=" + audioTrack.getIdentifier() : trackUrl, audioTrack));
if (!silent) {
event.getChannel().sendMessage(String.format("📣 Added to queue -> **%s** **!(%s)**", title, AudioUtils.getLength(length))).queue();
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project c0debaseBot by Biospheere.
the class NowPlayingCommand method execute.
@Override
public void execute(String[] args, Message msg) {
EmbedBuilder embedBuilder = getEmbed(msg.getGuild(), msg.getAuthor());
if (CodebaseBot.getInstance().getMusicManager().getPlayingTrack(msg.getGuild()) != null) {
AudioTrack audioTrack = CodebaseBot.getInstance().getMusicManager().getPlayingTrack(msg.getGuild());
embedBuilder.setDescription("**" + audioTrack.getInfo().title + "**");
} else {
embedBuilder.setDescription("Es wird gerade nichts gespielt");
}
msg.getTextChannel().sendMessage(embedBuilder.build()).queue();
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project MantaroBot by Mantaro.
the class MusicCmds method nextSong.
@Subscribe
public void nextSong(CommandRegistry cr) {
cr.register("ns", new SimpleCommand(Category.MUSIC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
GuildMusicManager musicManager = MantaroBot.getInstance().getAudioManager().getMusicManager(event.getGuild());
TrackScheduler scheduler = musicManager.getTrackScheduler();
AudioTrack next = scheduler.getQueue().peek();
if (next == null) {
event.getChannel().sendMessage(EmoteReference.TALKING + "Ow, there isn't any song next").queue();
} else {
event.getChannel().sendMessage(EmoteReference.MEGA + "Next song in queue: **" + next.getInfo().title + "** (" + Utils.getDurationMinutes(next.getDuration()) + ")" + " | *Total songs in queue: " + scheduler.getQueue().size() + "*").queue();
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Next Song Command").addField("Description", "**Shows the next song in queue!**", false).build();
}
});
cr.registerAlias("ns", "nextsong");
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project MantaroBot by Mantaro.
the class AudioLoader method playlistLoaded.
@Override
public void playlistLoaded(AudioPlaylist playlist) {
if (playlist.isSearchResult()) {
if (!skipSelection)
onSearch(playlist);
else
loadSingle(playlist.getTracks().get(0), false);
return;
}
try {
int i = 0;
for (AudioTrack track : playlist.getTracks()) {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
if (guildData.getMusicQueueSizeLimit() != null) {
if (i < guildData.getMusicQueueSizeLimit()) {
loadSingle(track, true);
} else {
event.getChannel().sendMessage(String.format(":warning: The queue you added had more than %d songs, so we added songs until this limit and ignored the rest.", guildData.getMusicQueueSizeLimit())).queue();
break;
}
} else {
if (i > MAX_QUEUE_LENGTH && !dbGuild.isPremium()) {
event.getChannel().sendMessage(":warning: The queue you added had more than " + MAX_QUEUE_LENGTH + " songs, so we added songs until this limit and ignored the rest.").queue();
// stop adding songs
break;
} else {
loadSingle(track, true);
}
}
i++;
}
event.getChannel().sendMessage(String.format("%sAdded **%d songs** to queue on playlist: **%s** *(%s)*", EmoteReference.CORRECT, i, playlist.getName(), Utils.getDurationMinutes(playlist.getTracks().stream().mapToLong(temp -> temp.getInfo().length).sum()))).queue();
} catch (Exception e) {
SentryHelper.captureExceptionContext("Cannot load playlist. I guess something broke pretty hard. Please check", e, this.getClass(), "Music Loader");
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project MantaroBot by Mantaro.
the class AudioUtils method getQueueList.
public static String getQueueList(ConcurrentLinkedDeque<AudioTrack> queue) {
StringBuilder sb = new StringBuilder();
int n = 1;
for (AudioTrack audioTrack : queue) {
long aDuration = audioTrack.getDuration();
String duration = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(aDuration), TimeUnit.MILLISECONDS.toSeconds(aDuration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(aDuration)));
User dj = audioTrack.getUserData() != null ? MantaroBot.getInstance().getUserById(String.valueOf(audioTrack.getUserData())) : null;
String title = audioTrack.getInfo().title;
if (title.length() > 30)
title = title.substring(0, 30) + "...";
sb.append("**").append(n).append(". [").append(title).append("](").append(audioTrack.getInfo().uri).append(")** (").append(duration).append(")").append(dj != null ? " **[" + dj.getName() + "]**" : "").append("\n");
n++;
}
return sb.toString();
}
Aggregations