Skip to content

Commit

Permalink
Fix a few music bugs
Browse files Browse the repository at this point in the history
- Fix lyrics not fetching correctly
- Fix /repeat not working
  • Loading branch information
DRSchlaubi committed Nov 15, 2024
1 parent 02c4467 commit e6b4e8f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion music/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subprojects {
version = "4.1.2-SNAPSHOT"
version = "4.1.3-SNAPSHOT"
}
14 changes: 13 additions & 1 deletion music/lyrics/src/main/kotlin/APIServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -51,6 +54,12 @@ import dev.schlaubi.mikbot.plugin.api.config.Config as BotConfig
private val PLAYER = AttributeKey<MusicPlayer>("MUSIC_PLAYER")
private val authKeys = mutableMapOf<String, Snowflake>()

@Serializable
private data class CurrenState(
val lyrics: Lyrics,
val time: Instant,
val position: Long
)

fun requestToken(userId: Snowflake): String {
val key = generateNonce()
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion music/lyrics/src/main/kotlin/LyricsCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/plugins.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
:music:player
:music:commands
:music:lyrics
:core:ktor

0 comments on commit e6b4e8f

Please sign in to comment.