-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4deebee
commit 521b9c6
Showing
10 changed files
with
264 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
core/src/commonMain/kotlin/dev/schlaubi/lavakord/audio/internal/AbstractLavakord.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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") | ||
alias(libs.plugins.ksp) | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
compilations.all { | ||
compilerOptions.configure { | ||
jvmTarget = JvmTarget.JVM_11 | ||
} | ||
} | ||
} | ||
sourceSets { | ||
all { | ||
languageSettings.optIn("kotlin.contracts.ExperimentalContracts") | ||
languageSettings.optIn("dev.schlaubi.lavakord.PluginApi") | ||
languageSettings.optIn("dev.schlaubi.lavakord.UnsafeRestApi") | ||
} | ||
commonMain { | ||
kotlin.srcDir(layout.buildDirectory.dir("generated/ksp/metadata/commonMain/kotlin")) | ||
dependencies { | ||
api(projects.core) | ||
api(libs.lavasearch.protocol) | ||
|
||
implementation(libs.ktor.client.resources) | ||
implementation(libs.kord.ksp.annotations) | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
kspCommonMainMetadata(libs.kord.ksp.processors) | ||
} | ||
|
||
tasks { | ||
listOf("sourcesJar", "jsSourcesJar", "jvmSourcesJar", "compileKotlinJs", "compileKotlinJvm", "dokkaHtml").forEach { | ||
named(it) { | ||
dependsOn("kspCommonMainKotlinMetadata") | ||
} | ||
} | ||
} | ||
|
||
mavenPublishing { | ||
configure(KotlinMultiplatform(JavadocJar.Dokka("dokkaHtml"))) | ||
} |
97 changes: 97 additions & 0 deletions
97
...p/metadata/commonMain/kotlin/dev/schlaubi/lavakord/plugins/lavasearch/model/SearchType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! | ||
@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", | ||
"ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) | ||
|
||
package dev.schlaubi.lavakord.plugins.lavasearch.model | ||
|
||
import kotlin.Any | ||
import kotlin.Boolean | ||
import kotlin.Int | ||
import kotlin.LazyThreadSafetyMode.PUBLICATION | ||
import kotlin.String | ||
import kotlin.Suppress | ||
import kotlin.collections.List | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
/** | ||
* See [SearchType]s in the | ||
* [Discord Developer Documentation](https://github.com/topi314/LavaSearch?tab=readme-ov-file#api). | ||
*/ | ||
@Serializable(with = SearchType.Serializer::class) | ||
public sealed class SearchType( | ||
/** | ||
* The raw value used by Discord. | ||
*/ | ||
public val `value`: String, | ||
) { | ||
public final override fun equals(other: Any?): Boolean = this === other || | ||
(other is SearchType && this.value == other.value) | ||
|
||
public final override fun hashCode(): Int = value.hashCode() | ||
|
||
public final override fun toString(): String = | ||
"SearchType.${this::class.simpleName}(value=$value)" | ||
|
||
/** | ||
* An unknown [SearchType]. | ||
* | ||
* This is used as a fallback for [SearchType]s that haven't been added to Kord yet. | ||
*/ | ||
public class Unknown( | ||
`value`: String, | ||
) : SearchType(value) | ||
|
||
public object Track : SearchType("track") | ||
|
||
public object Album : SearchType("album") | ||
|
||
public object Artist : SearchType("artist") | ||
|
||
public object Playlist : SearchType("playlist") | ||
|
||
/** | ||
* Search suggestions | ||
*/ | ||
public object Text : SearchType("text") | ||
|
||
internal object Serializer : KSerializer<SearchType> { | ||
public override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("dev.schlaubi.lavakord.plugins.lavasearch.model.SearchType", | ||
PrimitiveKind.STRING) | ||
|
||
public override fun serialize(encoder: Encoder, `value`: SearchType) = | ||
encoder.encodeString(value.value) | ||
|
||
public override fun deserialize(decoder: Decoder) = | ||
when (val value = decoder.decodeString()) { | ||
"track" -> Track | ||
"album" -> Album | ||
"artist" -> Artist | ||
"playlist" -> Playlist | ||
"text" -> Text | ||
else -> Unknown(value) | ||
} | ||
} | ||
|
||
public companion object { | ||
/** | ||
* A [List] of all known [SearchType]s. | ||
*/ | ||
public val entries: List<SearchType> by lazy(mode = PUBLICATION) { | ||
listOf( | ||
Track, | ||
Album, | ||
Artist, | ||
Playlist, | ||
Text, | ||
) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dev.schlaubi.lavakord.plugins.lavasearch | ||
|
||
import dev.schlaubi.lavakord.Plugin | ||
|
||
/** | ||
* Bindings for the [LavaSrc plugin](https://github.com/topi314/LavaSearch). | ||
* | ||
* ```kotlin | ||
* plugins { | ||
* install(LavaSearch) | ||
* } | ||
* ``` | ||
*/ | ||
public object LavaSearch : Plugin { | ||
override val name: String = "lavasearch-plugin" | ||
override val version: String = "4.0.0-beta.3" | ||
} |
36 changes: 36 additions & 0 deletions
36
plugins/lavasearch/src/commonMain/kotlin/model/SearchType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@file:GenerateKordEnum( | ||
"SearchType", | ||
GenerateKordEnum.ValueType.STRING, | ||
docUrl = "https://github.com/topi314/LavaSearch?tab=readme-ov-file#api", | ||
entries = [ | ||
GenerateKordEnum.Entry( | ||
"Track", | ||
stringValue = "track", | ||
kDoc = "Tracks." | ||
), | ||
GenerateKordEnum.Entry( | ||
"Album", | ||
stringValue = "album", | ||
kDoc = "Album." | ||
), | ||
GenerateKordEnum.Entry( | ||
"Artist", | ||
stringValue = "artist", | ||
kDoc = "Artists." | ||
), | ||
GenerateKordEnum.Entry( | ||
"Playlist", | ||
stringValue = "playlist", | ||
kDoc = "Playlists." | ||
), | ||
GenerateKordEnum.Entry( | ||
"Text", | ||
stringValue = "text", | ||
kDoc = "Search suggestions." | ||
) | ||
] | ||
) | ||
|
||
package dev.schlaubi.lavakord.plugins.lavasearch.model | ||
|
||
import dev.kord.ksp.GenerateKordEnum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.schlaubi.lavakord.plugins.lavasearch.rest | ||
|
||
import com.github.topi314.lavasearch.protocol.SearchResult | ||
import dev.schlaubi.lavakord.audio.Link | ||
import dev.schlaubi.lavakord.audio.Node | ||
import dev.schlaubi.lavakord.plugins.lavasearch.model.SearchType | ||
import dev.schlaubi.lavakord.rest.get | ||
|
||
/** | ||
* Searches for [query]. | ||
* | ||
* @param types the allowed [SearchTypes][SearchType] | ||
* @see SearchResult | ||
*/ | ||
public suspend fun Node.search(query: String, vararg types: SearchType): SearchResult = | ||
search(query, types.asIterable()) | ||
|
||
/** | ||
* Searches for [query]. | ||
* | ||
* @param types the allowed [SearchTypes][SearchType] | ||
* @see SearchResult | ||
*/ | ||
public suspend fun Node.search(query: String, types: Iterable<SearchType>): SearchResult = | ||
get(LavaSearchRoute(query, types.toList())) | ||
|
||
/** | ||
* Searches for [query]. | ||
* | ||
* @param types the allowed [SearchTypes][SearchType] | ||
* @see SearchResult | ||
*/ | ||
public suspend fun Link.search(query: String, vararg types: SearchType): SearchResult = node.search(query, *types) | ||
|
||
/** | ||
* Searches for [query]. | ||
* | ||
* @param types the allowed [SearchTypes][SearchType] | ||
* @see SearchResult | ||
*/ | ||
public suspend fun Link.search(query: String, types: Iterable<SearchType>): SearchResult = node.search(query, types) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.schlaubi.lavakord.plugins.lavasearch.rest | ||
|
||
import dev.schlaubi.lavakord.plugins.lavasearch.model.SearchType | ||
import dev.schlaubi.lavakord.rest.routes.V4Api | ||
import io.ktor.resources.* | ||
|
||
@Resource("loadsearch") | ||
internal data class LavaSearchRoute(val query: String, val types: List<SearchType>, val player: V4Api = V4Api()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters