use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class SkipCommand 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 (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
return;
final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
final AudioPlayer audioPlayer = musicManager.getAudioPlayer();
if (audioPlayer.getPlayingTrack() == null) {
channel.sendMessage("There is no track playing currently").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
List<String> args = ctx.getArgs();
String skipValue = (!args.isEmpty()) ? args.get(0) : "";
int tracksToSkip = !skipValue.isEmpty() ? Integer.parseInt(skipValue) : 1;
if (tracksToSkip < 0) {
channel.sendMessage("You're not too bright, but thanks for trying").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
if (PlayerManager.getInstance().isCurrentlyStoppable() || requestingUserDto.isSuperUser()) {
for (int j = 0; j < tracksToSkip; j++) {
musicManager.getScheduler().nextTrack();
}
musicManager.getScheduler().setLooping(false);
channel.sendMessage(String.format("Skipped %d track(s)", tracksToSkip)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
nowPlaying(channel, musicManager.getAudioPlayer().getPlayingTrack(), deleteDelay);
} else {
sendDeniedStoppableMessage(channel, musicManager, deleteDelay);
}
}
use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class StopCommand 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 (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
return;
final GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
if (PlayerManager.getInstance().isCurrentlyStoppable() || requestingUserDto.isSuperUser()) {
musicManager.getScheduler().stopTrack(true);
musicManager.getScheduler().getQueue().clear();
musicManager.getScheduler().setLooping(false);
musicManager.getAudioPlayer().setPaused(false);
channel.sendMessage("The player has been stopped and the queue has been cleared").queue(message -> ICommand.deleteAfter(message, deleteDelay));
} else {
sendDeniedStoppableMessage(channel, musicManager, deleteDelay);
}
}
use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class LeaveCommand 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 Member self = ctx.getSelfMember();
final GuildVoiceState selfVoiceState = self.getVoiceState();
if (!requestingUserDto.hasMusicPermission()) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
if (!selfVoiceState.inVoiceChannel()) {
channel.sendMessage("I'm not in a voice channel, somebody shoot this guy").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
Guild guild = ctx.getGuild();
final AudioManager audioManager = guild.getAudioManager();
final VoiceChannel memberChannel = memberVoiceState.getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);
if (PlayerManager.getInstance().isCurrentlyStoppable() || member.hasPermission(Permission.KICK_MEMBERS)) {
String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
ConfigDto databaseConfig = configService.getConfigByName(volumePropertyName, ctx.getGuild().getId());
int defaultVolume = databaseConfig != null ? Integer.parseInt(databaseConfig.getValue()) : 100;
musicManager.getScheduler().setLooping(false);
musicManager.getScheduler().getQueue().clear();
musicManager.getAudioPlayer().stopTrack();
musicManager.getAudioPlayer().setVolume(defaultVolume);
audioManager.closeAudioConnection();
channel.sendMessageFormat("Disconnecting from `\uD83D\uDD0A %s`", memberChannel.getName()).queue(message -> ICommand.deleteAfter(message, deleteDelay));
} else {
sendDeniedStoppableMessage(channel, musicManager, deleteDelay);
}
}
use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class LoopCommand 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()) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
if (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
return;
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
TrackScheduler scheduler = musicManager.getScheduler();
boolean newIsRepeating = !scheduler.isLooping();
scheduler.setLooping(newIsRepeating);
channel.sendMessageFormat("The Player has been set to **%s**", newIsRepeating ? "looping" : "not looping").queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
use of toby.lavaplayer.GuildMusicManager in project toby-bot by ml404.
the class PauseCommand 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()) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
if (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
return;
final Member member = ctx.getMember();
Guild guild = ctx.getGuild();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);
if (PlayerManager.getInstance().isCurrentlyStoppable() || member.hasPermission(Permission.KICK_MEMBERS)) {
AudioPlayer audioPlayer = PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer();
if (!audioPlayer.isPaused()) {
AudioTrack track = audioPlayer.getPlayingTrack();
channel.sendMessage("Pausing: `").append(track.getInfo().title).append("` by `").append(track.getInfo().author).append('`').queue(message -> ICommand.deleteAfter(message, deleteDelay));
audioPlayer.setPaused(true);
} else {
channel.sendMessageFormat("The audio player on this server is already paused. Please try using %sresume", prefix).queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
} else {
sendDeniedStoppableMessage(channel, musicManager, deleteDelay);
}
}
Aggregations