Search in sources :

Example 21 with Playlist

use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.

the class AlertPlaylistModificationInterceptor method afterCommit.

@Override
public void afterCommit() {
    List<Playlist> createdPlaylists = getCreatedEntities(Playlist.class);
    List<Playlist> deletedPlaylists = getDeletedEntities(Playlist.class);
    List<PlaylistItem> addedItems = getCreatedEntities(PlaylistItem.class);
    List<PlaylistItem> removedItems = getDeletedEntities(PlaylistItem.class);
    if (!createdPlaylists.isEmpty()) {
        String s = createdPlaylists.size() > 1 ? "Created playlists: " : "Created playlist: ";
        messageService.sendSuccess(s + StringList.create(createdPlaylists, Playlist::getName).toSeparatedString(", "), channel);
    }
    if (!deletedPlaylists.isEmpty()) {
        String s = deletedPlaylists.size() > 1 ? "Deleted playlists: " : "Deleted playlist: ";
        messageService.sendSuccess(s + StringList.create(deletedPlaylists, Playlist::getName).toSeparatedString(", "), channel);
    }
    if (!addedItems.isEmpty()) {
        if (addedItems.size() == 1) {
            PlaylistItem item = addedItems.get(0);
            if (!createdPlaylists.contains(item.getPlaylist())) {
                messageService.sendSuccess("Added " + item.display() + " to " + item.getPlaylist().getName(), channel);
            }
        } else {
            Multimap<Playlist, PlaylistItem> playlistWithItems = HashMultimap.create();
            for (PlaylistItem playlistItem : addedItems) {
                playlistWithItems.put(playlistItem.getPlaylist(), playlistItem);
            }
            for (Playlist playlist : playlistWithItems.keySet()) {
                if (!createdPlaylists.contains(playlist)) {
                    messageService.sendSuccess("Added " + playlistWithItems.get(playlist).size() + " items to playlist " + playlist.getName(), channel);
                }
            }
        }
    }
    if (!removedItems.isEmpty()) {
        if (removedItems.size() == 1) {
            PlaylistItem item = removedItems.get(0);
            if (!deletedPlaylists.contains(item.getPlaylist())) {
                messageService.sendSuccess("Removed " + item.display() + " from " + item.getPlaylist().getName(), channel);
            }
        } else {
            Multimap<Playlist, PlaylistItem> playlistWithItems = HashMultimap.create();
            for (PlaylistItem playlistItem : removedItems) {
                playlistWithItems.put(playlistItem.getPlaylist(), playlistItem);
            }
            for (Playlist playlist : playlistWithItems.keySet()) {
                if (!deletedPlaylists.contains(playlist)) {
                    messageService.sendSuccess("Removed " + playlistWithItems.get(playlist).size() + " items from playlist " + playlist.getName(), channel);
                }
            }
        }
    }
}
Also used : Playlist(net.robinfriedli.aiode.entities.Playlist) PlaylistItem(net.robinfriedli.aiode.entities.PlaylistItem)

Example 22 with Playlist

use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.

the class SearchEngine method searchLocalList.

@Nullable
public static Playlist searchLocalList(Session session, String searchTerm) {
    String searchName = Util.normalizeWhiteSpace(searchTerm).toLowerCase();
    QueryBuilderFactory queryBuilderFactory = Aiode.get().getQueryBuilderFactory();
    return queryBuilderFactory.find(Playlist.class).where((cb, root, query) -> cb.equal(cb.lower(root.get("name")), searchName)).build(session).uniqueResultOptional().orElse(null);
}
Also used : PlaylistItem(net.robinfriedli.aiode.entities.PlaylistItem) Arrays(java.util.Arrays) Predicate(java.util.function.Predicate) Session(org.hibernate.Session) LevenshteinDistance(org.apache.commons.text.similarity.LevenshteinDistance) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Preset(net.robinfriedli.aiode.entities.Preset) Aiode(net.robinfriedli.aiode.Aiode) QueryBuilderFactory(net.robinfriedli.aiode.persist.qb.QueryBuilderFactory) List(java.util.List) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Playlist(net.robinfriedli.aiode.entities.Playlist) SpotifyService(net.robinfriedli.aiode.audio.spotify.SpotifyService) EntityQueryBuilder(net.robinfriedli.aiode.persist.qb.builders.EntityQueryBuilder) StoredScript(net.robinfriedli.aiode.entities.StoredScript) Optional(java.util.Optional) XmlElement(net.robinfriedli.jxp.api.XmlElement) PartitionedQueryInterceptor(net.robinfriedli.aiode.persist.qb.interceptor.interceptors.PartitionedQueryInterceptor) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) YouTubeService(net.robinfriedli.aiode.audio.youtube.YouTubeService) QueryBuilderFactory(net.robinfriedli.aiode.persist.qb.QueryBuilderFactory) Nullable(javax.annotation.Nullable)

Example 23 with Playlist

use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.

the class SearchEngine method searchLocalList.

@Nullable
public static Playlist searchLocalList(Session session, String searchTerm, boolean isPartitioned, String guildId) {
    String searchName = Util.normalizeWhiteSpace(searchTerm).toLowerCase();
    QueryBuilderFactory queryBuilderFactory = Aiode.get().getQueryBuilderFactory();
    EntityQueryBuilder<Playlist> queryBuilder = queryBuilderFactory.find(Playlist.class).where((cb, root, query) -> cb.equal(cb.lower(root.get("name")), searchName));
    if (isPartitioned) {
        queryBuilder.where((cb, root, query) -> cb.equal(root.get("guildId"), guildId));
    }
    return queryBuilder.skipInterceptors(PartitionedQueryInterceptor.class).build(session).uniqueResultOptional().orElse(null);
}
Also used : QueryBuilderFactory(net.robinfriedli.aiode.persist.qb.QueryBuilderFactory) Playlist(net.robinfriedli.aiode.entities.Playlist) PartitionedQueryInterceptor(net.robinfriedli.aiode.persist.qb.interceptor.interceptors.PartitionedQueryInterceptor) Nullable(javax.annotation.Nullable)

Example 24 with Playlist

use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.

the class VerifyPlaylistInterceptor method onDeleteChained.

@Override
public void onDeleteChained(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
    if (entity instanceof PlaylistItem) {
        PlaylistItem playlistItem = (PlaylistItem) entity;
        Playlist playlist = playlistItem.getPlaylist();
        if (playlistItem instanceof Song) {
            playlist.getSongs().remove(playlistItem);
        } else if (playlistItem instanceof Video) {
            playlist.getVideos().remove(playlistItem);
        } else if (playlistItem instanceof UrlTrack) {
            playlist.getUrlTracks().remove(playlistItem);
        }
    }
}
Also used : Playlist(net.robinfriedli.aiode.entities.Playlist) Song(net.robinfriedli.aiode.entities.Song) Video(net.robinfriedli.aiode.entities.Video) UrlTrack(net.robinfriedli.aiode.entities.UrlTrack) PlaylistItem(net.robinfriedli.aiode.entities.PlaylistItem)

Aggregations

Playlist (net.robinfriedli.aiode.entities.Playlist)24 Session (org.hibernate.Session)15 PlaylistItem (net.robinfriedli.aiode.entities.PlaylistItem)12 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)10 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)10 List (java.util.List)8 Playable (net.robinfriedli.aiode.audio.Playable)5 User (net.dv8tion.jda.api.entities.User)4 Aiode (net.robinfriedli.aiode.Aiode)4 UrlTrack (net.robinfriedli.aiode.entities.UrlTrack)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 AudioQueue (net.robinfriedli.aiode.audio.AudioQueue)3 PlayableFactory (net.robinfriedli.aiode.audio.PlayableFactory)3 CommandContext (net.robinfriedli.aiode.command.CommandContext)3 CommandManager (net.robinfriedli.aiode.command.CommandManager)3 Song (net.robinfriedli.aiode.entities.Song)3 CommandContribution (net.robinfriedli.aiode.entities.xml.CommandContribution)3 SearchEngine (net.robinfriedli.aiode.util.SearchEngine)3