diff --git a/music/build.gradle.kts b/music/build.gradle.kts index 4ef1dc30..52a435a6 100644 --- a/music/build.gradle.kts +++ b/music/build.gradle.kts @@ -1,3 +1,3 @@ subprojects { - version = "4.1.2-SNAPSHOT" + version = "4.1.3-SNAPSHOT" } diff --git a/music/lyrics/src/main/kotlin/APIServer.kt b/music/lyrics/src/main/kotlin/APIServer.kt index fdb68f9e..39726795 100644 --- a/music/lyrics/src/main/kotlin/APIServer.kt +++ b/music/lyrics/src/main/kotlin/APIServer.kt @@ -15,6 +15,7 @@ import dev.schlaubi.lavakord.audio.TrackStartEvent import dev.schlaubi.lavakord.audio.on import dev.schlaubi.lavakord.audio.player.Player import dev.schlaubi.lavakord.plugins.lyrics.rest.requestLyrics +import dev.schlaubi.lyrics.protocol.Lyrics import dev.schlaubi.lyrics.protocol.TimedLyrics import dev.schlaubi.mikbot.plugin.api.config.Environment import dev.schlaubi.mikbot.util_plugins.ktor.api.KtorExtensionPoint @@ -41,6 +42,8 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.datetime.Clock +import kotlinx.datetime.Instant +import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import org.koin.core.component.inject import org.pf4j.Extension @@ -51,6 +54,12 @@ import dev.schlaubi.mikbot.plugin.api.config.Config as BotConfig private val PLAYER = AttributeKey("MUSIC_PLAYER") private val authKeys = mutableMapOf() +@Serializable +private data class CurrenState( + val lyrics: Lyrics, + val time: Instant, + val position: Long +) fun requestToken(userId: Snowflake): String { val key = generateNonce() @@ -111,7 +120,10 @@ class APIServer : KtorExtensionPoint, KordExKoinComponent { get("current") { val player = call.userId.findPlayer() - call.respond(player.player.requestLyrics().takeIf { it is TimedLyrics } ?: notFound()) + val lyrics = player.player.requestLyrics().takeIf { it is TimedLyrics } ?: notFound() + val state = CurrenState(lyrics, Clock.System.now(), player.player.position) + + call.respond(state) } route("events") { diff --git a/music/lyrics/src/main/kotlin/LyricsCommand.kt b/music/lyrics/src/main/kotlin/LyricsCommand.kt index b8fc2b24..a8388789 100644 --- a/music/lyrics/src/main/kotlin/LyricsCommand.kt +++ b/music/lyrics/src/main/kotlin/LyricsCommand.kt @@ -46,7 +46,7 @@ suspend fun Extension.lyricsCommand() = publicSlashCommand(::LyricsArguments) { return@action } val lyrics = try { - if (arguments.name != null && player.playingTrack != null) { + if (arguments.name == null && player.playingTrack != null) { player.requestLyrics() } else { val (videoId) = link.node.searchLyrics(query).firstOrNull() diff --git a/music/player/src/main/kotlin/dev/schlaubi/mikmusic/player/MusicPlayer.kt b/music/player/src/main/kotlin/dev/schlaubi/mikmusic/player/MusicPlayer.kt index 47bdba9d..45d82857 100644 --- a/music/player/src/main/kotlin/dev/schlaubi/mikmusic/player/MusicPlayer.kt +++ b/music/player/src/main/kotlin/dev/schlaubi/mikmusic/player/MusicPlayer.kt @@ -315,7 +315,7 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) : Link by li if (autoPlayTrack != null) { queue.addTracks(SimpleQueuedTrack(autoPlayTrack, guild.kord.selfId)) } - if (queue.isEmpty()) { + if (queue.isEmpty() && !repeat) { updateMusicChannelMessage() return } diff --git a/runtime/plugins.txt b/runtime/plugins.txt index bd7ba8fe..5fd25a30 100644 --- a/runtime/plugins.txt +++ b/runtime/plugins.txt @@ -1,2 +1,4 @@ :music:player :music:commands +:music:lyrics +:core:ktor