use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Clear method handle.
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
final List<AudioTrack> queue = musicManager.scheduler.queue;
if (queue.isEmpty()) {
channel.sendMessageEmbeds(Embeds.queueIsEmptyEmbed().build()).queue();
return;
}
musicManager.scheduler.queue.clear();
EmbedBuilder builder = Embeds.createBuilder(null, "💥 The queue has been cleared", null, null, null);
channel.sendMessageEmbeds(builder.build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class Favourite method handle.
@Override
public void handle(CommandContext ctx) {
TextChannel channel = ctx.getChannel();
long guildId = ctx.getGuild().getIdLong();
long userId = ctx.getMember().getIdLong();
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;
}
AudioTrack playingTrack = musicManager.scheduler.player.getPlayingTrack();
ArrayList<HashMap<String, String>> favourites = RedisDataStore.getInstance().getFavourites(guildId, userId);
for (HashMap<String, String> entry : favourites) {
if (entry.get("identifier").equals(playingTrack.getIdentifier())) {
channel.sendMessageEmbeds(Embeds.createBuilder("Error!", "This track is already in your list", null, null, null).build()).queue();
return;
}
}
ObjectId objectId = new ObjectId();
RedisDataStore.getInstance().addFavourite(guildId, userId, playingTrack, ctx.getGuild(), String.valueOf(objectId));
DatabaseManager.INSTANCE.addFavourite(guildId, userId, playingTrack, ctx.getGuild(), String.valueOf(objectId));
channel.sendMessageEmbeds(Embeds.createBuilder(null, "Added this track to your favourites", null, null, null).build()).queue();
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class SpotifyAudioSource method searchTrack.
@Override
public void searchTrack(CommandContext ctx, String query, EventWaiter waiter) {
try {
TextChannel channel = ctx.getChannel();
Paging<Track> execute = this.spi.searchTracks(query).build().execute();
Track[] items = execute.getItems();
if (items[0] == null) {
ctx.getChannel().sendMessageEmbeds(Embeds.createBuilder(null, "Couldn't find anything on spotify", null, null, null).build()).queue();
return;
}
EmbedBuilder builder = EmbedUtils.getDefaultEmbed();
builder.setDescription("Select a track. You have 15 seconds");
final int trackCount = Math.min(items.length, 20);
String s = UUID.randomUUID().toString();
SelectionMenu.Builder menu = SelectionMenu.create(s);
menu.setPlaceholder("Select your track here");
menu.setRequiredRange(1, 1);
for (int i = 0; i < trackCount; i++) {
final Track track = items[i];
menu.addOption(track.getName(), track.getName() + " " + track.getArtists()[0].getName() + " index " + i, track.getArtists()[0].getName());
}
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
channel.sendMessageEmbeds(builder.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) -> {
String q = e.getValues().get(0);
q = q.substring(0, q.indexOf("index")).trim();
final String sQuery = "ytsearch:" + q;
PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, sQuery, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
List<AudioTrack> tracks = playlist.getTracks();
if (tracks.isEmpty())
return;
AudioTrack audioTrack = tracks.get(0);
message.delete().queue();
channel.sendMessageEmbeds(Embeds.songEmbed(ctx.getMember(), audioTrack).build()).queue();
audioTrack.setUserData(ctx.getAuthor().getIdLong());
musicManager.scheduler.queue(audioTrack);
}
@Override
public void noMatches() {
}
@Override
public void loadFailed(FriendlyException exception) {
}
});
}, 15, TimeUnit.SECONDS, () -> {
message.delete().queue();
});
});
} catch (Exception e) {
e.printStackTrace();
}
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class SpotifyAudioSource method getTrack.
public void getTrack(CommandContext ctx, String url) {
final Matcher res = SPOTIFY_TRACK_REGEX.matcher(url);
if (!res.matches()) {
return;
}
try {
GetTrackRequest request = this.spi.getTrack(res.group(res.groupCount())).build();
Track track = request.execute();
LOGGER.info("Name: " + track.getName());
LOGGER.info("Artist: " + track.getArtists()[0].getName());
String query = "ytsearch:" + track.getName() + " " + track.getArtists()[0].getName();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, query, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
System.out.println("track loaded");
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
boolean empty = playlist.getTracks().isEmpty();
if (empty) {
return;
}
AudioTrack audioTrack = playlist.getTracks().get(0);
audioTrack.setUserData(ctx.getAuthor().getIdLong());
ctx.getChannel().sendMessageEmbeds(Embeds.songEmbed(ctx.getMember(), audioTrack).setDescription("[" + audioTrack.getInfo().title + " - " + audioTrack.getInfo().author + "]" + "(" + track.getExternalUrls().get("spotify") + ")").build()).queue();
musicManager.scheduler.queue(audioTrack);
}
@Override
public void noMatches() {
}
@Override
public void loadFailed(FriendlyException exception) {
}
});
} catch (IOException | SpotifyWebApiException | ParseException e) {
e.printStackTrace();
}
}
use of me.fero.ascent.lavaplayer.GuildMusicManager in project ascent_bot by FeroniK.
the class SpotifyAudioSource method getAlbum.
public void getAlbum(CommandContext ctx, String url) {
final Matcher res = SPOTIFY_ALBUM_REGEX.matcher(url);
if (!res.matches()) {
return;
}
try {
final Future<Album> albumFuture = this.spi.getAlbum(res.group(res.groupCount())).build().executeAsync();
final Album album = albumFuture.get();
TrackSimplified[] items = album.getTracks().getItems();
ctx.getChannel().sendMessageEmbeds(Embeds.createBuilder(null, "Spotify Album Loaded : Adding " + items.length + " Tracks to the queue", null, null, null).build()).queue();
for (final TrackSimplified track : items) {
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(ctx.getGuild());
final String query = "ytsearch:" + track.getName() + " " + track.getArtists()[0].getName();
PlayerManager.getInstance().audioPlayerManager.loadItemOrdered(musicManager, query, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
boolean empty = playlist.getTracks().isEmpty();
if (empty) {
return;
}
AudioTrack audioTrack = playlist.getTracks().get(0);
audioTrack.setUserData(ctx.getAuthor().getIdLong());
musicManager.scheduler.queue(audioTrack);
}
@Override
public void noMatches() {
}
@Override
public void loadFailed(FriendlyException exception) {
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations