Skip to content

Commit

Permalink
Fix issues with lyrics
Browse files Browse the repository at this point in the history
- Fix query being ignored if song is playing
- Fix server error
  • Loading branch information
DRSchlaubi committed Dec 23, 2023
1 parent 8ed2374 commit d62dc4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 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 = "3.5.2-SNAPSHOT"
version = "3.5.3-SNAPSHOT"
}
21 changes: 15 additions & 6 deletions music/lyrics/src/main/kotlin/LyricsCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalString
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import dev.schlaubi.lavakord.RestException
import dev.schlaubi.lavakord.plugins.lyrics.rest.requestLyrics
import dev.schlaubi.lavakord.plugins.lyrics.rest.searchLyrics
import dev.schlaubi.lyrics.protocol.TimedLyrics
Expand All @@ -12,6 +13,7 @@ import dev.schlaubi.mikbot.plugin.api.util.forList
import dev.schlaubi.mikmusic.checks.musicQuizAntiCheat
import dev.schlaubi.mikmusic.util.musicModule
import dev.schlaubi.stdx.core.paginate
import io.ktor.http.*

class LyricsArguments : Arguments() {
val name by optionalString {
Expand Down Expand Up @@ -42,12 +44,19 @@ suspend fun Extension.lyricsCommand() = publicSlashCommand(::LyricsArguments) {

return@action
}
val lyrics = if (player.playingTrack != null) {
player.requestLyrics()
} else {
val (videoId) = link.node.searchLyrics(query).firstOrNull()
?: discordError(translate("command.lyrics.no_lyrics"))
link.node.requestLyrics(videoId)
val lyrics = try {
if (arguments.name != null && player.playingTrack != null) {
player.requestLyrics()
} else {
val (videoId) = link.node.searchLyrics(query).firstOrNull()
?: discordError(translate("command.lyrics.no_lyrics"))
link.node.requestLyrics(videoId)
}
} catch (e: RestException) {
if (e.request.call.response.status == HttpStatusCode.NotFound) {
discordError(translate("command.lyrics.no_lyrics"))
}
throw e
}

val lines = if (lyrics is TimedLyrics) {
Expand Down

0 comments on commit d62dc4c

Please sign in to comment.