use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Seek method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
AudioPlayer audioPlayer = musicManager.scheduler.player;
if (ctx.getArgs().isEmpty()) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "Right format is MM:SS", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
if (audioPlayer.getPlayingTrack() == null) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
String arg = ctx.getArgs().get(0);
Matcher match = Pattern.compile("([0-9]{1,2})[:ms](([0-9]{1,2})s?)?").matcher(arg);
if (!match.matches()) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "Right format is MM:SS", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
long secs = -1;
if (match.group(3).length() > 0) {
int g1 = Integer.parseInt(match.group(1)) * 60;
int g2 = Integer.parseInt(match.group(3));
secs = g1 + g2;
} else {
secs = Integer.parseInt(match.group(1));
}
if (secs < 0) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "Error formatting timestamp !", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
audioPlayer.setPaused(false);
audioPlayer.getPlayingTrack().setPosition(secs * 1000);
EmbedBuilder builder = Embeds.createBuilder(null, "Sought", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Shuffle method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
List<AudioTrack> queue = musicManager.scheduler.queue;
if (queue.isEmpty()) {
channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
return;
}
Collections.shuffle(musicManager.scheduler.queue);
EmbedBuilder builder = Embeds.createBuilder(null, "Queue shuffled", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Listener method onGuildVoiceUpdate.
@Override
public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
if (event.getMember().getUser() != event.getGuild().getSelfMember().getUser()) {
VoiceChannel channelLeft = event.getChannelLeft();
if (channelLeft == null) {
return;
}
List<Member> members = channelLeft.getMembers();
List<Member> copy = new ArrayList<>();
boolean canClose = false;
for (Member member : members) {
if (member.getUser() != event.getGuild().getSelfMember().getUser()) {
copy.add(member);
} else {
canClose = true;
}
}
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
if (canClose && !copy.isEmpty() && musicManager.scheduler.votingGoingOn) {
musicManager.scheduler.totalMembers = copy;
}
if (copy.isEmpty() && canClose) {
musicManager.scheduler.isRepeating = false;
musicManager.scheduler.queue.clear();
musicManager.scheduler.player.stopTrack();
// **RESET EVERYTHING**
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.votes.clear();
musicManager.scheduler.votingGoingOn = false;
AudioManager audioManager = event.getGuild().getAudioManager();
audioManager.closeAudioConnection();
}
} else if (event.getMember().getUser() == event.getGuild().getSelfMember().getUser()) {
if (event.getChannelLeft() != null && event.getChannelJoined() != null) {
VoiceChannel channelJoined = event.getChannelJoined();
List<Member> members = channelJoined.getMembers();
List<Member> copy = new ArrayList<>();
boolean canClose = false;
for (Member member : members) {
if (member.getUser() != event.getGuild().getSelfMember().getUser()) {
copy.add(member);
} else {
canClose = true;
}
}
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
// **RESET EVERYTHING**
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.votes.clear();
musicManager.scheduler.votingGoingOn = false;
if (copy.isEmpty() && canClose) {
musicManager.scheduler.isRepeating = false;
musicManager.scheduler.queue.clear();
musicManager.scheduler.player.stopTrack();
AudioManager audioManager = event.getGuild().getAudioManager();
audioManager.closeAudioConnection();
}
} else if (event.getChannelLeft() != null && event.getChannelJoined() == null) {
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
musicManager.scheduler.isRepeating = false;
musicManager.scheduler.queue.clear();
musicManager.scheduler.player.stopTrack();
// **RESET EVERYTHING**
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.votes.clear();
musicManager.scheduler.votingGoingOn = false;
}
}
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Listener method onGuildLeave.
@Override
public void onGuildLeave(@NotNull GuildLeaveEvent event) {
this.jda.getPresence().setActivity(Activity.listening("help on " + event.getJDA().getGuilds().size() + " Guilds"));
Member selfMember = event.getGuild().getSelfMember();
if (selfMember.getVoiceState().inVoiceChannel()) {
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
musicManager.scheduler.isRepeating = false;
musicManager.scheduler.queue.clear();
musicManager.scheduler.player.stopTrack();
// **RESET EVERYTHING**
musicManager.scheduler.totalMembers.clear();
musicManager.scheduler.votes.clear();
musicManager.scheduler.votingGoingOn = false;
AudioManager audioManager = event.getGuild().getAudioManager();
audioManager.closeAudioConnection();
}
PlayerManager.getInstance().removeGuildMusicManager(event.getGuild());
LOGGER.info("Left " + event.getGuild().getName() + " guild Deleting the music manager");
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class ForceSkip method handle.
@Override
public void handle(CommandContext ctx) {
TextChannel channel = ctx.getChannel();
Member member = ctx.getMember();
GuildMusicManager manager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
if (!member.hasPermission(Permission.MESSAGE_MANAGE)) {
channel.sendMessageEmbeds(Embeds.createBuilder(null, "You do not have enough permission", null, null, null).build()).queue();
return;
}
if (manager.audioPlayer.getPlayingTrack() == null) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
if (manager.scheduler.votingGoingOn) {
manager.scheduler.totalMembers.clear();
manager.scheduler.votes.clear();
manager.scheduler.votingGoingOn = false;
}
manager.scheduler.nextTrack();
EmbedBuilder builder = Embeds.createBuilder(null, "Skipped the current track", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
Aggregations