Skip to content

Commit

Permalink
Add support for lyrics plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Dec 17, 2023
1 parent b3e5c4f commit d7e67d7
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "dev.schlaubi.lavakord"
version = "6.0.0"
version = "6.1.0"

allprojects {
repositories {
Expand Down
38 changes: 38 additions & 0 deletions plugins/lyrics/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinMultiplatform
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
`lavalink-module`
`lavalink-publishing`
kotlin("plugin.serialization")
}

kotlin {
jvm {
compilations.all {
compilerOptions.configure {
jvmTarget = JvmTarget.JVM_17
}
}
}

sourceSets {
all {
languageSettings.optIn("kotlin.contracts.ExperimentalContracts")
languageSettings.optIn("dev.schlaubi.lavakord.PluginApi")
languageSettings.optIn("dev.schlaubi.lavakord.UnsafeRestApi")
}
commonMain {
dependencies {
api(projects.core)
implementation(libs.ktor.client.resources)
api(libs.lyrics.protocol)
}
}
}
}

mavenPublishing {
configure(KotlinMultiplatform(JavadocJar.Dokka("dokkaHtml")))
}
18 changes: 18 additions & 0 deletions plugins/lyrics/src/commonMain/kotlin/Plugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.schlaubi.lavakord.plugins.lyrics

import dev.schlaubi.lavakord.Plugin
import kotlinx.serialization.json.Json

/**
* Bindings for the [Lyrics plugin](https://github.com/DRSchlaubi/lyrics.kt).
*
* ```kotlin
* plugins {
* install(Lyrics)
* }
* ```
*/
public object Lyrics : Plugin {
override val name: String = "lyrics"
override val version: String = "1.0.1"
}
24 changes: 24 additions & 0 deletions plugins/lyrics/src/commonMain/kotlin/rest/Rest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.schlaubi.lavakord.plugins.lyrics.rest

import dev.schlaubi.lavakord.audio.Node
import dev.schlaubi.lavakord.audio.player.Player
import dev.schlaubi.lavakord.audio.player.guildId
import dev.schlaubi.lavakord.audio.player.node
import dev.schlaubi.lavakord.rest.get
import dev.schlaubi.lyrics.protocol.Lyrics
import dev.schlaubi.lyrics.protocol.SearchTrack

/**
* Requests the lyrics by [videoId].
*/
public suspend fun Node.requestLyrics(videoId: String): Lyrics = get(LyricsRoute.Video(videoId))

/**
* Searches for [query].
*/
public suspend fun Node.searchLyrics(query: String): List<SearchTrack> = get(LyricsRoute.Search(query))

/**
* Requests the lyrics of the currently playing track.
*/
public suspend fun Player.requestLyrics(): Lyrics = node.get(LyricsRoute.CurrentLyrics(node.sessionId, guildId))
26 changes: 26 additions & 0 deletions plugins/lyrics/src/commonMain/kotlin/rest/Route.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@file:Suppress("KDocMissingDocumentation")

package dev.schlaubi.lavakord.plugins.lyrics.rest

import dev.schlaubi.lavakord.rest.routes.V4Api
import io.ktor.resources.*

@Resource("lyrics")
internal data class LyricsRoute(val parent: V4Api = V4Api()) {

@Resource("lyrics/search/{query}")
data class Search(val query: String, val parent: LyricsRoute = LyricsRoute())

@Resource("{videoId}")
data class Video(val videoId: String, val parent: LyricsRoute = LyricsRoute())

@Resource("lyrics")
data class CurrentLyrics(val players: V4Api.Sessions.Specific.Players.Specific) {
constructor(sessionId: String, guildId: ULong) : this(
V4Api.Sessions.Specific.Players.Specific(
guildId,
sessionId
)
)
}
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include(
":plugins:sponsorblock",
":plugins:lavasrc",
":plugins:lavasearch",
":plugins:lyrics",
"java",
"jda",
"jda-java"
Expand Down Expand Up @@ -56,6 +57,7 @@ dependencyResolutionManagement {
library("kotlinx-nodejs", "org.jetbrains.kotlin-wrappers", "kotlin-node").version("18.16.12-pre.594")

library("lavalink-protocol", "dev.arbjerg.lavalink", "protocol").version("4.0.0")
library("lyrics-protocol", "dev.schlaubi.lyrics", "protocol").version("1.0.1")
library(
"lavasearch-protocol",
"com.github.topi314.lavasearch",
Expand Down

0 comments on commit d7e67d7

Please sign in to comment.