Search in sources :

Example 1 with UserPlaybackHistory

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

the class AudioManager method createHistoryEntry.

void createHistoryEntry(Playable playable, Guild guild, VoiceChannel voiceChannel) {
    HistoryPool.execute(() -> {
        try {
            hibernateComponent.consumeSession(session -> {
                PlaybackHistory playbackHistory = new PlaybackHistory(LocalDateTime.now(), playable, guild, session);
                session.persist(playbackHistory);
                if (voiceChannel != null) {
                    Member selfMember = guild.getSelfMember();
                    for (Member member : voiceChannel.getMembers()) {
                        if (!member.equals(selfMember)) {
                            UserPlaybackHistory userPlaybackHistory = new UserPlaybackHistory(member.getUser(), playbackHistory);
                            session.persist(userPlaybackHistory);
                        }
                    }
                }
            });
        } catch (Exception e) {
            logger.error("Exception while creating playback history entry", e);
        }
    });
}
Also used : PlaybackHistory(net.robinfriedli.aiode.entities.PlaybackHistory) UserPlaybackHistory(net.robinfriedli.aiode.entities.UserPlaybackHistory) Member(net.dv8tion.jda.api.entities.Member) UserPlaybackHistory(net.robinfriedli.aiode.entities.UserPlaybackHistory) InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException)

Aggregations

Member (net.dv8tion.jda.api.entities.Member)1 InsufficientPermissionException (net.dv8tion.jda.api.exceptions.InsufficientPermissionException)1 PlaybackHistory (net.robinfriedli.aiode.entities.PlaybackHistory)1 UserPlaybackHistory (net.robinfriedli.aiode.entities.UserPlaybackHistory)1 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)1