use of com.sedmelluq.discord.lavaplayer.track.AudioTrack 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());
}
}
}
}
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.
the class Playing method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
GuildMusicManager manager = getGuildAudioPlayer(guild, channel);
ArdentMusicManager ardentMusicManager = manager.scheduler.manager;
ArdentTrack nowPlaying = ardentMusicManager.getCurrentlyPlaying();
if (nowPlaying != null) {
AudioTrack track = nowPlaying.getTrack();
AudioTrackInfo info = track.getInfo();
StringBuilder sb = new StringBuilder();
String queuedBy = "queued by";
sb.append(info.title + ": " + info.author + " " + getCurrentTime(track) + "\n *" + queuedBy + " " + UserUtils.getUserById(nowPlaying.getAuthor()).getName() + "* - [" + nowPlaying.getVotedToSkip().size() + " / " + Math.round(guild.getAudioManager().getConnectedChannel().getMembers().size() / 2) + "] votes to skip");
sendTranslatedMessage(sb.toString(), sendTo(channel, guild), user);
} else
sendTranslatedMessage("I'm not playing anything right now!", channel, user);
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project Ardent by adamint.
the class Queue method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
StringBuilder sb = new StringBuilder();
String queuedBy = "queued by";
sb.append("__Music Queue__\n");
BlockingQueue<ArdentTrack> queue = getGuildAudioPlayer(guild, channel).scheduler.manager.getQueue();
Iterator<ArdentTrack> iterator = queue.iterator();
int current = 1;
ArrayList<AudioTrack> trackList = new ArrayList<>();
while (iterator.hasNext()) {
ArdentTrack ardentTrack = iterator.next();
AudioTrack track = ardentTrack.getTrack();
trackList.add(track);
sb.append("#" + current + ": " + track.getInfo().title + ": " + track.getInfo().author + " " + getDuration(track) + "\n *" + queuedBy + " " + GuildUtils.getShard(guild).jda.getUserById(ardentTrack.getAuthor()).getName() + "*\n");
current++;
}
if (current == 1) {
sb.append("There aren't any songs in the queue!");
}
sendTranslatedMessage(sb.toString(), sendTo(channel, guild), user);
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack 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);
}
use of com.sedmelluq.discord.lavaplayer.track.AudioTrack 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);
}
Aggregations