use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Skip method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
VoiceChannel vc = ctx.getSelfMember().getVoiceState().getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
AudioPlayer audioPlayer = musicManager.audioPlayer;
if (audioPlayer.getPlayingTrack() == null) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
if (musicManager.scheduler.votingGoingOn) {
EmbedBuilder builder = Embeds.createBuilder(null, "A voting is going on already. Please be patient !", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
List<Member> filteredMembers = vc.getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
if (filteredMembers.size() >= 3) {
musicManager.scheduler.votingGoingOn = true;
musicManager.scheduler.votes.clear();
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.totalMembers = filteredMembers;
String unicode = "U+1F44D";
channel.sendMessageEmbeds(Embeds.createBuilder("Voting starts now", "React with :thumbsup: to vote for next song . I will wait for 20 seconds", "Requested by " + ctx.getMember().getEffectiveName(), ctx.getMember().getEffectiveAvatarUrl(), null).build()).queue((message) -> {
message.addReaction(unicode).queue();
this.waiter.waitForEvent(GuildMessageReactionAddEvent.class, (e) -> {
if (e.getMember().getUser().isBot() || !e.getReactionEmote().getEmoji().equalsIgnoreCase("👍") || !e.getMessageId().equals(message.getId()))
return false;
if (!e.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
message.removeReaction(unicode).queue();
return false;
}
if (!e.getMember().getVoiceState().inVoiceChannel()) {
message.removeReaction(unicode).queue();
e.getReaction().removeReaction().queue();
return false;
}
if (!e.getMember().getVoiceState().getChannel().getId().equalsIgnoreCase(e.getGuild().getSelfMember().getVoiceState().getChannel().getId())) {
e.getReaction().removeReaction().queue();
return false;
}
if (musicManager.scheduler.votingGoingOn) {
if (musicManager.scheduler.votes.contains(e.getMember())) {
e.getReaction().removeReaction().queue();
return false;
}
if (!musicManager.scheduler.totalMembers.contains(e.getMember())) {
musicManager.scheduler.totalMembers.add(e.getMember());
}
musicManager.scheduler.votes.add(e.getMember());
return musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f);
}
return false;
}, (e) -> {
if (musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f)) {
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.votes.clear();
musicManager.scheduler.votingGoingOn = false;
// Skip the song
musicManager.scheduler.nextTrack();
message.delete().queue();
EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
}, 20, TimeUnit.SECONDS, () -> {
if (musicManager.scheduler.votingGoingOn) {
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.votes.clear();
musicManager.scheduler.votingGoingOn = false;
message.delete().queue();
channel.sendMessageEmbeds(Embeds.createBuilder(null, "Voting did not come to an end . Try again next time..", null, null, null).build()).queue();
}
});
this.waiter.waitForEvent(GuildMessageReactionRemoveEvent.class, (e) -> {
if (e.getMember().getUser().isBot() || !e.getReactionEmote().getEmoji().equalsIgnoreCase("👍") || !e.getMessageId().equals(message.getId()))
return false;
if (!e.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) {
return false;
}
if (!e.getMember().getVoiceState().inVoiceChannel()) {
return false;
}
if (!e.getMember().getVoiceState().getChannel().getId().equalsIgnoreCase(e.getGuild().getSelfMember().getVoiceState().getChannel().getId())) {
return false;
}
if (musicManager.scheduler.votingGoingOn) {
if (musicManager.scheduler.votes.contains(e.getMember())) {
musicManager.scheduler.votes = musicManager.scheduler.votes.stream().filter((vote) -> vote != e.getMember()).collect(Collectors.toList());
return false;
}
return musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f);
}
return false;
}, (e) -> {
if (musicManager.scheduler.votes.size() >= Math.ceil(musicManager.scheduler.totalMembers.size() / 2f)) {
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.votes.clear();
musicManager.scheduler.votingGoingOn = false;
// Skip the song
musicManager.scheduler.nextTrack();
message.delete().queue();
EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
}, 20, TimeUnit.SECONDS, () -> {
});
});
return;
}
musicManager.scheduler.nextTrack();
EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Volume method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
List<String> args = ctx.getArgs();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
AudioPlayer audioPlayer = musicManager.scheduler.player;
if (args.isEmpty()) {
int result = audioPlayer.getVolume();
EmbedBuilder builder = Embeds.createBuilder(null, "Current volume is " + result + "%", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
int amount = -1;
try {
amount = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "Please pass a value between 0-100 for volume", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
if (amount < 0 || amount > 100) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "Please pass a value between 0-100 for volume", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
audioPlayer.setVolume(amount);
EmbedBuilder builder = Embeds.createBuilder(null, "Volume changed", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Leave method handle.
@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
musicManager.scheduler.isRepeating = false;
musicManager.scheduler.queue.clear();
musicManager.scheduler.player.startTrack(null, false);
AudioManager audioManager = ctx.getGuild().getAudioManager();
audioManager.closeAudioConnection();
String desc = "Disconnected from " + memberVoiceState.getChannel().getAsMention();
EmbedBuilder builder = Embeds.createBuilder("Disconnected", desc, "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class NowPlaying method handle.
@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
AudioPlayer audioPlayer = musicManager.audioPlayer;
AudioTrack playingTrack = audioPlayer.getPlayingTrack();
if (playingTrack == null) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
EmbedBuilder builder = Embeds.songEmbed(member, playingTrack);
builder.setTitle("Now playing 💿");
long fullMillis = playingTrack.getPosition();
String formattedFull;
if (fullMillis >= 3600000) {
formattedFull = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(fullMillis), TimeUnit.MILLISECONDS.toMinutes(fullMillis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(fullMillis)), TimeUnit.MILLISECONDS.toSeconds(fullMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fullMillis)));
} else {
formattedFull = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(fullMillis) - // The change is in this line
TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(fullMillis)), TimeUnit.MILLISECONDS.toSeconds(fullMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fullMillis)));
}
if (!playingTrack.getInfo().isStream) {
builder.addField("Current position", formattedFull + " minutes", false);
}
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Pause method handle.
@Override
@SuppressWarnings("ConstantConditions")
public void handle(@NotNull CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
AudioPlayer audioPlayer = musicManager.audioPlayer;
if (audioPlayer.getPlayingTrack() == null) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
AudioPlayer player = musicManager.scheduler.player;
if (player.isPaused()) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "Player is already paused", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
player.setPaused(true);
EmbedBuilder builder = Embeds.createBuilder(null, "Player paused", "Requested by " + member.getEffectiveName(), member.getEffectiveAvatarUrl(), null);
channel.sendMessageEmbeds(builder.build()).queue();
}
Aggregations