use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class Handler method closeAudioPlayer.
private void closeAudioPlayer(Guild guild, AudioManager audioManager, int defaultVolume) {
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);
musicManager.getScheduler().setLooping(false);
musicManager.getScheduler().getQueue().clear();
musicManager.getAudioPlayer().stopTrack();
musicManager.getAudioPlayer().setVolume(defaultVolume);
audioManager.closeAudioConnection();
}
use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class NowPlayingCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
if (requestingUserDto.hasMusicPermission()) {
if (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
return;
final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
final AudioPlayer audioPlayer = musicManager.getAudioPlayer();
final AudioTrack track = audioPlayer.getPlayingTrack();
if (track == null) {
channel.sendMessage("There is no track playing currently").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
final AudioTrackInfo info = track.getInfo();
AudioTrack playingTrack = musicManager.getAudioPlayer().getPlayingTrack();
if (!track.getInfo().isStream) {
long position = playingTrack.getPosition();
long duration = playingTrack.getDuration();
String songPosition = QueueCommand.formatTime(position);
String songDuration = QueueCommand.formatTime(duration);
String nowPlaying = String.format("Now playing `%s` by `%s` `[%s/%s]` (Link: <%s>) ", info.title, info.author, songPosition, songDuration, info.uri);
channel.sendMessage(nowPlaying).queue(message -> ICommand.deleteAfter(message, deleteDelay));
} else {
String nowPlaying = String.format("Now playing `%s` by `%s` (Link: <%s>) ", info.title, info.author, info.uri);
channel.sendMessage(nowPlaying).queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
}
}
use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class QueueCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
final BlockingQueue<AudioTrack> queue = musicManager.getScheduler().getQueue();
if (!requestingUserDto.hasMusicPermission()) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
if (queue.isEmpty()) {
channel.sendMessage("The queue is currently empty").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
final int trackCount = Math.min(queue.size(), 20);
final List<AudioTrack> trackList = new ArrayList<>(queue);
final MessageAction messageAction = channel.sendMessage("**Current Queue:**\n");
for (int i = 0; i < trackCount; i++) {
final AudioTrack track = trackList.get(i);
final AudioTrackInfo info = track.getInfo();
messageAction.append('#').append(String.valueOf(i + 1)).append(" `").append(String.valueOf(info.title)).append(" by ").append(info.author).append("` [`").append(formatTime(track.getDuration())).append("`]\n");
}
if (trackList.size() > trackCount) {
messageAction.append("And `").append(String.valueOf(trackList.size() - trackCount)).append("` more...");
}
messageAction.queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
Aggregations