use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Queue method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
final List<AudioTrack> queue = musicManager.scheduler.queue;
if (queue.isEmpty()) {
channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
return;
}
final int trackCount = Math.min(queue.size(), 20);
final List<AudioTrack> trackList = new ArrayList<>(queue);
EmbedBuilder builder = EmbedUtils.getDefaultEmbed();
builder.setTitle("Queue for " + ctx.getGuild().getName() + " 📀");
builder.setFooter("Requested by " + ctx.getMember().getEffectiveName(), ctx.getMember().getEffectiveAvatarUrl());
for (int i = 0; i < trackCount; i++) {
final AudioTrack track = trackList.get(i);
final AudioTrackInfo info = track.getInfo();
builder.appendDescription(i + 1 + ". `" + info.title + "" + " by " + info.author + "`" + "\n");
}
if (trackList.size() > trackCount) {
builder.appendDescription("And `" + String.valueOf(trackList.size() - trackCount) + "` more...");
}
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Remove method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
Guild guild = ctx.getGuild();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);
List<AudioTrack> queue = musicManager.scheduler.queue;
if (queue.isEmpty()) {
channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
return;
}
String s = UUID.randomUUID().toString();
SelectionMenu.Builder menu = SelectionMenu.create(s);
menu.setPlaceholder("Select a track here");
menu.setRequiredRange(1, 1);
for (AudioTrack track : queue) {
AudioTrackInfo info = track.getInfo();
menu.addOption(info.title, String.valueOf(queue.indexOf(track)), info.author);
}
channel.sendMessageEmbeds(Embeds.createBuilder(null, "Select a track that you want to remove", null, null, null).build()).setActionRow(menu.build()).queue((message) -> {
waiter.waitForEvent(SelectionMenuEvent.class, (e) -> {
if (!(e.getChannel() == channel && e.getMember() != null && !e.getMember().getUser().isBot() && e.getComponentId().equals(s))) {
return false;
}
if (e.getMember() != ctx.getMember()) {
e.reply("This menu is not for you").setEphemeral(true).queue();
return false;
}
return true;
}, (e) -> {
int index = Integer.parseInt(e.getValues().get(0));
message.delete().queue();
try {
queue.remove(index);
channel.sendMessageEmbeds(Embeds.createBuilder(null, "Track removed successfully", null, null, null).build()).queue();
} catch (Exception ex) {
channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Error removing the track", null, null, null).build()).queue();
}
}, 10, TimeUnit.SECONDS, () -> {
message.delete().queue();
});
});
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Restart method handle.
@Override
@SuppressWarnings("ConstantConditions")
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
AudioPlayer audioPlayer = musicManager.scheduler.player;
if (audioPlayer.getPlayingTrack() == null) {
channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "There is no track currently playing", null, null, null).build()).queue();
return;
}
audioPlayer.setPaused(false);
audioPlayer.getPlayingTrack().setPosition(0);
channel.sendMessageEmbeds(Embeds.createBuilder(null, "Track starting from beginning", null, null, null).build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class SkipTo method handle.
@Override
public void handle(CommandContext ctx) {
TextChannel channel = ctx.getChannel();
List<String> args = ctx.getArgs();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
List<AudioTrack> queue = musicManager.scheduler.queue;
if (args.isEmpty()) {
// TODO: ERROR
return;
}
if (queue.isEmpty()) {
channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
return;
}
int i1 = -1;
try {
i1 = Integer.parseInt(args.get(0)) - 1;
} catch (NumberFormatException e) {
channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Wrong input", null, null, null).build()).queue();
return;
}
if (i1 < 0) {
channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Wrong input", null, null, null).build()).queue();
return;
}
if (i1 > queue.size()) {
channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "Wrong input", null, null, null).build()).queue();
return;
}
musicManager.scheduler.player.startTrack(queue.get(i1), false);
for (int i = 0; i < i1 + 1; i++) {
queue.remove(i);
}
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Stop method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
if (musicManager.scheduler.player.getPlayingTrack() == null) {
EmbedBuilder builder = Embeds.createBuilder("Error!", "No track playing", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
return;
}
musicManager.scheduler.player.stopTrack();
musicManager.scheduler.queue.clear();
musicManager.scheduler.isRepeating = false;
EmbedBuilder builder = Embeds.createBuilder(null, "💥 Player stopped and cleared the queue", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
Aggregations