use of toby.lavaplayer.PlayerManager in project toby-bot by ml404.
the class PlayCommand 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 (ctx.getArgs().isEmpty()) {
channel.sendMessage("Correct usage is `!play <youtube link>`").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
if (IMusicCommand.isInvalidChannelStateForCommand(ctx, channel, deleteDelay))
return;
String link = String.join(" ", ctx.getArgs());
PlayerManager instance = PlayerManager.getInstance();
Guild guild = ctx.getGuild();
int currentVolume = instance.getMusicManager(guild).getAudioPlayer().getVolume();
instance.setPreviousVolume(currentVolume);
if (link.equals("intro")) {
playUserIntro(requestingUserDto, guild, channel, deleteDelay);
return;
}
if (link.contains("youtube") && !isUrl(link)) {
link = "ytsearch:" + link;
}
instance.loadAndPlay(channel, link, deleteDelay);
}
use of toby.lavaplayer.PlayerManager in project toby-bot by ml404.
the class MusicPlayerHelper method playUserIntro.
public static void playUserIntro(UserDto dbUser, Guild guild, TextChannel channel, int deleteDelay) {
MusicDto musicDto = dbUser.getMusicDto();
PlayerManager instance = PlayerManager.getInstance();
int currentVolume = PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().getVolume();
if (musicDto != null && musicDto.getFileName() != null) {
Integer introVolume = musicDto.getIntroVolume();
changeVolumeForIntro(channel, deleteDelay, currentVolume, introVolume);
PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().setVolume(introVolume != null ? introVolume : currentVolume);
instance.loadAndPlay(guild.getSystemChannel(), String.format(ConsumeWebService.getWebUrl() + "/music?id=%s", musicDto.getId()), true, 0);
} else if (musicDto != null) {
Integer introVolume = musicDto.getIntroVolume();
PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().setVolume(introVolume != null ? introVolume : currentVolume);
changeVolumeForIntro(channel, deleteDelay, currentVolume, introVolume);
instance.setPreviousVolume(currentVolume);
instance.loadAndPlay(guild.getSystemChannel(), Arrays.toString(dbUser.getMusicDto().getMusicBlob()), true, 0);
}
}
Aggregations