use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class SetPlaylistItemIndexTask method perform.
@Override
public void perform(@Nullable JDA shard) {
try (Session session = sessionFactory.openSession()) {
Query<Playlist> relevantPlaylistQuery = session.createQuery("from " + Playlist.class.getName() + " as p where " + "exists(from " + Song.class.getName() + " where item_index = null and playlist_pk = p.pk) or " + "exists(from " + Video.class.getName() + " where item_index = null and playlist_pk = p.pk) or " + "exists(from " + UrlTrack.class.getName() + " where item_index = null and playlist_pk = p.pk)", Playlist.class);
List<Playlist> relevantPlaylists = relevantPlaylistQuery.getResultList();
session.beginTransaction();
UpdatePlaylistItemIndicesTask task = new UpdatePlaylistItemIndicesTask(relevantPlaylists);
task.perform();
session.getTransaction().commit();
}
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class AddCommand method withUserResponse.
@Override
public void withUserResponse(Object option) {
Session session = getContext().getSession();
String playlistName = getArgumentValue(definingArgument);
Playlist playlist = SearchEngine.searchLocalList(session, playlistName);
if (playlist == null) {
throw new NoResultsFoundException(String.format("No local list found for '%s'", getToAddString()));
}
PlayableFactory playableFactory = Aiode.get().getAudioManager().createPlayableFactory(getSpotifyService(), new BlockingTrackLoadingExecutor());
List<Playable> playables = playableFactory.createPlayables(false, option);
addPlayables(playlist, playables);
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class AddCommand method doRun.
@Override
public void doRun() throws Exception {
Session session = getContext().getSession();
if (argumentSet("queue")) {
AudioQueue queue = Aiode.get().getAudioManager().getQueue(getContext().getGuild());
if (queue.isEmpty()) {
throw new InvalidCommandException("Queue is empty");
}
Playlist playlist = SearchEngine.searchLocalList(session, getToAddString());
if (playlist == null) {
throw new NoResultsFoundException(String.format("No local list found for '%s'", getToAddString()));
}
List<Playable> tracks = queue.getTracks();
addPlayables(playlist, tracks);
} else {
if (!argumentSet(definingArgument)) {
throw new InvalidCommandException(String.format("Expected argument '%s', defining the target playlist. " + "Hint: if you meant to add tracks to the queue, use the queue command instead.", definingArgument));
}
String playlistName = getArgumentValue(definingArgument);
playlist = SearchEngine.searchLocalList(session, playlistName);
if (playlist == null) {
throw new NoResultsFoundException(String.format("No local list found for '%s'", playlistName));
}
super.doRun();
}
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class AddCommand method addToList.
protected void addToList(Playlist playlist, List<PlaylistItem> items) {
if (items.isEmpty()) {
throw new NoResultsFoundException("Result is empty!");
}
Session session = getContext().getSession();
invoke(() -> items.forEach(item -> {
item.add();
session.persist(item);
}));
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class GuildManager method handleNewGuild.
private void handleNewGuild(Guild guild, GuildContext guildContext) {
Aiode aiode = Aiode.get();
MessageService messageService = aiode.getMessageService();
try {
EmbedDocumentContribution embedDocumentContribution = embedDocumentContext.query(attribute("name").is("getting-started"), EmbedDocumentContribution.class).getOnlyResult();
if (embedDocumentContribution != null) {
EmbedBuilder embedBuilder = embedDocumentContribution.buildEmbed();
TextChannel defaultTextChannelForGuild = getDefaultTextChannelForGuild(guild, guildContext);
if (defaultTextChannelForGuild != null) {
messageService.sendWithLogo(embedBuilder, defaultTextChannelForGuild);
}
}
} catch (Exception e) {
logger.error("Error sending getting started message", e);
}
SessionFactory sessionFactory = hibernateComponent.getSessionFactory();
SpotifyApi.Builder spotifyApiBuilder = aiode.getSpotifyApiBuilder();
if (defaultPlaylistContext != null) {
try (Session session = sessionFactory.withOptions().interceptor(InterceptorChain.of(PlaylistItemTimestampInterceptor.class, VerifyPlaylistInterceptor.class)).openSession()) {
HibernatePlaylistMigrator hibernatePlaylistMigrator = new HibernatePlaylistMigrator(defaultPlaylistContext, guild, spotifyApiBuilder.build(), session);
Map<Playlist, List<PlaylistItem>> playlistMap = hibernatePlaylistMigrator.perform();
Mode mode = getMode();
HibernateInvoker.create(session).invokeConsumer(currentSession -> {
for (Playlist playlist : playlistMap.keySet()) {
Playlist existingList = SearchEngine.searchLocalList(currentSession, playlist.getName(), mode == GuildManager.Mode.PARTITIONED, guild.getId());
if (existingList == null) {
playlistMap.get(playlist).forEach(item -> {
item.add();
currentSession.persist(item);
});
currentSession.persist(playlist);
}
}
});
} catch (Exception e) {
logger.error("Exception while setting up default playlists", e);
}
}
}
Aggregations