diff --git a/README.md b/README.md
index d4cddc9ff51..26e6f3bf4b1 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ you to try out our library, we don't recommend you use this in production just y
If you have any feedback, we'd love to hear it, hit us up on discord or write up an issue if you have any suggestions!
-## What is Kord
+## What is Kord?
Kord is a [coroutine-based](https://kotlinlang.org/docs/reference/coroutines-overview.html), modularized implementation
of the Discord API, written 100% in [Kotlin](https://kotlinlang.org/).
@@ -26,28 +26,42 @@ unconventional things, and we want to allow you to do those in a safe and suppor
## Status of Kord
-* [X] [Discord Gateway](https://github.com/kordlib/kord/tree/master/gateway)
-* [x] [Discord Rest API](https://github.com/kordlib/kord/tree/master/rest)
-* [X] [High level abstraction + caching](https://github.com/kordlib/kord/tree/master/core)
-* [X] [Discord Voice](https://github.com/kordlib/kord/tree/master/voice)
+* [X] [Discord Gateway](gateway)
+* [x] [Discord Rest API](rest)
+* [X] [High level abstraction + caching](core)
+* [X] [Discord Voice](voice)
* [ ] Support for multiple processes [#7](https://github.com/kordlib/kord/issues/7)
-Right now Kord *should* provide a full mapping of the non-voice API. We're currently working on a testing library for
-easy bot testing against a semi mocked client as well as our own command system to facilitate more complex bot
-development.
+Right now, Kord *should* provide a full mapping of the non-voice API on Kotlin/JVM and Kotlin/JS and an experimental
+mapping of the Voice API on Kotlin/JVM
## Documentation
* [Dokka docs](https://kordlib.github.io/kord/)
* [Wiki](https://github.com/kordlib/kord/wiki)
+## Modules
+
+| Module | Docs | Artifact | JVM | JS | Native² |
+|--------------------------|---------------------------------------------------------|-------------------|-----|----|---------|
+| [common](common) | [common](https://kordlib.github.io/kord/common) | `kord-common`¹ | ✅ | ✅ | ❌ |
+| [rest](rest) | [rest](https://kordlib.github.io/kord/rest) | `kord-rest`¹ | ✅ | ✅ | ❌ |
+| [gateway](gateway) | [gateway](https://kordlib.github.io/kord/gateway) | `kord-gateway`¹ | ✅ | ✅ | ❌ |
+| [core](core) | [core](https://kordlib.github.io/kord/core) | `kord-core`¹ | ✅ | ✅ | ❌ |
+| [voice](voice) | [voice](https://kordlib.github.io/kord/voice) | `kord-voice` | ✅ | ❌³ | ❌ |
+| [core-voice](core-voice) | [core-voice](https://kordlib.github.io/kord/core-voice) | `kord-core-voice` | ✅ | ❌ | ❌ |
+
+¹ These artifacts only supports Gradle Version 5.3 or higher, for older Gradle versions and Maven please append `-jvm`
+² For Native Support please see #69
+³ For Voice JS please see #69
+
## Installation
Replace `{version}` with the latest version number on maven central.
-For Snapshots replace `{version}` with `{branch}-SNAPSHOT`
+For Snapshots replace `{version}` with `{branch}-SNAPSHOT`
-e.g: `0.7.x-SNAPSHOT`
+e.g: `0.9.x-SNAPSHOT` for the branch `0.9.x` or `feature-mpp-SNAPSHOT` for the branch `feature/mpp`
[![Download](https://img.shields.io/maven-central/v/dev.kord/kord-core.svg?label=Maven%20Central&style=for-the-badge)](https://search.maven.org/search?q=g:%22dev.kord%22%20AND%20a:%22kord-core%22)
@@ -111,129 +125,22 @@ dependencies {
dev.kord
- kord-core
+ kord-core-jvm
{version}
```
-## Modules
-
-### Core
-
-A higher level API, combining `rest` and `gateway`, with additional (optional) caching. Unless you're writing your own
-abstractions, we'd recommend using this.
-
-```kotlin
-suspend fun main() {
- val kord = Kord("your bot token")
- val pingPong = ReactionEmoji.Unicode("\uD83C\uDFD3")
-
- kord.on {
- if (message.content != "!ping") return@on
-
- val response = message.channel.createMessage("Pong!")
- response.addReaction(pingPong)
-
- delay(5000)
- message.delete()
- response.delete()
- }
-
- kord.login {
- @OptIn(PrivilegedIntent::class)
- intents += Intent.MessageContent
- }
-}
-```
-
-### Rest
-
-A low level mapping of Discord's REST API. Requests follow
-Discord's [rate limits](https://discord.com/developers/docs/topics/rate-limits).
-
-```kotlin
-suspend fun main() {
- val rest = RestClient("your bot token")
- val channelId = Snowflake(605212557522763787)
-
- rest.channel.createMessage(channelId) {
- content = "Hello Kord!"
-
- embed {
- color = Color(red = 0, green = 0, blue = 255)
- description = "Hello embed!"
- }
- }
-}
-```
-
-### Gateway
-
-A low level mapping of [Discord's Gateway](https://discord.com/developers/docs/topics/gateway), which maintains the
-connection and rate limits commands.
-
-```kotlin
-suspend fun main() {
- val gateway = DefaultGateway()
-
- gateway.on {
- println("${message.author.username}: ${message.content}")
- val words = message.content.split(' ')
- when (words.firstOrNull()) {
- "!close" -> gateway.stop()
- "!detach" -> gateway.detach()
- }
- }
-
- gateway.start("your bot token") {
- @OptIn(PrivilegedIntent::class)
- intents += Intent.MessageContent
- }
-}
-```
-
-
-### Voice
-
-A mapping of [Discord's Voice Connection](https://discord.com/developers/docs/topics/voice-connections), which maintains the connection and handles audio transmission.
-
-If you want to use voice, you need to enable the voice capability,
-which is only available for Gradle
-
-```kotlin
-dependencies {
- implementation("dev.kord", "core", "") {
- capabilities {
- requireCapability("dev.kord:core-voice:")
- }
- }
-}
-```
-
-```kotlin
-suspend fun main() {
- val kord = Kord("your token")
- val voiceChannel = kord.getChannelOf(id = Snowflake(1))!!
-
- voiceChannel.connect {
- audioProvider { AudioFrame.fromData(/* your opus encoded audio */) }
- }
-
- kord.login()
-}
-```
-
## FAQ
## Will you support kotlin multi-platform
-We will, there's an [issue](https://github.com/kordlib/kord/issues/69) open to track the features we want/need to make a
-transition to MPP smooth.
+Currently we're supporting both Kotlin/JVM and Kotlin/JS for the majority of our API, for more information check
+[Modules](#modules) and #69
-## When will you document your code
+## When will you document your code?
Yes.
# This project is supported by JetBrains
-[![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://jb.gg/OpenSourceSupport)
\ No newline at end of file
+[![JetBrains Logo (Main) logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://jb.gg/OpenSourceSupport)
diff --git a/buildSrc/src/main/kotlin/BinaryCompatibility.kt b/buildSrc/src/main/kotlin/BinaryCompatibility.kt
new file mode 100644
index 00000000000..c457cea65e4
--- /dev/null
+++ b/buildSrc/src/main/kotlin/BinaryCompatibility.kt
@@ -0,0 +1,5 @@
+import kotlinx.validation.ApiValidationExtension
+
+fun ApiValidationExtension.applyKordBCVOptions() {
+ nonPublicMarkers += "dev.kord.common.annotation.KordInternal"
+}
diff --git a/buildSrc/src/main/kotlin/Compiler.kt b/buildSrc/src/main/kotlin/Compiler.kt
index 382763bca8c..3d4cc2614d1 100644
--- a/buildSrc/src/main/kotlin/Compiler.kt
+++ b/buildSrc/src/main/kotlin/Compiler.kt
@@ -1,21 +1,46 @@
-import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
+import kotlinx.atomicfu.plugin.gradle.AtomicFUPluginExtension
+import org.gradle.api.Project
+import org.gradle.api.artifacts.VersionCatalogsExtension
+import org.gradle.kotlin.dsl.configure
+import org.gradle.kotlin.dsl.getByType
+import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
+import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
-object CompilerArguments {
- const val time = "-opt-in=kotlin.time.ExperimentalTime"
- const val contracts = "-opt-in=kotlin.contracts.ExperimentalContracts"
+object OptIns {
+ const val coroutines = "kotlinx.coroutines.ExperimentalCoroutinesApi"
+}
- const val kordPreview = "-opt-in=dev.kord.common.annotation.KordPreview"
- const val kordExperimental = "-opt-in=dev.kord.common.annotation.KordExperimental"
- const val kordVoice = "-opt-in=dev.kord.common.annotation.KordVoice"
+val kordOptIns = listOf(
+ "kotlin.time.ExperimentalTime",
+ "kotlin.contracts.ExperimentalContracts",
- const val progressive = "-progressive"
-}
+ "dev.kord.common.annotation.KordInternal",
+ "dev.kord.common.annotation.KordPreview",
+ "dev.kord.common.annotation.KordExperimental",
+ "dev.kord.common.annotation.KordVoice",
+)
object Jvm {
const val target = 8
}
-fun KotlinJvmCompilerOptions.applyKordCompilerOptions() {
- allWarningsAsErrors.set(true)
- freeCompilerArgs.add(CompilerArguments.progressive)
+fun KotlinCommonCompilerOptions.applyKordCompilerOptions() {
+ // TODO: set to true again once https://github.com/Kotlin/kotlinx-atomicfu/issues/289 is fixed
+ allWarningsAsErrors.set(false)
+ freeCompilerArgs.add("-progressive")
+}
+
+fun KotlinSourceSet.applyKordOptIns() {
+ languageSettings {
+ if ("Test" in name) optIn(OptIns.coroutines)
+ kordOptIns.forEach(::optIn)
+ }
+}
+
+fun Project.configureAtomicFU() {
+ // https://github.com/Kotlin/kotlinx-atomicfu/issues/210
+ configure {
+ val libs = extensions.getByType().named("libs")
+ dependenciesVersion = libs.findVersion("kotlinx-atomicfu").get().requiredVersion
+ }
}
diff --git a/buildSrc/src/main/kotlin/Documentation.kt b/buildSrc/src/main/kotlin/Documentation.kt
new file mode 100644
index 00000000000..db5da77659e
--- /dev/null
+++ b/buildSrc/src/main/kotlin/Documentation.kt
@@ -0,0 +1,33 @@
+import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
+import java.net.URL
+
+fun AbstractDokkaLeafTask.applyKordDokkaOptions() {
+ failOnWarning.set(true)
+
+ dokkaSourceSets.configureEach {
+
+ jdkVersion.set(Jvm.target)
+
+ suppressGeneratedFiles.set(false)
+
+ sourceLink {
+ localDirectory.set(project.projectDir)
+ remoteUrl.set(URL("https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.9.x")}/${project.name}"))
+ remoteLineSuffix.set("#L")
+ }
+
+ externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
+ externalDocumentationLink("https://kotlinlang.org/api/kotlinx.serialization/")
+ externalDocumentationLink(
+ url = "https://kotlinlang.org/api/kotlinx-datetime/",
+ packageListUrl = "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list",
+ )
+ externalDocumentationLink("https://api.ktor.io/")
+
+ // don't list `TweetNaclFast` in docs
+ perPackageOption {
+ matchingRegex.set("""com\.iwebpp\.crypto""")
+ suppress.set(true)
+ }
+ }
+}
diff --git a/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts
new file mode 100644
index 00000000000..53be1985486
--- /dev/null
+++ b/buildSrc/src/main/kotlin/kord-internal-multiplatform-module.gradle.kts
@@ -0,0 +1,23 @@
+plugins {
+ org.jetbrains.kotlin.multiplatform
+}
+
+repositories {
+ mavenCentral()
+}
+
+kotlin {
+ jvm()
+ js(IR) {
+ nodejs()
+ }
+ jvmToolchain(Jvm.target)
+
+ targets {
+ all {
+ compilations.all {
+ compilerOptions.options.applyKordCompilerOptions()
+ }
+ }
+ }
+}
diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts
index 37b6d0dab5b..1c7608680a4 100644
--- a/buildSrc/src/main/kotlin/kord-module.gradle.kts
+++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts
@@ -1,7 +1,5 @@
-import com.google.devtools.ksp.gradle.KspTask
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-import java.net.URL
plugins {
org.jetbrains.kotlin.jvm
@@ -17,38 +15,32 @@ repositories {
mavenCentral()
}
+dependencies {
+ ksp(project(":ksp-processors"))
+}
+
+apiValidation {
+ applyKordBCVOptions()
+}
+
kotlin {
explicitApi()
jvmToolchain(Jvm.target)
sourceSets {
- // mark ksp src dir
- main { kotlin.srcDir("build/generated/ksp/main/kotlin") }
-
// allow `ExperimentalCoroutinesApi` for `runTest {}`
- test { languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") }
+ test { languageSettings.optIn(OptIns.coroutines) }
}
}
-// https://github.com/Kotlin/kotlinx-atomicfu/issues/210
-atomicfu {
- val libs = extensions.getByType().named("libs")
- dependenciesVersion = libs.findVersion("kotlinx-atomicfu").get().requiredVersion
-}
+configureAtomicFU()
tasks {
- withType {
+ withType().configureEach {
compilerOptions {
applyKordCompilerOptions()
- freeCompilerArgs.addAll(
- CompilerArguments.time,
- CompilerArguments.contracts,
-
- CompilerArguments.kordPreview,
- CompilerArguments.kordExperimental,
- CompilerArguments.kordVoice,
- )
+ freeCompilerArgs.addAll(kordOptIns.map { "-opt-in=$it" })
}
}
@@ -56,80 +48,18 @@ tasks {
useJUnitPlatform()
}
- fun Task.dependsOnKspKotlin() {
- val kspKotlin = findByName("kspKotlin")
- if (kspKotlin != null) dependsOn(kspKotlin)
- }
-
- // configure both dokkaHtml and dokkaHtmlPartial tasks
- // (dokkaHtmlMultiModule depends on dokkaHtmlPartial, dokkaJar depends on dokkaHtml)
withType().configureEach {
- // see https://kotlin.github.io/dokka//user_guide/gradle/usage/#configuration-options
-
- // include documentation generated by ksp
- dependsOnKspKotlin()
-
- failOnWarning.set(true)
-
- dokkaSourceSets.configureEach {
-
- jdkVersion.set(Jvm.target)
-
- val baseRemoteUrl =
- "https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.9.x")}/${project.name}"
-
- sourceLink {
- localDirectory.set(file("src/main/kotlin"))
- remoteUrl.set(URL("$baseRemoteUrl/src/main/kotlin"))
- remoteLineSuffix.set("#L")
- }
-
- // config for files generated by ksp
- suppressGeneratedFiles.set(false)
- sourceLink {
- // will fail if dir doesn't exist -> always create it, won't harm if not needed
- localDirectory.set(file("build/generated/ksp/main/kotlin").apply { mkdirs() })
- remoteUrl.set(URL("$baseRemoteUrl/build/generated/ksp/main/kotlin"))
- remoteLineSuffix.set("#L")
- }
-
- externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
- externalDocumentationLink("https://kotlinlang.org/api/kotlinx.serialization/")
- externalDocumentationLink(
- url = "https://kotlinlang.org/api/kotlinx-datetime/",
- packageListUrl = "https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/package-list",
- )
- externalDocumentationLink("https://api.ktor.io/")
-
- // don't list `TweetNaclFast` in docs
- perPackageOption {
- matchingRegex.set("""com\.iwebpp\.crypto""")
- suppress.set(true)
- }
- }
+ applyKordDokkaOptions()
}
withType().configureEach {
doFirst { require(!Library.isUndefined) { "No release/snapshot version found." } }
}
-
- kotlinSourcesJar {
- // include sources generated by ksp
- dependsOnKspKotlin()
- }
-}
-
-val dokkaJar by tasks.registering(Jar::class) {
- group = JavaBasePlugin.DOCUMENTATION_GROUP
- description = "Assembles Kotlin docs with Dokka"
- archiveClassifier.set("javadoc")
- from(tasks.dokkaHtml)
}
publishing {
- publications.withType().configureEach {
+ publications.register(Library.name) {
from(components["java"])
artifact(tasks.kotlinSourcesJar)
- artifact(dokkaJar)
}
}
diff --git a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
new file mode 100644
index 00000000000..b33a4e65cfc
--- /dev/null
+++ b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
@@ -0,0 +1,88 @@
+import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
+import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
+
+plugins {
+ org.jetbrains.kotlin.multiplatform
+ org.jetbrains.kotlin.plugin.serialization
+ org.jetbrains.dokka
+ `kotlinx-atomicfu`
+ org.jetbrains.kotlinx.`binary-compatibility-validator`
+ com.google.devtools.ksp
+}
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ kspCommonMainMetadata(project(":ksp-processors"))
+}
+
+apiValidation {
+ applyKordBCVOptions()
+}
+
+kotlin {
+ explicitApi()
+
+ jvm()
+ js(IR) {
+ nodejs()
+ }
+ jvmToolchain(Jvm.target)
+
+ targets.all {
+ compilations.all {
+ compilerOptions.options.applyKordCompilerOptions()
+ }
+ }
+
+ sourceSets {
+ all {
+ applyKordOptIns()
+ }
+ commonMain {
+ // mark ksp src dir
+ kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
+ }
+ commonTest {
+ dependencies {
+ implementation(project(":test-kit"))
+ }
+ }
+ val nonJvmMain by creating {
+ dependsOn(commonMain.get())
+ }
+ targets
+ .map { it.name }
+ .filter { it != "jvm" && it != "metadata" }
+ .forEach { target ->
+ sourceSets.getByName("${target}Main") {
+ dependsOn(nonJvmMain)
+ }
+ }
+ }
+}
+
+configureAtomicFU()
+
+tasks {
+ withType().configureEach {
+ useJUnitPlatform()
+ }
+
+ withType().configureEach {
+ environment("PROJECT_ROOT", rootProject.projectDir.absolutePath)
+ }
+
+ for (task in listOf("compileKotlinJvm", "compileKotlinJs", "jvmSourcesJar", "jsSourcesJar")) {
+ named(task) {
+ dependsOn("kspCommonMainKotlinMetadata")
+ }
+ }
+
+ withType().configureEach {
+ applyKordDokkaOptions()
+ dependsOn("kspCommonMainKotlinMetadata")
+ }
+}
diff --git a/buildSrc/src/main/kotlin/kord-publishing.gradle.kts b/buildSrc/src/main/kotlin/kord-publishing.gradle.kts
index f080e6714f1..593dd1348b8 100644
--- a/buildSrc/src/main/kotlin/kord-publishing.gradle.kts
+++ b/buildSrc/src/main/kotlin/kord-publishing.gradle.kts
@@ -5,11 +5,17 @@ plugins {
signing
}
+val dokkaJar by tasks.registering(Jar::class) {
+ archiveClassifier.set("javadoc")
+ from(tasks.named("dokkaHtml"))
+}
+
publishing {
publications {
- create(Library.name) {
+ withType().configureEach {
+ artifact(dokkaJar)
groupId = Library.group
- artifactId = "kord-${project.name}"
+ artifactId = "kord-$artifactId"
version = Library.version
pom {
@@ -46,17 +52,17 @@ publishing {
url.set(Library.projectUrl)
}
}
+ }
+ }
- if (!isJitPack) {
- repositories {
- maven {
- url = uri(if (Library.isSnapshot) Repo.snapshotsUrl else Repo.releasesUrl)
+ if (!isJitPack) {
+ repositories {
+ maven {
+ url = uri(if (Library.isSnapshot) Repo.snapshotsUrl else Repo.releasesUrl)
- credentials {
- username = System.getenv("NEXUS_USER")
- password = System.getenv("NEXUS_PASSWORD")
- }
- }
+ credentials {
+ username = System.getenv("NEXUS_USER")
+ password = System.getenv("NEXUS_PASSWORD")
}
}
}
diff --git a/common/api/common.api b/common/api/common.api
index 81a0b0d6a68..42028ff4097 100644
--- a/common/api/common.api
+++ b/common/api/common.api
@@ -102,7 +102,6 @@ public final class dev/kord/common/Locale {
public static final field Companion Ldev/kord/common/Locale$Companion;
public fun (Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
- public final fun asJavaLocale ()Ljava/util/Locale;
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/String;)Ldev/kord/common/Locale;
@@ -161,6 +160,7 @@ public final class dev/kord/common/Locale$Serializer : kotlinx/serialization/KSe
}
public final class dev/kord/common/LocaleKt {
+ public static final fun asJavaLocale (Ldev/kord/common/Locale;)Ljava/util/Locale;
public static final fun getKLocale (Ljava/util/Locale;)Ldev/kord/common/Locale;
}
@@ -174,6 +174,9 @@ public abstract interface annotation class dev/kord/common/annotation/KordDsl :
public abstract interface annotation class dev/kord/common/annotation/KordExperimental : java/lang/annotation/Annotation {
}
+public abstract interface annotation class dev/kord/common/annotation/KordInternal : java/lang/annotation/Annotation {
+}
+
public abstract interface annotation class dev/kord/common/annotation/KordPreview : java/lang/annotation/Annotation {
}
diff --git a/common/build.gradle.kts b/common/build.gradle.kts
index 270b4b897d9..3975a46823f 100644
--- a/common/build.gradle.kts
+++ b/common/build.gradle.kts
@@ -1,22 +1,46 @@
@Suppress("DSL_SCOPE_VIOLATION") // false positive for `libs` in IntelliJ
plugins {
- `kord-module`
- `kord-sampled-module`
+ `kord-multiplatform-module`
`kord-publishing`
alias(libs.plugins.buildconfig)
}
-dependencies {
- api(libs.kotlinx.coroutines.core)
- api(libs.kotlinx.serialization.json)
- api(libs.kotlinx.datetime)
- api(libs.kotlin.logging)
+kotlin {
+ sourceSets {
+ commonMain {
+ dependencies {
+ api(libs.kotlinx.coroutines.core)
+ api(libs.kotlinx.serialization.json)
+ api(libs.kotlinx.datetime)
+ api(libs.kotlin.logging)
- compileOnly(projects.kspAnnotations)
- ksp(projects.kspProcessors)
+ api(libs.ktor.client.core)
- testImplementation(libs.bundles.test.implementation)
- testRuntimeOnly(libs.bundles.test.runtime)
+ compileOnly(projects.kspAnnotations)
+ }
+ }
+ jvmMain {
+ dependencies {
+ api(libs.ktor.client.cio)
+ }
+ }
+ nonJvmMain {
+ dependencies {
+ implementation(libs.ktor.utils)
+ implementation(libs.bignum)
+ implementation(libs.stately.collections)
+ }
+ }
+ jsMain {
+ dependencies {
+ api(libs.ktor.client.js)
+
+ // workaround for https://youtrack.jetbrains.com/issue/KT-43500
+ // (intended to be compileOnly in commonMain only)
+ implementation(projects.kspAnnotations)
+ }
+ }
+ }
}
/*
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AllowedMentionType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AllowedMentionType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ApplicationCommandType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AuditLogEvent.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AuditLogEvent.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationActionType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationActionType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ButtonStyle.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ButtonStyle.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ChannelType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ChannelType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ComponentType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ComponentType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/EmbedType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/EmbedType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/EmbedType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/EmbedType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ForumLayoutType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ForumLayoutType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ForumLayoutType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ForumLayoutType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/GuildFeature.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/GuildFeature.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionResponseType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionResponseType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InteractionType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InviteTargetType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/InviteTargetType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MFALevel.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MFALevel.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MessageActivityType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MessageActivityType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MessageStickerType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MessageStickerType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MessageType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/MessageType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/NsfwLevel.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/NsfwLevel.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OnboardingPromptType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/OnboardingPromptType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OnboardingPromptType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/OnboardingPromptType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/OverwriteType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/OverwriteType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/PremiumTier.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/PremiumTier.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/PresenceStatus.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/PresenceStatus.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ScheduledEntityType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/ScheduledEntityType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/SortOrderType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/SortOrderType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/SortOrderType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/SortOrderType.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/TeamMembershipState.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/TeamMembershipState.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/TextInputStyle.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/TextInputStyle.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/UserPremium.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/UserPremium.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/VerificationLevel.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/VerificationLevel.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/VideoQualityMode.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/VideoQualityMode.kt
diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt b/common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/WebhookType.kt
similarity index 100%
rename from common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt
rename to common/build/generated/ksp/metadata/commonMain/kotlin/dev/kord/common/entity/WebhookType.kt
diff --git a/common/src/main/kotlin/Color.kt b/common/src/commonMain/kotlin/Color.kt
similarity index 78%
rename from common/src/main/kotlin/Color.kt
rename to common/src/commonMain/kotlin/Color.kt
index c45381954b2..b7fed9e7485 100644
--- a/common/src/main/kotlin/Color.kt
+++ b/common/src/commonMain/kotlin/Color.kt
@@ -36,6 +36,17 @@ public class Color(rgb: Int) {
public companion object {
private const val MIN_COLOR = 0
private const val MAX_COLOR = 0xFFFFFF
+
+ private fun rgb(red: Int, green: Int, blue: Int): Int {
+ require(red in 0..255) { "Red should be in range of 0..255 but was $red" }
+ require(green in 0..255) { "Green should be in range of 0..255 but was $green" }
+ require(blue in 0..255) { "Blue should be in range of 0..255 but was $blue" }
+
+
+ return red and 0xFF shl 16 or
+ (green and 0xFF shl 8) or
+ (blue and 0xFF) shl 0
+ }
}
internal object Serializer : KSerializer {
@@ -49,16 +60,3 @@ public class Color(rgb: Int) {
}
}
}
-
-private fun rgb(red: Int, green: Int, blue: Int): Int {
- require(red in 0..255) { "Red should be in range of 0..255 but was $red" }
- require(green in 0..255) { "Green should be in range of 0..255 but was $green" }
- require(blue in 0..255) { "Blue should be in range of 0..255 but was $blue" }
-
-
- return red and 0xFF shl 16 or
- (green and 0xFF shl 8) or
- (blue and 0xFF) shl 0
-}
-
-public val java.awt.Color.kColor: Color get() = Color(rgb)
diff --git a/common/src/commonMain/kotlin/ConcurrentHashMap.kt b/common/src/commonMain/kotlin/ConcurrentHashMap.kt
new file mode 100644
index 00000000000..6e0ea0791fb
--- /dev/null
+++ b/common/src/commonMain/kotlin/ConcurrentHashMap.kt
@@ -0,0 +1,11 @@
+package dev.kord.common
+
+import dev.kord.common.annotation.KordInternal
+
+/**
+ * Platform-agnostic implementation of ConcurrentHashMap.
+ *
+ * @suppress
+ */
+@KordInternal
+public expect class ConcurrentHashMap() : MutableMap
diff --git a/common/src/main/kotlin/DiscordBitSet.kt b/common/src/commonMain/kotlin/DiscordBitSet.kt
similarity index 91%
rename from common/src/main/kotlin/DiscordBitSet.kt
rename to common/src/commonMain/kotlin/DiscordBitSet.kt
index 17ebcffb2c4..8098026c470 100644
--- a/common/src/main/kotlin/DiscordBitSet.kt
+++ b/common/src/commonMain/kotlin/DiscordBitSet.kt
@@ -7,8 +7,6 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
-import java.math.BigInteger
-import java.nio.ByteBuffer
import kotlin.math.max
import kotlin.math.min
@@ -18,19 +16,16 @@ private const val WIDTH = Long.SIZE_BITS
@Suppress("FunctionName")
public fun EmptyBitSet(): DiscordBitSet = DiscordBitSet()
+internal expect fun formatIntegerFromLittleEndianLongArray(data: LongArray): String
+internal expect fun parseIntegerToBigEndianByteArray(value: String): ByteArray
+
@Serializable(with = DiscordBitSetSerializer::class)
public class DiscordBitSet(internal var data: LongArray) { // data is in little-endian order
public val isEmpty: Boolean
get() = data.all { it == 0L }
- public val value: String
- get() {
- // need to convert from little-endian data to big-endian expected by BigInteger
- val buffer = ByteBuffer.allocate(data.size * Long.SIZE_BYTES)
- buffer.asLongBuffer().put(data.reversedArray())
- return BigInteger(buffer.array()).toString()
- }
+ public val value: String get() = formatIntegerFromLittleEndianLongArray(data)
public val size: Int
get() = data.size * WIDTH
@@ -128,7 +123,7 @@ public fun DiscordBitSet(value: String): DiscordBitSet {
return DiscordBitSet(longArrayOf(value.toULong().toLong()))
}
- val bytes = BigInteger(value).toByteArray()
+ val bytes = parseIntegerToBigEndianByteArray(value)
val longSize = (bytes.size / Long.SIZE_BYTES) + 1
val destination = LongArray(longSize)
diff --git a/common/src/main/kotlin/DiscordTimestamp.kt b/common/src/commonMain/kotlin/DiscordTimestamp.kt
similarity index 100%
rename from common/src/main/kotlin/DiscordTimestamp.kt
rename to common/src/commonMain/kotlin/DiscordTimestamp.kt
diff --git a/common/src/main/kotlin/KordConfiguration.kt b/common/src/commonMain/kotlin/KordConfiguration.kt
similarity index 100%
rename from common/src/main/kotlin/KordConfiguration.kt
rename to common/src/commonMain/kotlin/KordConfiguration.kt
diff --git a/common/src/main/kotlin/KordConstants.kt b/common/src/commonMain/kotlin/KordConstants.kt
similarity index 100%
rename from common/src/main/kotlin/KordConstants.kt
rename to common/src/commonMain/kotlin/KordConstants.kt
diff --git a/common/src/main/kotlin/Locale.kt b/common/src/commonMain/kotlin/Locale.kt
similarity index 95%
rename from common/src/main/kotlin/Locale.kt
rename to common/src/commonMain/kotlin/Locale.kt
index 63e922ddb2e..9b45e530cdd 100644
--- a/common/src/main/kotlin/Locale.kt
+++ b/common/src/commonMain/kotlin/Locale.kt
@@ -7,7 +7,6 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
-import java.util.Locale as JLocale
/**
* Representation of a locale [supported by Discord](https://discord.com/developers/docs/reference#locales).
@@ -17,11 +16,6 @@ import java.util.Locale as JLocale
*/
@Serializable(with = Locale.Serializer::class)
public data class Locale(val language: String, val country: String? = null) {
- /**
- * Converts this into a [JLocale].
- */
- public fun asJavaLocale(): JLocale = JLocale(language, country ?: "")
-
public companion object {
/**
@@ -247,9 +241,3 @@ public data class Locale(val language: String, val country: String? = null) {
override fun deserialize(decoder: Decoder): Locale = fromString(decoder.decodeString())
}
}
-
-/**
- * Converts this into a [Locale].
- */
-public val JLocale.kLocale: Locale
- get() = Locale(language, country.ifBlank { null })
diff --git a/common/src/main/kotlin/annotation/Annotations.kt b/common/src/commonMain/kotlin/annotation/Annotations.kt
similarity index 85%
rename from common/src/main/kotlin/annotation/Annotations.kt
rename to common/src/commonMain/kotlin/annotation/Annotations.kt
index ee5107389a4..c3355c01d84 100644
--- a/common/src/main/kotlin/annotation/Annotations.kt
+++ b/common/src/commonMain/kotlin/annotation/Annotations.kt
@@ -1,12 +1,13 @@
package dev.kord.common.annotation
+import kotlin.RequiresOptIn.Level.ERROR
import kotlin.RequiresOptIn.Level.WARNING
-import kotlin.annotation.AnnotationRetention.RUNTIME
+import kotlin.annotation.AnnotationRetention.BINARY
import kotlin.annotation.AnnotationTarget.*
/** [DslMarker] for Kord DSLs. */
@DslMarker
-@Retention(RUNTIME)
+@Retention(BINARY)
@Target(CLASS)
public annotation class KordDsl
@@ -20,7 +21,7 @@ public annotation class KordDsl
*/
@MustBeDocumented
@RequiresOptIn(level = WARNING)
-@Retention(RUNTIME)
+@Retention(BINARY)
@Target(CLASS, PROPERTY, CONSTRUCTOR, FUNCTION, TYPEALIAS)
public annotation class KordPreview
@@ -35,7 +36,7 @@ public annotation class KordPreview
*/
@MustBeDocumented
@RequiresOptIn(level = WARNING)
-@Retention(RUNTIME)
+@Retention(BINARY)
@Target(CLASS, PROPERTY, FUNCTION, TYPEALIAS)
public annotation class KordExperimental
@@ -50,7 +51,7 @@ public annotation class KordExperimental
*/
@MustBeDocumented
@RequiresOptIn(level = WARNING)
-@Retention(RUNTIME)
+@Retention(BINARY)
@Target(CLASS, PROPERTY, FUNCTION, TYPEALIAS)
public annotation class KordVoice
@@ -66,7 +67,7 @@ public annotation class KordVoice
*/
@MustBeDocumented
@RequiresOptIn("This API is potentially unsafe.", level = WARNING)
-@Retention(RUNTIME)
+@Retention(BINARY)
@Target(CLASS, PROPERTY, FUNCTION, PROPERTY_SETTER, TYPEALIAS)
public annotation class KordUnsafe
@@ -76,6 +77,15 @@ public annotation class KordUnsafe
* These declarations must also be annotated with [Deprecated].
*/
@MustBeDocumented
-@Retention(RUNTIME)
+@Retention(BINARY)
@Target(CLASS, ANNOTATION_CLASS, PROPERTY, CONSTRUCTOR, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, TYPEALIAS)
public annotation class DeprecatedSinceKord(val version: String)
+
+/**
+ * Marks an API for internal use only.
+ */
+@MustBeDocumented
+@RequiresOptIn("This API is intended for internal use only.", level = ERROR)
+@Retention(BINARY)
+@Target(CLASS, PROPERTY, FUNCTION, TYPEALIAS)
+public annotation class KordInternal
diff --git a/common/src/main/kotlin/entity/AuditLog.kt b/common/src/commonMain/kotlin/entity/AuditLog.kt
similarity index 84%
rename from common/src/main/kotlin/entity/AuditLog.kt
rename to common/src/commonMain/kotlin/entity/AuditLog.kt
index 5dc4b436516..dce82c8c975 100644
--- a/common/src/main/kotlin/entity/AuditLog.kt
+++ b/common/src/commonMain/kotlin/entity/AuditLog.kt
@@ -72,6 +72,7 @@ import dev.kord.ksp.GenerateKordEnum.Entry
import dev.kord.ksp.GenerateKordEnum.ValueType.INT
import kotlinx.datetime.Instant
import kotlinx.serialization.*
+import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@@ -237,147 +238,156 @@ public sealed class AuditLogChangeKey(public val name: String, public val ser
public class Unknown(name: String) : AuditLogChangeKey(name, JsonElement.serializer())
@SerialName("name")
- public object Name : AuditLogChangeKey("name", serializer())
+ public object Name : AuditLogChangeKey("name", String.serializer())
@SerialName("icon_hash")
- public object IconHash : AuditLogChangeKey("icon_hash", serializer())
+ public object IconHash : AuditLogChangeKey("icon_hash", String.serializer())
@SerialName("image_hash")
- public object ImageHash : AuditLogChangeKey("image_hash", serializer())
+ public object ImageHash : AuditLogChangeKey("image_hash", String.serializer())
@SerialName("splash_hash")
- public object SplashHash : AuditLogChangeKey("splash_hash", serializer())
+ public object SplashHash : AuditLogChangeKey("splash_hash", String.serializer())
@SerialName("owner_id")
- public object OwnerId : AuditLogChangeKey("owner_id", serializer())
+ public object OwnerId : AuditLogChangeKey("owner_id", Snowflake.serializer())
@SerialName("region")
- public object Region : AuditLogChangeKey("region", serializer())
+ public object Region : AuditLogChangeKey("region", String.serializer())
@SerialName("afk_channel_id")
- public object AfkChannelId : AuditLogChangeKey("afk_channel_id", serializer())
+ public object AfkChannelId : AuditLogChangeKey("afk_channel_id", Snowflake.serializer())
@SerialName("afk_timeout")
public object AfkTimeout : AuditLogChangeKey("afk_timeout", DurationInSecondsSerializer)
@SerialName("mfa_level")
- public object MFALevel : AuditLogChangeKey("mfa_level", serializer())
+ public object MFALevel : AuditLogChangeKey("mfa_level", CommonMFALevel.serializer())
@SerialName("verification_level")
- public object VerificationLevel : AuditLogChangeKey("verification_level", serializer())
+ public object VerificationLevel :
+ AuditLogChangeKey("verification_level", CommonVerificationLevel.serializer())
@SerialName("explicit_content_filter")
- public object ExplicitContentFilter :
- AuditLogChangeKey("explicit_content_filter", serializer())
+ public object ExplicitContentFilter : AuditLogChangeKey(
+ "explicit_content_filter",
+ CommonExplicitContentFilter.serializer()
+ )
@SerialName("default_message_notifications")
- public object DefaultMessageNotificationLevel :
- AuditLogChangeKey("default_message_notifications", serializer())
+ public object DefaultMessageNotificationLevel : AuditLogChangeKey(
+ "default_message_notifications",
+ CommonDefaultMessageNotificationLevel.serializer()
+ )
@SerialName("vanity_url_code")
- public object VanityUrlCode : AuditLogChangeKey("vanity_url_code", serializer())
+ public object VanityUrlCode : AuditLogChangeKey("vanity_url_code", String.serializer())
@SerialName("\$add")
- public object Add : AuditLogChangeKey>("\$add", serializer())
+ public object Add :
+ AuditLogChangeKey>("\$add", ListSerializer(DiscordPartialRole.serializer()))
@SerialName("\$remove")
- public object Remove : AuditLogChangeKey>("\$remove", serializer())
+ public object Remove :
+ AuditLogChangeKey>("\$remove", ListSerializer(DiscordPartialRole.serializer()))
@SerialName("prune_delete_days")
- public object PruneDeleteDays : AuditLogChangeKey("prune_delete_days", serializer())
+ public object PruneDeleteDays : AuditLogChangeKey("prune_delete_days", Int.serializer())
@SerialName("widget_enabled")
- public object WidgetEnabled : AuditLogChangeKey("widget_enabled", serializer())
+ public object WidgetEnabled : AuditLogChangeKey("widget_enabled", Boolean.serializer())
@SerialName("widget_channel_id")
- public object WidgetChannelId : AuditLogChangeKey("widget_channel_id", serializer())
+ public object WidgetChannelId : AuditLogChangeKey("widget_channel_id", Snowflake.serializer())
@SerialName("system_channel_id")
- public object SystemChannelId : AuditLogChangeKey("system_channel_id", serializer())
+ public object SystemChannelId : AuditLogChangeKey("system_channel_id", Snowflake.serializer())
@SerialName("position")
- public object Position : AuditLogChangeKey("position", serializer())
+ public object Position : AuditLogChangeKey("position", Int.serializer())
@SerialName("topic")
- public object Topic : AuditLogChangeKey("topic", serializer())
+ public object Topic : AuditLogChangeKey("topic", String.serializer())
@SerialName("bitrate")
- public object Bitrate : AuditLogChangeKey("bitrate", serializer())
+ public object Bitrate : AuditLogChangeKey("bitrate", Int.serializer())
@SerialName("permission_overwrites")
- public object PermissionOverwrites : AuditLogChangeKey>("permission_overwrites", serializer())
+ public object PermissionOverwrites :
+ AuditLogChangeKey>("permission_overwrites", ListSerializer(Overwrite.serializer()))
@SerialName("nsfw")
- public object Nsfw : AuditLogChangeKey("nsfw", serializer())
+ public object Nsfw : AuditLogChangeKey("nsfw", Boolean.serializer())
@SerialName("application_id")
- public object ApplicationId : AuditLogChangeKey("application_id", serializer())
+ public object ApplicationId : AuditLogChangeKey("application_id", Snowflake.serializer())
@SerialName("rate_limit_per_user")
public object RateLimitPerUser : AuditLogChangeKey("rate_limit_per_user", DurationInSecondsSerializer)
@SerialName("permissions")
- public object Permissions : AuditLogChangeKey("permissions", serializer())
+ public object Permissions : AuditLogChangeKey("permissions", CommonPermissions.serializer())
@SerialName("color")
- public object Color : AuditLogChangeKey("color", serializer())
+ public object Color : AuditLogChangeKey("color", CommonColor.serializer())
@SerialName("command_id")
- public object CommandId : AuditLogChangeKey("command_id", serializer())
+ public object CommandId : AuditLogChangeKey("command_id", Snowflake.serializer())
@SerialName("communication_disabled_until")
- public object CommunicationDisabledUntil : AuditLogChangeKey("communication_disabled_until", serializer())
+ public object CommunicationDisabledUntil :
+ AuditLogChangeKey("communication_disabled_until", Instant.serializer())
@SerialName("hoist")
- public object Hoist : AuditLogChangeKey("hoist", serializer())
+ public object Hoist : AuditLogChangeKey("hoist", Boolean.serializer())
@SerialName("mentionable")
- public object Mentionable : AuditLogChangeKey("mentionable", serializer())
+ public object Mentionable : AuditLogChangeKey("mentionable", Boolean.serializer())
@SerialName("allow")
- public object Allow : AuditLogChangeKey("allow", serializer())
+ public object Allow : AuditLogChangeKey("allow", CommonPermissions.serializer())
@SerialName("deny")
- public object Deny : AuditLogChangeKey("deny", serializer())
+ public object Deny : AuditLogChangeKey("deny", CommonPermissions.serializer())
@SerialName("code")
- public object Code : AuditLogChangeKey("code", serializer())
+ public object Code : AuditLogChangeKey("code", String.serializer())
@SerialName("channel_id")
- public object ChannelId : AuditLogChangeKey("channel_id", serializer())
+ public object ChannelId : AuditLogChangeKey("channel_id", Snowflake.serializer())
@SerialName("inviter_id")
- public object InviterId : AuditLogChangeKey("inviter_id", serializer())
+ public object InviterId : AuditLogChangeKey("inviter_id", Snowflake.serializer())
@SerialName("location")
- public object Location : AuditLogChangeKey("location", serializer())
+ public object Location : AuditLogChangeKey("location", String.serializer())
@SerialName("max_uses")
- public object MaxUses : AuditLogChangeKey("max_uses", serializer())
+ public object MaxUses : AuditLogChangeKey("max_uses", Int.serializer())
@SerialName("uses")
- public object Uses : AuditLogChangeKey("uses", serializer())
+ public object Uses : AuditLogChangeKey("uses", Int.serializer())
@SerialName("max_age")
public object MaxAges : AuditLogChangeKey("max_age", DurationInSecondsSerializer)
@SerialName("temporary")
- public object Temporary : AuditLogChangeKey("temporary", serializer())
+ public object Temporary : AuditLogChangeKey("temporary", Boolean.serializer())
@SerialName("deaf")
- public object Deaf : AuditLogChangeKey("deaf", serializer())
+ public object Deaf : AuditLogChangeKey("deaf", Boolean.serializer())
@SerialName("mute")
- public object Mute : AuditLogChangeKey("mute", serializer())
+ public object Mute : AuditLogChangeKey("mute", Boolean.serializer())
@SerialName("nick")
- public object Nick : AuditLogChangeKey("nick", serializer())
+ public object Nick : AuditLogChangeKey("nick", String.serializer())
@SerialName("avatar_hash")
- public object AvatarHash : AuditLogChangeKey("avatar_hash", serializer())
+ public object AvatarHash : AuditLogChangeKey("avatar_hash", String.serializer())
@SerialName("id")
- public object Id : AuditLogChangeKey("id", serializer())
+ public object Id : AuditLogChangeKey("id", Snowflake.serializer())
/**
* The actual supertype is [AuditLogChangeKey][AuditLogChangeKey] but Kotlin does not support union
@@ -390,47 +400,41 @@ public sealed class AuditLogChangeKey(public val name: String, public val ser
public object Type : AuditLogChangeKey("type", LongOrStringSerializer)
@SerialName("enable_emoticons")
- public object EnableEmoticons : AuditLogChangeKey("enable_emoticons", serializer())
+ public object EnableEmoticons : AuditLogChangeKey("enable_emoticons", Boolean.serializer())
@SerialName("expire_behavior")
- public object ExpireBehavior : AuditLogChangeKey("expire_behavior", serializer())
+ public object ExpireBehavior :
+ AuditLogChangeKey("expire_behavior", IntegrationExpireBehavior.serializer())
@SerialName("expire_grace_period")
public object ExpireGracePeriod : AuditLogChangeKey("expire_grace_period", DurationInDaysSerializer)
@SerialName("user_limit")
- public object UserLimit : AuditLogChangeKey("user_limit", serializer())
+ public object UserLimit : AuditLogChangeKey("user_limit", Int.serializer())
@SerialName("archived")
- public object Archived : AuditLogChangeKey("archived", serializer())
+ public object Archived : AuditLogChangeKey("archived", Boolean.serializer())
@SerialName("locked")
- public object Locked : AuditLogChangeKey("locked", serializer())
+ public object Locked : AuditLogChangeKey("locked", Boolean.serializer())
@SerialName("auto_archive_duration")
- public object AutoArchiveDuration : AuditLogChangeKey("auto_archive_duration", serializer())
+ public object AutoArchiveDuration :
+ AuditLogChangeKey("auto_archive_duration", ArchiveDuration.serializer())
@SerialName("default_auto_archive_duration")
public object DefaultAutoArchiveDuration :
- AuditLogChangeKey("default_auto_archive_duration", serializer())
+ AuditLogChangeKey("default_auto_archive_duration", ArchiveDuration.serializer())
@SerialName("entity_type")
- public object EntityType : AuditLogChangeKey(
- "entity_type",
- serializer()
- )
+ public object EntityType : AuditLogChangeKey("entity_type", ScheduledEntityType.serializer())
@SerialName("status")
- public object Status : AuditLogChangeKey(
- "status",
- serializer()
- )
+ public object Status :
+ AuditLogChangeKey("status", GuildScheduledEventStatus.serializer())
@SerialName("sku_ids")
- public object SkuIds : AuditLogChangeKey>(
- "sku_ids",
- serializer()
- )
+ public object SkuIds : AuditLogChangeKey>("sku_ids", ListSerializer(Snowflake.serializer()))
internal class Serializer(val type: KSerializer) : KSerializer> {
override val descriptor: SerialDescriptor
diff --git a/common/src/main/kotlin/entity/AutoModeration.kt b/common/src/commonMain/kotlin/entity/AutoModeration.kt
similarity index 100%
rename from common/src/main/kotlin/entity/AutoModeration.kt
rename to common/src/commonMain/kotlin/entity/AutoModeration.kt
diff --git a/common/src/main/kotlin/entity/Data.kt b/common/src/commonMain/kotlin/entity/Data.kt
similarity index 100%
rename from common/src/main/kotlin/entity/Data.kt
rename to common/src/commonMain/kotlin/entity/Data.kt
diff --git a/common/src/main/kotlin/entity/DiscordActivity.kt b/common/src/commonMain/kotlin/entity/DiscordActivity.kt
similarity index 99%
rename from common/src/main/kotlin/entity/DiscordActivity.kt
rename to common/src/commonMain/kotlin/entity/DiscordActivity.kt
index 9b1fd74dcd4..dd1dd521d96 100644
--- a/common/src/main/kotlin/entity/DiscordActivity.kt
+++ b/common/src/commonMain/kotlin/entity/DiscordActivity.kt
@@ -13,6 +13,8 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.DeprecationLevel.HIDDEN
import kotlin.LazyThreadSafetyMode.PUBLICATION
+import kotlin.jvm.JvmField
+import kotlin.jvm.JvmStatic
@Serializable
public data class DiscordBotActivity(
diff --git a/common/src/main/kotlin/entity/DiscordApplication.kt b/common/src/commonMain/kotlin/entity/DiscordApplication.kt
similarity index 99%
rename from common/src/main/kotlin/entity/DiscordApplication.kt
rename to common/src/commonMain/kotlin/entity/DiscordApplication.kt
index 59d8076599e..64bb6115213 100644
--- a/common/src/main/kotlin/entity/DiscordApplication.kt
+++ b/common/src/commonMain/kotlin/entity/DiscordApplication.kt
@@ -12,6 +12,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
+import kotlin.jvm.JvmName
public sealed interface BaseDiscordApplication {
public val id: Snowflake
diff --git a/common/src/main/kotlin/entity/DiscordChannel.kt b/common/src/commonMain/kotlin/entity/DiscordChannel.kt
similarity index 99%
rename from common/src/main/kotlin/entity/DiscordChannel.kt
rename to common/src/commonMain/kotlin/entity/DiscordChannel.kt
index 8315021d321..cebfee56211 100644
--- a/common/src/main/kotlin/entity/DiscordChannel.kt
+++ b/common/src/commonMain/kotlin/entity/DiscordChannel.kt
@@ -99,6 +99,7 @@ import kotlin.DeprecationLevel.HIDDEN
import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
+import kotlin.jvm.JvmName
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes
diff --git a/common/src/main/kotlin/entity/DiscordComponent.kt b/common/src/commonMain/kotlin/entity/DiscordComponent.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordComponent.kt
rename to common/src/commonMain/kotlin/entity/DiscordComponent.kt
diff --git a/common/src/main/kotlin/entity/DiscordConnection.kt b/common/src/commonMain/kotlin/entity/DiscordConnection.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordConnection.kt
rename to common/src/commonMain/kotlin/entity/DiscordConnection.kt
diff --git a/common/src/main/kotlin/entity/DiscordEmoji.kt b/common/src/commonMain/kotlin/entity/DiscordEmoji.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordEmoji.kt
rename to common/src/commonMain/kotlin/entity/DiscordEmoji.kt
diff --git a/common/src/main/kotlin/entity/DiscordGuild.kt b/common/src/commonMain/kotlin/entity/DiscordGuild.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordGuild.kt
rename to common/src/commonMain/kotlin/entity/DiscordGuild.kt
diff --git a/common/src/main/kotlin/entity/DiscordGuildOnboarding.kt b/common/src/commonMain/kotlin/entity/DiscordGuildOnboarding.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordGuildOnboarding.kt
rename to common/src/commonMain/kotlin/entity/DiscordGuildOnboarding.kt
diff --git a/common/src/main/kotlin/entity/DiscordGuildPreview.kt b/common/src/commonMain/kotlin/entity/DiscordGuildPreview.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordGuildPreview.kt
rename to common/src/commonMain/kotlin/entity/DiscordGuildPreview.kt
diff --git a/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt b/common/src/commonMain/kotlin/entity/DiscordGuildScheduledEvent.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt
rename to common/src/commonMain/kotlin/entity/DiscordGuildScheduledEvent.kt
diff --git a/common/src/main/kotlin/entity/DiscordGuildWidget.kt b/common/src/commonMain/kotlin/entity/DiscordGuildWidget.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordGuildWidget.kt
rename to common/src/commonMain/kotlin/entity/DiscordGuildWidget.kt
diff --git a/common/src/main/kotlin/entity/DiscordIntegration.kt b/common/src/commonMain/kotlin/entity/DiscordIntegration.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordIntegration.kt
rename to common/src/commonMain/kotlin/entity/DiscordIntegration.kt
diff --git a/common/src/main/kotlin/entity/DiscordInvite.kt b/common/src/commonMain/kotlin/entity/DiscordInvite.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordInvite.kt
rename to common/src/commonMain/kotlin/entity/DiscordInvite.kt
diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/commonMain/kotlin/entity/DiscordMessage.kt
similarity index 99%
rename from common/src/main/kotlin/entity/DiscordMessage.kt
rename to common/src/commonMain/kotlin/entity/DiscordMessage.kt
index 37b4904e030..263a79c080a 100644
--- a/common/src/main/kotlin/entity/DiscordMessage.kt
+++ b/common/src/commonMain/kotlin/entity/DiscordMessage.kt
@@ -108,6 +108,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
+import kotlin.jvm.JvmName
/**
* Represents [a message sent in a channel within Discord](https://discord.com/developers/docs/resources/channel#message-object).
diff --git a/common/src/main/kotlin/entity/DiscordNull.kt b/common/src/commonMain/kotlin/entity/DiscordNull.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordNull.kt
rename to common/src/commonMain/kotlin/entity/DiscordNull.kt
diff --git a/common/src/main/kotlin/entity/DiscordRole.kt b/common/src/commonMain/kotlin/entity/DiscordRole.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordRole.kt
rename to common/src/commonMain/kotlin/entity/DiscordRole.kt
diff --git a/common/src/main/kotlin/entity/DiscordSelectOption.kt b/common/src/commonMain/kotlin/entity/DiscordSelectOption.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordSelectOption.kt
rename to common/src/commonMain/kotlin/entity/DiscordSelectOption.kt
diff --git a/common/src/main/kotlin/entity/DiscordShard.kt b/common/src/commonMain/kotlin/entity/DiscordShard.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordShard.kt
rename to common/src/commonMain/kotlin/entity/DiscordShard.kt
diff --git a/common/src/main/kotlin/entity/DiscordStageInstance.kt b/common/src/commonMain/kotlin/entity/DiscordStageInstance.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordStageInstance.kt
rename to common/src/commonMain/kotlin/entity/DiscordStageInstance.kt
diff --git a/common/src/main/kotlin/entity/DiscordTemplate.kt b/common/src/commonMain/kotlin/entity/DiscordTemplate.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordTemplate.kt
rename to common/src/commonMain/kotlin/entity/DiscordTemplate.kt
diff --git a/common/src/main/kotlin/entity/DiscordUser.kt b/common/src/commonMain/kotlin/entity/DiscordUser.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordUser.kt
rename to common/src/commonMain/kotlin/entity/DiscordUser.kt
diff --git a/common/src/main/kotlin/entity/DiscordWebhook.kt b/common/src/commonMain/kotlin/entity/DiscordWebhook.kt
similarity index 100%
rename from common/src/main/kotlin/entity/DiscordWebhook.kt
rename to common/src/commonMain/kotlin/entity/DiscordWebhook.kt
diff --git a/common/src/main/kotlin/entity/Interactions.kt b/common/src/commonMain/kotlin/entity/Interactions.kt
similarity index 100%
rename from common/src/main/kotlin/entity/Interactions.kt
rename to common/src/commonMain/kotlin/entity/Interactions.kt
diff --git a/common/src/main/kotlin/entity/Member.kt b/common/src/commonMain/kotlin/entity/Member.kt
similarity index 100%
rename from common/src/main/kotlin/entity/Member.kt
rename to common/src/commonMain/kotlin/entity/Member.kt
diff --git a/common/src/main/kotlin/entity/Permission.kt b/common/src/commonMain/kotlin/entity/Permission.kt
similarity index 99%
rename from common/src/main/kotlin/entity/Permission.kt
rename to common/src/commonMain/kotlin/entity/Permission.kt
index a5f27c30332..ce1ed221156 100644
--- a/common/src/main/kotlin/entity/Permission.kt
+++ b/common/src/commonMain/kotlin/entity/Permission.kt
@@ -11,6 +11,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
+import kotlin.jvm.JvmName
@Serializable(with = Permissions.Companion::class)
diff --git a/common/src/main/kotlin/entity/Presence.kt b/common/src/commonMain/kotlin/entity/Presence.kt
similarity index 100%
rename from common/src/main/kotlin/entity/Presence.kt
rename to common/src/commonMain/kotlin/entity/Presence.kt
diff --git a/common/src/main/kotlin/entity/Snowflake.kt b/common/src/commonMain/kotlin/entity/Snowflake.kt
similarity index 94%
rename from common/src/main/kotlin/entity/Snowflake.kt
rename to common/src/commonMain/kotlin/entity/Snowflake.kt
index ba5a7bffbf4..07a1f2a06ab 100644
--- a/common/src/main/kotlin/entity/Snowflake.kt
+++ b/common/src/commonMain/kotlin/entity/Snowflake.kt
@@ -138,7 +138,7 @@ public class Snowflake : Comparable {
*
* The comparison is based first on the value of the [timestamp], then on the value of the [workerId], then on the
* value of the [processId] and finally on the value of the [increment]. It is *consistent with equals*, as defined
- * by [Comparable][java.lang.Comparable].
+ * by [Comparable](https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html).
*/
override fun compareTo(other: Snowflake): Int {
// the layout of Snowflake values from MSB to LSB is timestamp, workerId, processId, increment,
@@ -175,9 +175,10 @@ public class Snowflake : Comparable {
* [processId] and [increment] are not taken into account.
*
* Note: this comparator imposes an ordering that is *inconsistent with equals*, as defined by
- * [Comparator][java.util.Comparator]. It therefore shouldn't be used to order a
- * [SortedSet][java.util.SortedSet] or [SortedMap][java.util.SortedMap]. This is because `TimestampComparator`
- * only compares the first 42 bits of the ULong [value] (comparing the timestamp), whereas
+ * [Comparator](https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html). It therefore shouldn't be
+ * used to order a [SortedSet](https://docs.oracle.com/javase/8/docs/api/java/util/SortedSet.html) or
+ * [SortedMap](https://docs.oracle.com/javase/8/docs/api/java/util/SortedMap.html). This is because
+ * `TimestampComparator` only compares the first 42 bits of the ULong [value] (comparing the timestamp), whereas
* [equals][Snowflake.equals] compares all the bits of the [value]. `TimestampComparator` can return `0` even if
* [equals][Snowflake.equals] returns `false`, but [equals][Snowflake.equals] only returns `true` if
* `TimestampComparator` returns `0`.
diff --git a/common/src/main/kotlin/entity/Team.kt b/common/src/commonMain/kotlin/entity/Team.kt
similarity index 100%
rename from common/src/main/kotlin/entity/Team.kt
rename to common/src/commonMain/kotlin/entity/Team.kt
diff --git a/common/src/main/kotlin/entity/optional/Optional.kt b/common/src/commonMain/kotlin/entity/optional/Optional.kt
similarity index 98%
rename from common/src/main/kotlin/entity/optional/Optional.kt
rename to common/src/commonMain/kotlin/entity/optional/Optional.kt
index c67a8cbebe7..96b157dfe69 100644
--- a/common/src/main/kotlin/entity/optional/Optional.kt
+++ b/common/src/commonMain/kotlin/entity/optional/Optional.kt
@@ -9,6 +9,8 @@ import kotlinx.serialization.SerializationException
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
+import kotlin.js.JsName
+import kotlin.jvm.JvmName
/**
* Represents a value that encapsulates all [three possible states of a value in the Discord API](https://discord.com/developers/docs/reference#nullable-and-optional-resource-fields).
@@ -143,6 +145,7 @@ public sealed class Optional {
* Returns an [Optional] that is either [value] on a non-null [value], or [Null] on `null`.
*/
@JvmName("invokeNullable")
+ @JsName("invokeNullable")
public operator fun invoke(value: T?): Optional = when (value) {
null -> Null()
else -> Value(value)
@@ -252,6 +255,7 @@ public inline fun Optional.flatMap(mapper: (E) -> Optional
@Suppress("UNCHECKED_CAST")
@JvmName("mapNullableOptional")
+@JsName("mapNullableOptional")
public inline fun Optional.map(mapper: (E) -> T): Optional = when (this) {
is Missing, is Null<*> -> this as Optional
is Value -> Value(mapper(value!!))
@@ -285,6 +289,7 @@ public inline fun Optional.mapSnowflake(mapper: (E) -> Snowflake):
}
@JvmName("mapNullableSnowflake")
+@JsName("mapNullableSnowflake")
public inline fun Optional.mapSnowflake(mapper: (E) -> Snowflake): OptionalSnowflake = when (this) {
is Missing, is Null<*> -> OptionalSnowflake.Missing
is Value -> OptionalSnowflake.Value(mapper(value!!))
diff --git a/common/src/main/kotlin/entity/optional/OptionalBoolean.kt b/common/src/commonMain/kotlin/entity/optional/OptionalBoolean.kt
similarity index 100%
rename from common/src/main/kotlin/entity/optional/OptionalBoolean.kt
rename to common/src/commonMain/kotlin/entity/optional/OptionalBoolean.kt
diff --git a/common/src/main/kotlin/entity/optional/OptionalInt.kt b/common/src/commonMain/kotlin/entity/optional/OptionalInt.kt
similarity index 100%
rename from common/src/main/kotlin/entity/optional/OptionalInt.kt
rename to common/src/commonMain/kotlin/entity/optional/OptionalInt.kt
diff --git a/common/src/main/kotlin/entity/optional/OptionalLong.kt b/common/src/commonMain/kotlin/entity/optional/OptionalLong.kt
similarity index 100%
rename from common/src/main/kotlin/entity/optional/OptionalLong.kt
rename to common/src/commonMain/kotlin/entity/optional/OptionalLong.kt
diff --git a/common/src/main/kotlin/entity/optional/OptionalSnowflake.kt b/common/src/commonMain/kotlin/entity/optional/OptionalSnowflake.kt
similarity index 99%
rename from common/src/main/kotlin/entity/optional/OptionalSnowflake.kt
rename to common/src/commonMain/kotlin/entity/optional/OptionalSnowflake.kt
index cd304db7504..f8fbbdb9ef9 100644
--- a/common/src/main/kotlin/entity/optional/OptionalSnowflake.kt
+++ b/common/src/commonMain/kotlin/entity/optional/OptionalSnowflake.kt
@@ -7,6 +7,7 @@ import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
+import kotlin.jvm.JvmName
/**
* Represents a value that encapsulate a [Snowflake]'s
diff --git a/common/src/main/kotlin/entity/optional/delegate/OptionalBooleanDelegate.kt b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalBooleanDelegate.kt
similarity index 98%
rename from common/src/main/kotlin/entity/optional/delegate/OptionalBooleanDelegate.kt
rename to common/src/commonMain/kotlin/entity/optional/delegate/OptionalBooleanDelegate.kt
index 698e198fa82..dfb602cad61 100644
--- a/common/src/main/kotlin/entity/optional/delegate/OptionalBooleanDelegate.kt
+++ b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalBooleanDelegate.kt
@@ -3,6 +3,7 @@ package dev.kord.common.entity.optional.delegate
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.optional
import dev.kord.common.entity.optional.value
+import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
diff --git a/common/src/main/kotlin/entity/optional/delegate/OptionalDelegate.kt b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalDelegate.kt
similarity index 95%
rename from common/src/main/kotlin/entity/optional/delegate/OptionalDelegate.kt
rename to common/src/commonMain/kotlin/entity/optional/delegate/OptionalDelegate.kt
index e2b498760f0..cf5f6517d4b 100644
--- a/common/src/main/kotlin/entity/optional/delegate/OptionalDelegate.kt
+++ b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalDelegate.kt
@@ -1,6 +1,8 @@
package dev.kord.common.entity.optional.delegate
import dev.kord.common.entity.optional.Optional
+import kotlin.js.JsName
+import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
@@ -42,6 +44,7 @@ public fun KMutableProperty0>>.delegateList(): ReadWr
}
@JvmName("provideNullableDelegate")
+@JsName("provideNullableDelegate")
public fun KMutableProperty0>.delegate(): ReadWriteProperty =
object : ReadWriteProperty {
diff --git a/common/src/main/kotlin/entity/optional/delegate/OptionalIntDelegate.kt b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalIntDelegate.kt
similarity index 94%
rename from common/src/main/kotlin/entity/optional/delegate/OptionalIntDelegate.kt
rename to common/src/commonMain/kotlin/entity/optional/delegate/OptionalIntDelegate.kt
index e938aab84a6..239c8e84410 100644
--- a/common/src/main/kotlin/entity/optional/delegate/OptionalIntDelegate.kt
+++ b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalIntDelegate.kt
@@ -3,10 +3,13 @@ package dev.kord.common.entity.optional.delegate
import dev.kord.common.entity.optional.OptionalInt
import dev.kord.common.entity.optional.optionalInt
import dev.kord.common.entity.optional.value
+import kotlin.js.JsName
+import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
+@JsName("intDelegate")
public fun KMutableProperty0.delegate(): ReadWriteProperty = object : ReadWriteProperty {
override fun getValue(thisRef: Any?, property: KProperty<*>): Int? {
diff --git a/common/src/main/kotlin/entity/optional/delegate/OptionalLongDelegate.kt b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalLongDelegate.kt
similarity index 98%
rename from common/src/main/kotlin/entity/optional/delegate/OptionalLongDelegate.kt
rename to common/src/commonMain/kotlin/entity/optional/delegate/OptionalLongDelegate.kt
index 1f3e674d557..8e67e2ecfef 100644
--- a/common/src/main/kotlin/entity/optional/delegate/OptionalLongDelegate.kt
+++ b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalLongDelegate.kt
@@ -3,6 +3,7 @@ package dev.kord.common.entity.optional.delegate
import dev.kord.common.entity.optional.OptionalLong
import dev.kord.common.entity.optional.optional
import dev.kord.common.entity.optional.value
+import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
diff --git a/common/src/main/kotlin/entity/optional/delegate/OptionalSnowflakeDelegate.kt b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalSnowflakeDelegate.kt
similarity index 98%
rename from common/src/main/kotlin/entity/optional/delegate/OptionalSnowflakeDelegate.kt
rename to common/src/commonMain/kotlin/entity/optional/delegate/OptionalSnowflakeDelegate.kt
index 975f299eb4e..756689e8972 100644
--- a/common/src/main/kotlin/entity/optional/delegate/OptionalSnowflakeDelegate.kt
+++ b/common/src/commonMain/kotlin/entity/optional/delegate/OptionalSnowflakeDelegate.kt
@@ -4,6 +4,7 @@ import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.OptionalSnowflake
import dev.kord.common.entity.optional.optionalSnowflake
import dev.kord.common.entity.optional.value
+import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
diff --git a/common/src/main/kotlin/exception/RequestException.kt b/common/src/commonMain/kotlin/exception/RequestException.kt
similarity index 100%
rename from common/src/main/kotlin/exception/RequestException.kt
rename to common/src/commonMain/kotlin/exception/RequestException.kt
diff --git a/common/src/commonMain/kotlin/http/HttpEngine.kt b/common/src/commonMain/kotlin/http/HttpEngine.kt
new file mode 100644
index 00000000000..feabfdbdebd
--- /dev/null
+++ b/common/src/commonMain/kotlin/http/HttpEngine.kt
@@ -0,0 +1,8 @@
+package dev.kord.common.http
+
+import dev.kord.common.annotation.KordInternal
+import io.ktor.client.engine.*
+
+/** @suppress */
+@KordInternal
+public expect object HttpEngine : HttpClientEngineFactory
diff --git a/common/src/main/kotlin/ratelimit/AbstractIntervalRateLimiter.kt b/common/src/commonMain/kotlin/ratelimit/AbstractIntervalRateLimiter.kt
similarity index 100%
rename from common/src/main/kotlin/ratelimit/AbstractIntervalRateLimiter.kt
rename to common/src/commonMain/kotlin/ratelimit/AbstractIntervalRateLimiter.kt
diff --git a/common/src/main/kotlin/ratelimit/ClockIntervalRateLimiter.kt b/common/src/commonMain/kotlin/ratelimit/ClockIntervalRateLimiter.kt
similarity index 100%
rename from common/src/main/kotlin/ratelimit/ClockIntervalRateLimiter.kt
rename to common/src/commonMain/kotlin/ratelimit/ClockIntervalRateLimiter.kt
diff --git a/common/src/main/kotlin/ratelimit/RateLimiter.kt b/common/src/commonMain/kotlin/ratelimit/RateLimiter.kt
similarity index 100%
rename from common/src/main/kotlin/ratelimit/RateLimiter.kt
rename to common/src/commonMain/kotlin/ratelimit/RateLimiter.kt
diff --git a/common/src/main/kotlin/ratelimit/TimeSourceIntervalRateLimiter.kt b/common/src/commonMain/kotlin/ratelimit/TimeSourceIntervalRateLimiter.kt
similarity index 100%
rename from common/src/main/kotlin/ratelimit/TimeSourceIntervalRateLimiter.kt
rename to common/src/commonMain/kotlin/ratelimit/TimeSourceIntervalRateLimiter.kt
diff --git a/common/src/main/kotlin/serialization/DurationSerializers.kt b/common/src/commonMain/kotlin/serialization/DurationSerializers.kt
similarity index 100%
rename from common/src/main/kotlin/serialization/DurationSerializers.kt
rename to common/src/commonMain/kotlin/serialization/DurationSerializers.kt
diff --git a/common/src/main/kotlin/serialization/InstantSerializers.kt b/common/src/commonMain/kotlin/serialization/InstantSerializers.kt
similarity index 100%
rename from common/src/main/kotlin/serialization/InstantSerializers.kt
rename to common/src/commonMain/kotlin/serialization/InstantSerializers.kt
diff --git a/common/src/main/kotlin/serialization/LongOrStringSerializer.kt b/common/src/commonMain/kotlin/serialization/LongOrStringSerializer.kt
similarity index 100%
rename from common/src/main/kotlin/serialization/LongOrStringSerializer.kt
rename to common/src/commonMain/kotlin/serialization/LongOrStringSerializer.kt
diff --git a/common/src/test/kotlin/BitSetTests.kt b/common/src/commonTest/kotlin/BitSetTests.kt
similarity index 84%
rename from common/src/test/kotlin/BitSetTests.kt
rename to common/src/commonTest/kotlin/BitSetTests.kt
index c4fe11871bb..0360bdfdf60 100644
--- a/common/src/test/kotlin/BitSetTests.kt
+++ b/common/src/commonTest/kotlin/BitSetTests.kt
@@ -1,9 +1,11 @@
-import dev.kord.common.DiscordBitSet
-import dev.kord.common.EmptyBitSet
+package dev.kord.common
+
+import kotlin.js.JsName
import kotlin.test.*
class BitSetTests {
@Test
+ @JsName("test1")
fun `a contains b and c`() {
val a = DiscordBitSet(0b111)
val b = DiscordBitSet(0b101)
@@ -13,6 +15,7 @@ class BitSetTests {
}
@Test
+ @JsName("test2")
fun `a and b are equal and have the same hashCode`() {
val a = DiscordBitSet(0b111, 0)
val b = DiscordBitSet(0b111)
@@ -21,6 +24,7 @@ class BitSetTests {
}
@Test
+ @JsName("test3")
fun `a does not equal b`() {
val a = DiscordBitSet(0b111, 0)
val b = DiscordBitSet(0b111, 0b1)
@@ -28,6 +32,7 @@ class BitSetTests {
}
@Test
+ @JsName("test4")
fun `get bits`() {
val a = DiscordBitSet(0b101, 0)
assertTrue(a[0])
@@ -41,6 +46,7 @@ class BitSetTests {
}
@Test
+ @JsName("test5")
fun `set bits`() {
val a = EmptyBitSet()
for (i in 0..64) a[i] = true
@@ -56,28 +62,32 @@ class BitSetTests {
}
@Test
+ @JsName("test6")
fun `get a bit out of range`() {
val a = DiscordBitSet(0b101, 0)
- assert(!a[10000])
+ assertFalse(a[10000])
}
@Test
+ @JsName("test7")
fun `add and remove a bit`() {
val a = DiscordBitSet(0b101, 0)
a.add(DiscordBitSet(0b111))
- assert(a.value == 0b111.toString())
+ assertEquals(0b111.toString(), a.value)
a.remove(DiscordBitSet(0b001))
- assert(a.value == 0b110.toString())
+ assertEquals(0b110.toString(), a.value)
}
@Test
+ @JsName("test8")
fun `remove a bit`() {
val a = DiscordBitSet(0b101, 0)
a.remove(DiscordBitSet(0b111))
- assert(a.value == "0")
+ assertEquals("0", a.value)
}
@Test
+ @JsName("test9")
fun `binary works`() {
assertEquals("0", DiscordBitSet().binary)
assertEquals("0", DiscordBitSet(0).binary)
diff --git a/common/src/test/kotlin/ColorTests.kt b/common/src/commonTest/kotlin/ColorTests.kt
similarity index 61%
rename from common/src/test/kotlin/ColorTests.kt
rename to common/src/commonTest/kotlin/ColorTests.kt
index bff3b926191..5dfd63076ae 100644
--- a/common/src/test/kotlin/ColorTests.kt
+++ b/common/src/commonTest/kotlin/ColorTests.kt
@@ -1,16 +1,19 @@
-import dev.kord.common.Color
-import dev.kord.common.kColor
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertThrows
+package dev.kord.common
+
+import kotlin.js.JsName
+import kotlin.test.Test
import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
class ColorTests {
@Test
+ @JsName("test1")
fun `Color throws if invalid rgb value is provided`() {
- assertThrows { Color(256, 256, 300) }
+ assertFailsWith { Color(256, 256, 300) }
}
@Test
+ @JsName("test2")
fun `Color provides a correct value`() {
val red = Color(0xFF0000)
assertEquals(255, red.red)
@@ -25,15 +28,7 @@ class ColorTests {
}
@Test
- fun `java to kColor conversion`() {
- val color = java.awt.Color.decode("#DBD0B4").kColor
-
- assertEquals(219, color.red)
- assertEquals(208, color.green)
- assertEquals(180, color.blue)
- }
-
- @Test
+ @JsName("test3")
fun `Color implementation should drop alpha values if given`() {
val color = Color(0x1E1F2E3D)
assertEquals(0x1F2E3D, color.rgb)
diff --git a/common/src/test/kotlin/FixedClock.kt b/common/src/commonTest/kotlin/FixedClock.kt
similarity index 90%
rename from common/src/test/kotlin/FixedClock.kt
rename to common/src/commonTest/kotlin/FixedClock.kt
index 9268573652a..b34fdb8dcf7 100644
--- a/common/src/test/kotlin/FixedClock.kt
+++ b/common/src/commonTest/kotlin/FixedClock.kt
@@ -1,3 +1,5 @@
+package dev.kord.common
+
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
diff --git a/common/src/test/kotlin/LocaleTest.kt b/common/src/commonTest/kotlin/LocaleTest.kt
similarity index 95%
rename from common/src/test/kotlin/LocaleTest.kt
rename to common/src/commonTest/kotlin/LocaleTest.kt
index e8f29c8b4ba..3130f7f8516 100644
--- a/common/src/test/kotlin/LocaleTest.kt
+++ b/common/src/commonTest/kotlin/LocaleTest.kt
@@ -1,7 +1,9 @@
-import dev.kord.common.Locale
+package dev.kord.common
+
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
+import kotlin.js.JsName
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -49,6 +51,7 @@ class LocaleTest {
@Test
+ @JsName("test1")
fun `all documented Locales can be deserialized`() {
all.forEach { (string, locale) ->
assertEquals(expected = locale, actual = Json.decodeFromString("\"$string\""))
@@ -56,6 +59,7 @@ class LocaleTest {
}
@Test
+ @JsName("test2")
fun `all documented Locales can be serialized`() {
all.forEach { (string, locale) ->
assertEquals(expected = "\"$string\"", actual = Json.encodeToString(locale))
diff --git a/common/src/test/kotlin/entity/SnowflakeTest.kt b/common/src/commonTest/kotlin/entity/SnowflakeTest.kt
similarity index 91%
rename from common/src/test/kotlin/entity/SnowflakeTest.kt
rename to common/src/commonTest/kotlin/entity/SnowflakeTest.kt
index 23832a7985a..6a52cfdc51a 100644
--- a/common/src/test/kotlin/entity/SnowflakeTest.kt
+++ b/common/src/commonTest/kotlin/entity/SnowflakeTest.kt
@@ -1,8 +1,8 @@
-package entity
+package dev.kord.common.entity
-import dev.kord.common.entity.Snowflake
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
+import kotlin.js.JsName
import kotlin.test.*
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.nanoseconds
@@ -10,46 +10,54 @@ import kotlin.time.Duration.Companion.nanoseconds
class SnowflakeTest {
@Test
+ @JsName("test1")
fun `min Snowflake's timestamp is equal to discordEpoch`() {
assertEquals(Snowflake.discordEpoch, Snowflake.min.timestamp)
}
@Test
+ @JsName("test2")
fun `max Snowflake's timestamp is equal to endOfTime`() {
assertEquals(Snowflake.endOfTime, Snowflake.max.timestamp)
}
@Test
+ @JsName("test3")
fun `Snowflake created from ULong MIN_VALUE has timestamp equal to discordEpoch`() {
val snowflake = Snowflake(ULong.MIN_VALUE)
assertEquals(Snowflake.discordEpoch, snowflake.timestamp)
}
@Test
+ @JsName("test4")
fun `Snowflake created from ULong MAX_VALUE has timestamp equal to endOfTime`() {
val snowflake = Snowflake(ULong.MAX_VALUE)
assertEquals(Snowflake.endOfTime, snowflake.timestamp)
}
@Test
+ @JsName("test5")
fun `Snowflake created from Long MIN_VALUE has timestamp equal to discordEpoch`() {
val snowflake = Snowflake(Long.MIN_VALUE)
assertEquals(Snowflake.discordEpoch, snowflake.timestamp)
}
@Test
+ @JsName("test6")
fun `Snowflake created from instant far in the past has timestamp equal to discordEpoch`() {
val snowflake = Snowflake(Instant.DISTANT_PAST)
assertEquals(Snowflake.discordEpoch, snowflake.timestamp)
}
@Test
+ @JsName("test7")
fun `Snowflake created from instant far in the future has timestamp equal to endOfTime`() {
val snowflake = Snowflake(Instant.DISTANT_FUTURE)
assertEquals(Snowflake.endOfTime, snowflake.timestamp)
}
@Test
+ @JsName("test8")
fun `Snowflake's timestamp calculates an Instant close to the Instant the Snowflake was created from`() {
val instant = Clock.System.now()
val snowflake = Snowflake(instant)
@@ -62,16 +70,19 @@ class SnowflakeTest {
}
@Test
+ @JsName("test9")
fun `min Snowflake's timeMark has passed`() {
assertTrue(Snowflake.min.timeMark.hasPassedNow())
}
@Test
+ @JsName("test10")
fun `max Snowflake's timeMark has not passed`() {
assertFalse(Snowflake.max.timeMark.hasPassedNow())
}
@Test
+ @JsName("test11")
fun `Snowflake can be destructured`() {
val snowflake = Snowflake(0b110010110111_10111_01101_101100111101_u)
val (timestamp, worker, process, increment) = snowflake
@@ -88,6 +99,7 @@ class SnowflakeTest {
}
@Test
+ @JsName("test12")
fun `Snowflakes are compared correctly`() {
// timestamp worker process increment
// vvv vvv vvv vvv
@@ -116,13 +128,4 @@ class SnowflakeTest {
assertEquals(0, compare(c, f))
}
}
-
- @Test
- fun `Snowflake's natural order works with SortedSets`() {
- val a = Snowflake(0b0_00000_00000_000000000000_u)
- val b = Snowflake(0b0_00000_00000_000000000001_u)
- val c = Snowflake(0b1_00000_00000_000000000000_u)
- assertEquals(2, sortedSetOf(a, b).size)
- assertEquals(2, sortedSetOf(a, c).size)
- }
}
diff --git a/common/src/test/kotlin/entity/optional/OptionalBooleanTest.kt b/common/src/commonTest/kotlin/entity/optional/OptionalBooleanTest.kt
similarity index 71%
rename from common/src/test/kotlin/entity/optional/OptionalBooleanTest.kt
rename to common/src/commonTest/kotlin/entity/optional/OptionalBooleanTest.kt
index 14b32bf1d2b..74142b875b2 100644
--- a/common/src/test/kotlin/entity/optional/OptionalBooleanTest.kt
+++ b/common/src/commonTest/kotlin/entity/optional/OptionalBooleanTest.kt
@@ -4,9 +4,11 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
-import org.intellij.lang.annotations.Language
-import org.junit.jupiter.api.Assertions
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
+import kotlin.test.assertFailsWith
+import kotlin.test.assertIs
+import kotlin.test.assertTrue
internal class OptionalBooleanTest {
@@ -14,24 +16,26 @@ internal class OptionalBooleanTest {
private class EmptyOptionalEntity(val value: OptionalBoolean = OptionalBoolean.Missing)
@Test
+ @JsName("test1")
fun `deserializing nothing in optional assigns Missing`(){
- @Language("json")
+ //language=json
val json = """{}"""
val entity = Json.decodeFromString(json)
- assert(entity.value is OptionalBoolean.Missing)
+ assertIs(entity.value)
}
@Serializable
private class NullOptionalEntity(@Suppress("unused") val value: OptionalBoolean = OptionalBoolean.Missing)
@Test
+ @JsName("test2")
fun `deserializing null in optional throws SerializationException`(){
- @Language("json")
+ //language=json
val json = """{ "value":null }"""
- org.junit.jupiter.api.assertThrows {
+ assertFailsWith {
Json.decodeFromString(json)
}
}
@@ -40,15 +44,16 @@ internal class OptionalBooleanTest {
private class ValueOptionalEntity(@Suppress("unused") val value: OptionalBoolean = OptionalBoolean.Missing)
@Test
+ @JsName("test3")
fun `deserializing value in optional assigns Value`(){
- @Language("json")
+ //language=json
val json = """{ "value":true }"""
val entity = Json.decodeFromString(json)
- require(entity.value is OptionalBoolean.Value)
+ assertIs(entity.value)
- Assertions.assertEquals(true, entity.value.value)
+ assertTrue(entity.value.value)
}
}
diff --git a/common/src/test/kotlin/entity/optional/OptionalIntTest.kt b/common/src/commonTest/kotlin/entity/optional/OptionalIntTest.kt
similarity index 73%
rename from common/src/test/kotlin/entity/optional/OptionalIntTest.kt
rename to common/src/commonTest/kotlin/entity/optional/OptionalIntTest.kt
index a6f497e26be..cda9d356eb1 100644
--- a/common/src/test/kotlin/entity/optional/OptionalIntTest.kt
+++ b/common/src/commonTest/kotlin/entity/optional/OptionalIntTest.kt
@@ -4,9 +4,8 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
-import org.intellij.lang.annotations.Language
-import org.junit.jupiter.api.Assertions.*
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.*
internal class OptionalIntTest {
@@ -14,13 +13,14 @@ internal class OptionalIntTest {
private class EmptyOptionalEntity(val value: OptionalInt = OptionalInt.Missing)
@Test
+ @JsName("test1")
fun `deserializing nothing in optional assigns Missing`(){
- @Language("json")
+ //language=json
val json = """{}"""
val entity = Json.decodeFromString(json)
- assert(entity.value is OptionalInt.Missing)
+ assertIs(entity.value)
}
@@ -28,12 +28,13 @@ internal class OptionalIntTest {
private class NullOptionalEntity(@Suppress("unused") val value: OptionalInt = OptionalInt.Missing)
@Test
+ @JsName("test2")
fun `deserializing null in optional throws SerializationException`(){
- @Language("json")
+ //language=json
val json = """{ "value":null }"""
- org.junit.jupiter.api.assertThrows {
+ assertFailsWith {
Json.decodeFromString(json)
}
}
@@ -42,14 +43,15 @@ internal class OptionalIntTest {
class ValueOptionalEntity(@Suppress("unused") val value: OptionalInt = OptionalInt.Missing)
@Test
+ @JsName("test3")
fun `deserializing value in optional assigns Value`(){
- @Language("json")
+ //language=json
val json = """{ "value":5 }"""
val entity = Json.decodeFromString(json)
- require(entity.value is OptionalInt.Value)
+ assertIs(entity.value)
- assertEquals(5, entity.value.value)
+ assertSame(5, entity.value.value)
}
}
diff --git a/common/src/test/kotlin/entity/optional/OptionalLongTest.kt b/common/src/commonTest/kotlin/entity/optional/OptionalLongTest.kt
similarity index 73%
rename from common/src/test/kotlin/entity/optional/OptionalLongTest.kt
rename to common/src/commonTest/kotlin/entity/optional/OptionalLongTest.kt
index 9ec0618be62..d67d1e6d5d5 100644
--- a/common/src/test/kotlin/entity/optional/OptionalLongTest.kt
+++ b/common/src/commonTest/kotlin/entity/optional/OptionalLongTest.kt
@@ -4,9 +4,8 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
-import org.intellij.lang.annotations.Language
-import org.junit.jupiter.api.Assertions
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.*
internal class OptionalLongTest {
@@ -14,14 +13,15 @@ internal class OptionalLongTest {
class EmptyOptionalEntity(val value: OptionalLong = OptionalLong.Missing)
@Test
+ @JsName("test1")
fun `deserializing nothing in optional assigns Missing`() {
- @Language("json")
+ //language=json
val json = """{}"""
val entity = Json.decodeFromString(json)
- assert(entity.value is OptionalLong.Missing)
+ assertIs(entity.value)
}
@@ -29,12 +29,13 @@ internal class OptionalLongTest {
class NullOptionalEntity(@Suppress("unused") val value: OptionalLong = OptionalLong.Missing)
@Test
+ @JsName("test2")
fun `deserializing null in optional throws SerializationException`() {
- @Language("json")
+ //language=json
val json = """{ "value":null }"""
- org.junit.jupiter.api.assertThrows {
+ assertFailsWith {
Json.decodeFromString(json)
}
}
@@ -44,14 +45,15 @@ internal class OptionalLongTest {
class ValueOptionalEntity(@Suppress("unused") val value: OptionalLong = OptionalLong.Missing)
@Test
+ @JsName("test3")
fun `deserializing value in optional assigns Value`() {
- @Language("json")
+ //language=json
val json = """{ "value":5 }"""
val entity = Json.decodeFromString(json)
- require(entity.value is OptionalLong.Value)
+ assertIs(entity.value)
- Assertions.assertEquals(5, entity.value.value)
+ assertEquals(5, entity.value.value)
}
}
diff --git a/common/src/test/kotlin/entity/optional/OptionalSnowflakeTest.kt b/common/src/commonTest/kotlin/entity/optional/OptionalSnowflakeTest.kt
similarity index 65%
rename from common/src/test/kotlin/entity/optional/OptionalSnowflakeTest.kt
rename to common/src/commonTest/kotlin/entity/optional/OptionalSnowflakeTest.kt
index 3bdc8cb69fa..d7f4b05a391 100644
--- a/common/src/test/kotlin/entity/optional/OptionalSnowflakeTest.kt
+++ b/common/src/commonTest/kotlin/entity/optional/OptionalSnowflakeTest.kt
@@ -5,9 +5,8 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
-import org.intellij.lang.annotations.Language
-import org.junit.jupiter.api.Assertions
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.*
internal class OptionalSnowflakeTest {
@@ -16,14 +15,15 @@ internal class OptionalSnowflakeTest {
class EmptyOptionalEntity(val value: OptionalSnowflake = OptionalSnowflake.Missing)
@Test
- fun `deserializing nothing in optional assigns Missing`(){
- @Language("json")
+ @JsName("test1")
+ fun `deserializing nothing in optional assigns Missing`() {
+ //language=json
val json = """{}"""
val entity = Json.decodeFromString(json)
- assert(entity.value is OptionalSnowflake.Missing)
+ assertIs(entity.value)
}
@@ -31,11 +31,12 @@ internal class OptionalSnowflakeTest {
class NullOptionalEntity(@Suppress("unused") val value: OptionalSnowflake = OptionalSnowflake.Missing)
@Test
- fun `deserializing null in optional throws SerializationException`(){
- @Language("json")
+ @JsName("test2")
+ fun `deserializing null in optional throws SerializationException`() {
+ //language=json
val json = """{ "value":null }"""
- org.junit.jupiter.api.assertThrows {
+ assertFailsWith {
Json.decodeFromString(json)
}
}
@@ -45,14 +46,14 @@ internal class OptionalSnowflakeTest {
class ValueOptionalEntity(@Suppress("unused") val value: OptionalSnowflake = OptionalSnowflake.Missing)
@Test
- fun `deserializing value in optional assigns Value`(){
- @Language("json")
+ @JsName("test3")
+ fun `deserializing value in optional assigns Value`() {
+ //language=test
val json = """{ "value":5 }"""
val entity = Json.decodeFromString(json)
- require(entity.value is OptionalSnowflake.Value)
-
- Assertions.assertEquals(Snowflake(5u), entity.value.value)
+ assertIs(entity.value)
+ assertEquals(Snowflake(5u), entity.value.value)
}
}
diff --git a/common/src/test/kotlin/entity/optional/OptionalTest.kt b/common/src/commonTest/kotlin/entity/optional/OptionalTest.kt
similarity index 71%
rename from common/src/test/kotlin/entity/optional/OptionalTest.kt
rename to common/src/commonTest/kotlin/entity/optional/OptionalTest.kt
index c06c47e4ae3..25879bfaff6 100644
--- a/common/src/test/kotlin/entity/optional/OptionalTest.kt
+++ b/common/src/commonTest/kotlin/entity/optional/OptionalTest.kt
@@ -4,26 +4,31 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
-import org.intellij.lang.annotations.Language
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
+import kotlin.test.assertIs
internal class OptionalTest {
@Test
+ @JsName("test1")
fun `creating optional from nullable value returns Value on non-null value`() {
- val value: Int? = 5
+ val value = 5
val optional = Optional(value)
- assert(optional is Optional.Value)
- assert((optional as Optional.Value).value == value)
+ assertIs>(optional)
+ assertEquals(optional.value, value)
}
@Test
+ @JsName("test2")
fun `creating optional from nullable value returns Null on null value`() {
val value: Int? = null
val optional = Optional(value)
- assert(optional is Optional.Null)
+ assertIs>(optional)
}
@@ -31,13 +36,14 @@ internal class OptionalTest {
private class NullOptionalEntity(val value: Optional = Optional.Missing())
@Test
+ @JsName("test3")
fun `deserializing null in nullable optional assigns Null`() {
- @Language("json")
+ //language=json
val json = """{ "value":null }"""
val entity = Json.decodeFromString(json)
- assert(entity.value is Optional.Null)
+ assertIs>(entity.value)
}
@@ -45,13 +51,14 @@ internal class OptionalTest {
class EmptyOptionalEntity(val value: Optional = Optional.Missing())
@Test
+ @JsName("test4")
fun `deserializing nothing in nullable optional assigns Missing`() {
- @Language("json")
+ //language=json
val json = """{}"""
val entity = Json.decodeFromString(json)
- assert(entity.value is Optional.Missing)
+ assertIs>(entity.value)
}
@@ -59,13 +66,14 @@ internal class OptionalTest {
class UnexpectedEmptyOptionalEntity(val value: Optional = Optional.Missing())
@Test
+ @JsName("test5")
fun `deserializing nothing in non-nullable optional assigns Missing`() {
- @Language("json")
+ //language=json
val json = """{}"""
val entity = Json.decodeFromString(json)
- assert(entity.value is Optional.Missing)
+ assertIs>(entity.value)
}
@@ -73,11 +81,12 @@ internal class OptionalTest {
private class UnexpectedNullOptionalEntity(@Suppress("unused") val value: Optional = Optional.Missing())
@Test
+ @JsName("test6")
fun `deserializing null in non-nullable optional throws SerializationException`() {
- @Language("json")
+ //language=json
val json = """{ "value":null }"""
- org.junit.jupiter.api.assertThrows {
+ assertFailsWith {
Json.decodeFromString(json)
}
}
diff --git a/common/src/commonTest/kotlin/file.kt b/common/src/commonTest/kotlin/file.kt
new file mode 100644
index 00000000000..7f0b71174f9
--- /dev/null
+++ b/common/src/commonTest/kotlin/file.kt
@@ -0,0 +1,5 @@
+package dev.kord.common
+
+import dev.kord.test.file
+suspend fun readFile(prefix: String, name: String): String =
+ file("common", "json/$prefix/$name.json")
diff --git a/common/src/test/kotlin/json/ChannelTest.kt b/common/src/commonTest/kotlin/json/ChannelTest.kt
similarity index 87%
rename from common/src/test/kotlin/json/ChannelTest.kt
rename to common/src/commonTest/kotlin/json/ChannelTest.kt
index 9b87b0d9619..9153fbd5d25 100644
--- a/common/src/test/kotlin/json/ChannelTest.kt
+++ b/common/src/commonTest/kotlin/json/ChannelTest.kt
@@ -1,20 +1,21 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.DiscordChannel
import dev.kord.common.entity.optional.value
+import dev.kord.common.readFile
+import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
import kotlin.time.Duration.Companion.seconds
+import kotlin.test.Test
-private fun file(name: String): String {
- val loader = ChannelTest::class.java.classLoader
- return loader.getResource("json/channel/$name.json")!!.readText()
-}
+private suspend fun file(name: String): String = readFile("channel", name)
class ChannelTest {
@Test
- fun `DMChannel serialization`() {
+ @JsName("test1")
+ fun `DMChannel serialization`() = runTest {
val channel = Json.decodeFromString(DiscordChannel.serializer(), file("dmchannel"))
with(channel) {
@@ -34,7 +35,8 @@ class ChannelTest {
@Test
- fun `ChannelCategory serialization`() {
+ @JsName("test2")
+ fun `ChannelCategory serialization`() = runTest {
val channel = Json.decodeFromString(DiscordChannel.serializer(), file("channelcategory"))
with(channel) {
@@ -50,7 +52,8 @@ class ChannelTest {
@Test
- fun `GroupDMChannel serialization`() {
+ @JsName("test3")
+ fun `GroupDMChannel serialization`() = runTest {
val channel = Json.decodeFromString(DiscordChannel.serializer(), file("groupdmchannel"))
with(channel) {
@@ -78,7 +81,8 @@ class ChannelTest {
@Test
- fun `GuildNewChannel serialization`() {
+ @JsName("test4")
+ fun `GuildNewChannel serialization`() = runTest {
val channel = Json.decodeFromString(DiscordChannel.serializer(), file("guildnewschannel"))
with(channel) {
@@ -97,7 +101,8 @@ class ChannelTest {
@Test
- fun `GuildTextChannel serialization`() {
+ @JsName("test5")
+ fun `GuildTextChannel serialization`() = runTest {
val channel = Json.decodeFromString(DiscordChannel.serializer(), file("guildtextchannel"))
with(channel) {
@@ -117,7 +122,8 @@ class ChannelTest {
@Test
- fun `GuildVoiceChannel serialization`() {
+ @JsName("test6")
+ fun `GuildVoiceChannel serialization`() = runTest {
val channel = Json.decodeFromString(DiscordChannel.serializer(), file("guildvoicechannel"))
with(channel) {
diff --git a/common/src/test/kotlin/json/EmojiTest.kt b/common/src/commonTest/kotlin/json/EmojiTest.kt
similarity index 74%
rename from common/src/test/kotlin/json/EmojiTest.kt
rename to common/src/commonTest/kotlin/json/EmojiTest.kt
index 528b834932e..3cca7f47aaf 100644
--- a/common/src/test/kotlin/json/EmojiTest.kt
+++ b/common/src/commonTest/kotlin/json/EmojiTest.kt
@@ -1,20 +1,20 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.DiscordEmoji
import dev.kord.common.entity.Snowflake
+import dev.kord.common.readFile
+import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
-
-private fun file(name: String): String {
- val loader = ChannelTest::class.java.classLoader
- return loader.getResource("json/emoji/$name.json").readText()
-}
+private suspend fun file(name: String): String = readFile("emoji", name)
class EmojiTest {
@Test
- fun `Custom Emoji serialization`() {
+ @JsName("test1")
+ fun `Custom Emoji serialization`() = runTest {
val emoji = Json.decodeFromString(DiscordEmoji.serializer(), file("customemoji"))
with(emoji) {
@@ -24,7 +24,8 @@ class EmojiTest {
}
@Test
- fun `Standard Emoji serialization`() {
+ @JsName("test2")
+ fun `Standard Emoji serialization`() = runTest {
val emoji = Json.decodeFromString(DiscordEmoji.serializer(), file("standardemoji"))
with(emoji) {
@@ -34,7 +35,8 @@ class EmojiTest {
}
@Test
- fun `Emoji serialization`() {
+ @JsName("test3")
+ fun `Emoji serialization`() = runTest {
val emoji = Json.decodeFromString(DiscordEmoji.serializer(), file("emoji"))
with(emoji) {
diff --git a/common/src/test/kotlin/json/GuildTest.kt b/common/src/commonTest/kotlin/json/GuildTest.kt
similarity index 87%
rename from common/src/test/kotlin/json/GuildTest.kt
rename to common/src/commonTest/kotlin/json/GuildTest.kt
index a0570b56da2..d74d43977f8 100644
--- a/common/src/test/kotlin/json/GuildTest.kt
+++ b/common/src/commonTest/kotlin/json/GuildTest.kt
@@ -1,21 +1,21 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.*
+import dev.kord.common.readFile
+import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
import kotlin.time.Duration.Companion.seconds
+import kotlin.test.Test
-
-private fun file(name: String): String {
- val loader = ChannelTest::class.java.classLoader
- return loader.getResource("json/guild/$name.json")!!.readText()
-}
+private suspend fun file(name: String): String = readFile("guild", name)
class GuildTest {
@Test
- fun `Guild serialization`() {
+ @JsName("test1")
+ fun `Guild serialization`() = runTest {
val guild = Json.decodeFromString(DiscordGuild.serializer(), file("guild"))
with(guild) {
@@ -65,7 +65,8 @@ class GuildTest {
}
@Test
- fun `UnavailableGuild serialization`() {
+ @JsName("test2")
+ fun `UnavailableGuild serialization`() = runTest {
val guild = Json.decodeFromString(DiscordUnavailableGuild.serializer(), file("unavailableguild"))
with(guild) {
@@ -76,7 +77,8 @@ class GuildTest {
}
@Test
- fun `GuildMember serialization`() {
+ @JsName("test3")
+ fun `GuildMember serialization`() = runTest {
val member = Json.decodeFromString(DiscordGuildMember.serializer(), file("guildmember"))
with(member) {
@@ -90,7 +92,8 @@ class GuildTest {
}
@Test
- fun `PartialGuild serialization`() {
+ @JsName("test4")
+ fun `PartialGuild serialization`() = runTest {
val guild = Json.decodeFromString(DiscordPartialGuild.serializer(), file("partialguild"))
with(guild) {
diff --git a/common/src/test/kotlin/json/InteractionTest.kt b/common/src/commonTest/kotlin/json/InteractionTest.kt
similarity index 83%
rename from common/src/test/kotlin/json/InteractionTest.kt
rename to common/src/commonTest/kotlin/json/InteractionTest.kt
index c962e75d18a..1f27899a664 100644
--- a/common/src/test/kotlin/json/InteractionTest.kt
+++ b/common/src/commonTest/kotlin/json/InteractionTest.kt
@@ -1,14 +1,15 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.*
import dev.kord.common.entity.optional.orEmpty
+import dev.kord.common.readFile
+import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
+import kotlin.test.assertIs
-private fun file(name: String): String {
- val loader = InteractionTest::class.java.classLoader
- return loader.getResource("json/interaction/$name.json")!!.readText()
-}
+private suspend fun file(name: String): String = readFile("interaction", name)
class InteractionTest {
@@ -17,7 +18,8 @@ class InteractionTest {
}
@Test
- fun `group command can be deserialized`() {
+ @JsName("test1")
+ fun `group command can be deserialized`() = runTest {
val text = file("groupsubcommand")
val interaction = json.decodeFromString(DiscordInteraction.serializer(), text)
@@ -31,8 +33,7 @@ class InteractionTest {
data.name shouldBe "testsubcommands"
data.id shouldBe "792107855418490901"
val group = data.options.orEmpty().first()
- assert(group is CommandGroup)
- group as CommandGroup
+ assertIs(group)
group.name shouldBe "group"
val subCommand = group.options.orEmpty().first()
subCommand.name shouldBe "groupsubcommand"
@@ -45,7 +46,8 @@ class InteractionTest {
}
@Test
- fun `subcommand can be deserialized`() {
+ @JsName("test2")
+ fun `subcommand can be deserialized`() = runTest {
val text = file("subcommand")
val interaction = json.decodeFromString(DiscordInteraction.serializer(), text)
@@ -59,8 +61,7 @@ class InteractionTest {
data.name shouldBe "testsubcommands"
data.id shouldBe "792107855418490901"
val subCommand = data.options.orEmpty().first()
- assert(subCommand is SubCommand)
- subCommand as SubCommand
+ assertIs(subCommand)
subCommand.name shouldBe "subcommand"
val arg = subCommand.options.orEmpty().first()
arg.type shouldBe ApplicationCommandOptionType.Integer
@@ -72,7 +73,8 @@ class InteractionTest {
@Test
- fun `root can be deserialized`() {
+ @JsName("test3")
+ fun `root can be deserialized`() = runTest {
val text = file("rootcommand")
val interaction = json.decodeFromString(DiscordInteraction.serializer(), text)
@@ -86,8 +88,7 @@ class InteractionTest {
data.name shouldBe "testsubcommands"
data.id shouldBe "792107855418490901"
val arg = data.options.orEmpty().first()
- assert(arg is CommandArgument<*>)
- arg as CommandArgument<*>
+ assertIs>(arg)
arg.type shouldBe ApplicationCommandOptionType.Integer
arg.name shouldBe "testint"
arg.value shouldBe 1L
@@ -96,7 +97,8 @@ class InteractionTest {
}
@Test
- fun `slash command permissions can be serialized`() {
+ @JsName("test4")
+ fun `slash command permissions can be serialized`() = runTest {
val text = file("slash_command_permissions_update")
val interaction = json.decodeFromString(DiscordGuildApplicationCommandPermissions.serializer(), text)
@@ -115,14 +117,15 @@ class InteractionTest {
}
@Test
- fun `select menu can be deserialized`() {
+ @JsName("test5")
+ fun `select menu can be deserialized`() = runTest {
val text = file("selectmenu")
val interaction = json.decodeFromString(DiscordInteraction.serializer(), text)
with(interaction) {
applicationId shouldBe "845027738276462632"
channelId shouldBe "772908445358620702"
- with(data){
+ with(data) {
componentType shouldBe ComponentType.StringSelect
customId shouldBe "class_select_1"
values shouldBe listOf("mage", "rogue")
diff --git a/common/src/test/kotlin/json/MessageTest.kt b/common/src/commonTest/kotlin/json/MessageTest.kt
similarity index 89%
rename from common/src/test/kotlin/json/MessageTest.kt
rename to common/src/commonTest/kotlin/json/MessageTest.kt
index 5f6bfabd3d1..5fea99400e9 100644
--- a/common/src/test/kotlin/json/MessageTest.kt
+++ b/common/src/commonTest/kotlin/json/MessageTest.kt
@@ -1,20 +1,20 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.*
+import dev.kord.common.readFile
+import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
-
-private fun file(name: String): String {
- val loader = ChannelTest::class.java.classLoader
- return loader.getResource("json/message/$name.json")!!.readText()
-}
+private suspend fun file(name: String): String = readFile("message", name)
class MessageTest {
@Test
- fun `Message serialization`() {
+ @JsName("test1")
+ fun `Message serialization`() = runTest {
val message: DiscordMessage = Json.decodeFromString(DiscordMessage.serializer(), file("message"))
with(message) {
@@ -51,7 +51,8 @@ class MessageTest {
}
@Test
- fun `User serialization`() {
+ @JsName("test2")
+ fun `User serialization`() = runTest {
val message = Json.decodeFromString(DiscordMessage.serializer(), file("crossposted"))
with(message) {
diff --git a/common/src/test/kotlin/json/PermissionsTest.kt b/common/src/commonTest/kotlin/json/PermissionsTest.kt
similarity index 80%
rename from common/src/test/kotlin/json/PermissionsTest.kt
rename to common/src/commonTest/kotlin/json/PermissionsTest.kt
index 63a7c8405d3..e1dc29845dc 100644
--- a/common/src/test/kotlin/json/PermissionsTest.kt
+++ b/common/src/commonTest/kotlin/json/PermissionsTest.kt
@@ -1,16 +1,18 @@
-package json
+package dev.kord.common.json
import dev.kord.common.DiscordBitSet
-import dev.kord.common.EmptyBitSet
import dev.kord.common.entity.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
+import kotlin.test.assertEquals
class PermissionsTest {
@Test
+ @JsName("test1")
fun `adding permissions together does not swallow the universe`() {
Permission.values.fold(Permissions(DiscordBitSet(0))) { acc, permission ->
acc + permission
@@ -18,11 +20,13 @@ class PermissionsTest {
}
@Test
+ @JsName("test2")
fun `Permission All does not swallow the universe`() {
Permission.All //oh yeah, this is worthy of a test
}
@Test
+ @JsName("test3")
fun `permissions serialization test`() {
val expected = buildJsonObject {
put("id", "12323232")
@@ -35,10 +39,11 @@ class PermissionsTest {
put("mentionable", false)
}
val actual = Json.decodeFromJsonElement(DiscordRole.serializer(), expected)
- assert(actual.permissions.code.value == "123456789876543000000000000") {
+ assertEquals(
+ "123456789876543000000000000", actual.permissions.code.value,
"1234567898765430000000000 was expected but ${actual.permissions.code.value} was found"
- }
+ )
}
-}
\ No newline at end of file
+}
diff --git a/common/src/test/kotlin/json/UserTest.kt b/common/src/commonTest/kotlin/json/UserTest.kt
similarity index 70%
rename from common/src/test/kotlin/json/UserTest.kt
rename to common/src/commonTest/kotlin/json/UserTest.kt
index f25a129cc10..a5c9c3e2d82 100644
--- a/common/src/test/kotlin/json/UserTest.kt
+++ b/common/src/commonTest/kotlin/json/UserTest.kt
@@ -1,19 +1,20 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.DiscordUser
import dev.kord.common.entity.UserFlags
+import dev.kord.common.readFile
+import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
-private fun file(name: String): String {
- val loader = ChannelTest::class.java.classLoader
- return loader.getResource("json/user/$name.json").readText()
-}
+private suspend fun file(name: String): String = readFile("user", name)
class UserTest {
@Test
- fun `User serialization`() {
+ @JsName("test1")
+ fun `User serialization`() = runTest{
val user = Json.decodeFromString(DiscordUser.serializer(), file("user"))
with(user) {
diff --git a/common/src/test/kotlin/json/Util.kt b/common/src/commonTest/kotlin/json/Util.kt
similarity index 56%
rename from common/src/test/kotlin/json/Util.kt
rename to common/src/commonTest/kotlin/json/Util.kt
index 8f952f310b8..00d62b3c2aa 100644
--- a/common/src/test/kotlin/json/Util.kt
+++ b/common/src/commonTest/kotlin/json/Util.kt
@@ -1,69 +1,69 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.*
import dev.kord.common.entity.optional.*
-import org.junit.jupiter.api.Assertions
+import kotlin.test.assertEquals
infix fun String?.shouldBe(value: String?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun Optional.shouldBe(value: String?){
- Assertions.assertEquals(value, this.value)
+ assertEquals(value, this.value)
}
infix fun OptionalBoolean.shouldBe(value: Boolean){
- Assertions.assertEquals(value, this.value)
+ assertEquals(value, this.value)
}
infix fun Snowflake?.shouldBe(value: String?){
- Assertions.assertEquals(value, this?.toString())
+ assertEquals(value, this?.toString())
}
infix fun OptionalSnowflake?.shouldBe(value: String?){
- Assertions.assertEquals(value, this?.value?.toString())
+ assertEquals(value, this?.value?.toString())
}
infix fun VerificationLevel?.shouldBe(value: VerificationLevel?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun DefaultMessageNotificationLevel?.shouldBe(value: DefaultMessageNotificationLevel?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun MFALevel?.shouldBe(value: MFALevel?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun ExplicitContentFilter?.shouldBe(value: ExplicitContentFilter?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun PremiumTier?.shouldBe(value: PremiumTier?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun SystemChannelFlags?.shouldBe(value: SystemChannelFlags?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun List?.shouldBe(value: List?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun Int?.shouldBe(value: Int?){
- Assertions.assertEquals(value, this)
+ assertEquals(value, this)
}
infix fun OptionalInt?.shouldBe(value: Int?){
- Assertions.assertEquals(value, this.value)
+ assertEquals(value, this.value)
}
infix fun Optional.shouldBe(that: T?) {
- Assertions.assertEquals(that, this.value)
+ assertEquals(that, this.value)
}
infix fun T.shouldBe(that: T) {
- Assertions.assertEquals(that, this)
+ assertEquals(that, this)
}
diff --git a/common/src/test/kotlin/json/VoiceStateTest.kt b/common/src/commonTest/kotlin/json/VoiceStateTest.kt
similarity index 72%
rename from common/src/test/kotlin/json/VoiceStateTest.kt
rename to common/src/commonTest/kotlin/json/VoiceStateTest.kt
index 0aa78e4062b..1d73de02faf 100644
--- a/common/src/test/kotlin/json/VoiceStateTest.kt
+++ b/common/src/commonTest/kotlin/json/VoiceStateTest.kt
@@ -1,19 +1,20 @@
-package json
+package dev.kord.common.json
import dev.kord.common.entity.DiscordVoiceState
+import dev.kord.common.readFile
+import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
+import kotlin.js.JsName
+import kotlin.test.Test
-private fun file(name: String): String {
- val loader = ChannelTest::class.java.classLoader
- return loader.getResource("json/voice/$name.json")!!.readText()
-}
+private suspend fun file(name: String): String = readFile("voice", name)
class VoiceStateTest {
@Test
- fun `VoiceState serialization`() {
+ @JsName("test1")
+ fun `VoiceState serialization`() = runTest {
val state = Json.decodeFromString(DiscordVoiceState.serializer(), file("voicestate"))
with(state) {
diff --git a/common/src/test/kotlin/ratelimit/AbstractIntervalRateLimiterTest.kt b/common/src/commonTest/kotlin/ratelimit/AbstractIntervalRateLimiterTest.kt
similarity index 94%
rename from common/src/test/kotlin/ratelimit/AbstractIntervalRateLimiterTest.kt
rename to common/src/commonTest/kotlin/ratelimit/AbstractIntervalRateLimiterTest.kt
index 5abebfbbb03..2a47a2cf732 100644
--- a/common/src/test/kotlin/ratelimit/AbstractIntervalRateLimiterTest.kt
+++ b/common/src/commonTest/kotlin/ratelimit/AbstractIntervalRateLimiterTest.kt
@@ -1,8 +1,8 @@
-package ratelimit
+package dev.kord.common.ratelimit
-import dev.kord.common.ratelimit.IntervalRateLimiter
import kotlinx.coroutines.test.currentTime
import kotlinx.coroutines.test.runTest
+import kotlin.js.JsName
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -27,6 +27,7 @@ abstract class AbstractIntervalRateLimiterTest {
}
@Test
+ @JsName("test1")
fun `an interval rate limiter does not accept illegal arguments`() {
fun assertIAE(limit: Int, interval: Duration) {
@@ -41,6 +42,7 @@ abstract class AbstractIntervalRateLimiterTest {
}
@Test
+ @JsName("test2")
fun `an interval rate limiter does not ratelimit when under limit`() = runTest {
repeat(limit) { rateLimiter.consume() }
@@ -48,6 +50,7 @@ abstract class AbstractIntervalRateLimiterTest {
}
@Test
+ @JsName("test3")
fun `an interval rate limiter does ratelimit when over limit`() = runTest {
repeat(limit + 1) { rateLimiter.consume() }
diff --git a/common/src/test/kotlin/ratelimit/ClockIntervalRateLimiterTest.kt b/common/src/commonTest/kotlin/ratelimit/ClockIntervalRateLimiterTest.kt
similarity index 70%
rename from common/src/test/kotlin/ratelimit/ClockIntervalRateLimiterTest.kt
rename to common/src/commonTest/kotlin/ratelimit/ClockIntervalRateLimiterTest.kt
index c6a3533ca10..f88681bc4f1 100644
--- a/common/src/test/kotlin/ratelimit/ClockIntervalRateLimiterTest.kt
+++ b/common/src/commonTest/kotlin/ratelimit/ClockIntervalRateLimiterTest.kt
@@ -1,8 +1,6 @@
-package ratelimit
+package dev.kord.common.ratelimit
-import dev.kord.common.ratelimit.ClockIntervalRateLimiter
-import dev.kord.common.ratelimit.IntervalRateLimiter
-import fixed
+import dev.kord.common.fixed
import kotlinx.datetime.Clock
import kotlin.time.Duration
diff --git a/common/src/test/kotlin/ratelimit/TimeSourceIntervalRateLimiterTest.kt b/common/src/commonTest/kotlin/ratelimit/TimeSourceIntervalRateLimiterTest.kt
similarity index 72%
rename from common/src/test/kotlin/ratelimit/TimeSourceIntervalRateLimiterTest.kt
rename to common/src/commonTest/kotlin/ratelimit/TimeSourceIntervalRateLimiterTest.kt
index 694196d78a6..2f519e8d210 100644
--- a/common/src/test/kotlin/ratelimit/TimeSourceIntervalRateLimiterTest.kt
+++ b/common/src/commonTest/kotlin/ratelimit/TimeSourceIntervalRateLimiterTest.kt
@@ -1,7 +1,5 @@
-package ratelimit
+package dev.kord.common.ratelimit
-import dev.kord.common.ratelimit.IntervalRateLimiter
-import dev.kord.common.ratelimit.TimeSourceIntervalRateLimiter
import kotlin.time.Duration
import kotlin.time.TestTimeSource
diff --git a/common/src/test/kotlin/serialization/DurationSerializersTests.kt b/common/src/commonTest/kotlin/serialization/DurationSerializersTests.kt
similarity index 94%
rename from common/src/test/kotlin/serialization/DurationSerializersTests.kt
rename to common/src/commonTest/kotlin/serialization/DurationSerializersTests.kt
index be071f4a8db..5a5e5761bdb 100644
--- a/common/src/test/kotlin/serialization/DurationSerializersTests.kt
+++ b/common/src/commonTest/kotlin/serialization/DurationSerializersTests.kt
@@ -1,8 +1,8 @@
-package serialization
+package dev.kord.common.serialization
-import dev.kord.common.serialization.*
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
+import kotlin.js.JsName
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
@@ -43,17 +43,20 @@ abstract class DurationSerializerTest(
@Test
+ @JsName("test1")
fun `zero Duration can be serialized`() {
assertEquals(expected = "0", actual = serialize(Duration.ZERO))
}
@Test
+ @JsName("test2")
fun `zero Duration can be deserialized`() {
assertEquals(expected = Duration.ZERO, actual = deserialize("0"))
}
@Test
+ @JsName("test3")
fun `infinite Durations cannot be serialized`() {
assertFailsWith { serialize(Duration.INFINITE) }
assertFailsWith { serialize(-Duration.INFINITE) }
@@ -61,38 +64,45 @@ abstract class DurationSerializerTest(
@Test
+ @JsName("test4")
fun `positive Duration can be serialized`() {
assertEquals(expected = json, actual = serialize(duration))
}
@Test
+ @JsName("test5")
fun `positive Duration can be rounded and serialized`() {
assertEquals(expected = json, actual = serialize(durationToRound))
}
@Test
+ @JsName("test6")
fun `positive Duration can be deserialized`() {
assertEquals(expected = duration, actual = deserialize(json))
}
@Test
+ @JsName("test7")
fun `negative Duration can be serialized`() {
assertEquals(expected = "-$json", actual = serialize(-duration))
}
@Test
+ @JsName("test8")
fun `negative Duration can be rounded and serialized`() {
assertEquals(expected = "-$json", actual = serialize(-durationToRound))
}
@Test
+ @JsName("test9")
fun `negative Duration can be deserialized`() {
assertEquals(expected = -duration, actual = deserialize("-$json"))
}
@Test
+ @JsName("test10")
fun `positive Duration that would overflow in target unit cannot be serialized`() {
if (durationThatWouldOverflowInTargetUnit != null) assertFailsWith {
serialize(durationThatWouldOverflowInTargetUnit)
@@ -100,6 +110,7 @@ abstract class DurationSerializerTest(
}
@Test
+ @JsName("test11")
fun `negative Duration that would overflow in target unit cannot be serialized`() {
if (durationThatWouldOverflowInTargetUnit != null) assertFailsWith {
serialize(-durationThatWouldOverflowInTargetUnit)
@@ -108,11 +119,13 @@ abstract class DurationSerializerTest(
@Test
+ @JsName("test12")
fun `large positive Duration gets deserialized as Infinity`() {
if (largeJson != null) assertEquals(expected = Duration.INFINITE, deserialize(largeJson))
}
@Test
+ @JsName("test13")
fun `large negative Duration gets deserialized as -Infinity`() {
if (largeJson != null) assertEquals(expected = -Duration.INFINITE, deserialize("-$largeJson"))
}
diff --git a/common/src/test/kotlin/serialization/InstantSerializersTests.kt b/common/src/commonTest/kotlin/serialization/InstantSerializersTests.kt
similarity index 89%
rename from common/src/test/kotlin/serialization/InstantSerializersTests.kt
rename to common/src/commonTest/kotlin/serialization/InstantSerializersTests.kt
index ebbe87a3abf..70ccbd59d53 100644
--- a/common/src/test/kotlin/serialization/InstantSerializersTests.kt
+++ b/common/src/commonTest/kotlin/serialization/InstantSerializersTests.kt
@@ -1,11 +1,11 @@
-package serialization
+package dev.kord.common.serialization
-import dev.kord.common.serialization.InstantInEpochMillisecondsSerializer
-import dev.kord.common.serialization.InstantInEpochSecondsSerializer
+import dev.kord.test.IgnoreOnJs
import kotlinx.datetime.Instant
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
+import kotlin.js.JsName
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
@@ -29,39 +29,46 @@ abstract class InstantSerializerTest(
@Test
+ @JsName("test1")
fun `epoch Instant can be serialized`() {
assertEquals(expected = "0", actual = serialize(EPOCH))
}
@Test
+ @JsName("test2")
fun `epoch Instant can be deserialized`() {
assertEquals(expected = EPOCH, actual = deserialize("0"))
}
@Test
+ @JsName("test3")
fun `future Instant can be serialized`() {
assertEquals(expected = json, actual = serialize(instant))
}
@Test
+ @JsName("test4")
fun `future Instant can be deserialized`() {
assertEquals(expected = instant, actual = deserialize(json))
}
@Test
+ @JsName("test5")
fun `past Instant can be serialized`() {
assertEquals(expected = "-$json", actual = serialize(mirroredInstant))
}
@Test
+ @JsName("test6")
fun `past Instant can be deserialized`() {
assertEquals(expected = mirroredInstant, actual = deserialize("-$json"))
}
}
+@IgnoreOnJs // currently can't pass
class InstantInEpochMillisecondsSerializerTest : InstantSerializerTest(
json = "796514689159",
instant = Instant.fromEpochMilliseconds(796514689159),
@@ -71,6 +78,7 @@ class InstantInEpochMillisecondsSerializerTest : InstantSerializerTest(
private val pastInstantExactlyAtLimit = Instant.fromEpochMilliseconds(Long.MIN_VALUE)
@Test
+ @JsName("test7")
fun `future Instant under limit can be serialized`() {
assertEquals(
expected = (Long.MAX_VALUE - 1).toString(),
@@ -79,6 +87,7 @@ class InstantInEpochMillisecondsSerializerTest : InstantSerializerTest(
}
@Test
+ @JsName("test8")
fun `past Instant under limit can be serialized`() {
assertEquals(
expected = Long.MIN_VALUE.toString(),
@@ -88,22 +97,26 @@ class InstantInEpochMillisecondsSerializerTest : InstantSerializerTest(
@Test
+ @JsName("test9")
fun `future Instant exactly at limit can be serialized`() {
assertEquals(expected = Long.MAX_VALUE.toString(), actual = serialize(futureInstantExactlyAtLimit))
}
@Test
+ @JsName("test10")
fun `past Instant exactly at limit can be serialized`() {
assertEquals(expected = Long.MIN_VALUE.toString(), actual = serialize(pastInstantExactlyAtLimit))
}
@Test
+ @JsName("test11")
fun `future Instant over limit cannot be serialized`() {
assertFailsWith { serialize(futureInstantExactlyAtLimit + 1.nanoseconds) }
}
@Test
+ @JsName("test12")
fun `past Instant over limit cannot be serialized`() {
assertFailsWith { serialize(pastInstantExactlyAtLimit - 1.nanoseconds) }
}
diff --git a/common/src/test/resources/json/channel/channelcategory.json b/common/src/commonTest/resources/json/channel/channelcategory.json
similarity index 100%
rename from common/src/test/resources/json/channel/channelcategory.json
rename to common/src/commonTest/resources/json/channel/channelcategory.json
diff --git a/common/src/test/resources/json/channel/dmchannel.json b/common/src/commonTest/resources/json/channel/dmchannel.json
similarity index 100%
rename from common/src/test/resources/json/channel/dmchannel.json
rename to common/src/commonTest/resources/json/channel/dmchannel.json
diff --git a/common/src/test/resources/json/channel/groupdmchannel.json b/common/src/commonTest/resources/json/channel/groupdmchannel.json
similarity index 100%
rename from common/src/test/resources/json/channel/groupdmchannel.json
rename to common/src/commonTest/resources/json/channel/groupdmchannel.json
diff --git a/common/src/test/resources/json/channel/guildnewschannel.json b/common/src/commonTest/resources/json/channel/guildnewschannel.json
similarity index 100%
rename from common/src/test/resources/json/channel/guildnewschannel.json
rename to common/src/commonTest/resources/json/channel/guildnewschannel.json
diff --git a/common/src/test/resources/json/channel/guildtextchannel.json b/common/src/commonTest/resources/json/channel/guildtextchannel.json
similarity index 100%
rename from common/src/test/resources/json/channel/guildtextchannel.json
rename to common/src/commonTest/resources/json/channel/guildtextchannel.json
diff --git a/common/src/test/resources/json/channel/guildvoicechannel.json b/common/src/commonTest/resources/json/channel/guildvoicechannel.json
similarity index 100%
rename from common/src/test/resources/json/channel/guildvoicechannel.json
rename to common/src/commonTest/resources/json/channel/guildvoicechannel.json
diff --git a/common/src/test/resources/json/emoji/customemoji.json b/common/src/commonTest/resources/json/emoji/customemoji.json
similarity index 100%
rename from common/src/test/resources/json/emoji/customemoji.json
rename to common/src/commonTest/resources/json/emoji/customemoji.json
diff --git a/common/src/test/resources/json/emoji/emoji.json b/common/src/commonTest/resources/json/emoji/emoji.json
similarity index 100%
rename from common/src/test/resources/json/emoji/emoji.json
rename to common/src/commonTest/resources/json/emoji/emoji.json
diff --git a/common/src/test/resources/json/emoji/standardemoji.json b/common/src/commonTest/resources/json/emoji/standardemoji.json
similarity index 100%
rename from common/src/test/resources/json/emoji/standardemoji.json
rename to common/src/commonTest/resources/json/emoji/standardemoji.json
diff --git a/common/src/test/resources/json/guild/guild.json b/common/src/commonTest/resources/json/guild/guild.json
similarity index 100%
rename from common/src/test/resources/json/guild/guild.json
rename to common/src/commonTest/resources/json/guild/guild.json
diff --git a/common/src/test/resources/json/guild/guildmember.json b/common/src/commonTest/resources/json/guild/guildmember.json
similarity index 100%
rename from common/src/test/resources/json/guild/guildmember.json
rename to common/src/commonTest/resources/json/guild/guildmember.json
diff --git a/common/src/test/resources/json/guild/partialguild.json b/common/src/commonTest/resources/json/guild/partialguild.json
similarity index 100%
rename from common/src/test/resources/json/guild/partialguild.json
rename to common/src/commonTest/resources/json/guild/partialguild.json
diff --git a/common/src/test/resources/json/guild/unavailableguild.json b/common/src/commonTest/resources/json/guild/unavailableguild.json
similarity index 100%
rename from common/src/test/resources/json/guild/unavailableguild.json
rename to common/src/commonTest/resources/json/guild/unavailableguild.json
diff --git a/common/src/test/resources/json/interaction/groupsubcommand.json b/common/src/commonTest/resources/json/interaction/groupsubcommand.json
similarity index 100%
rename from common/src/test/resources/json/interaction/groupsubcommand.json
rename to common/src/commonTest/resources/json/interaction/groupsubcommand.json
diff --git a/common/src/test/resources/json/interaction/rootcommand.json b/common/src/commonTest/resources/json/interaction/rootcommand.json
similarity index 100%
rename from common/src/test/resources/json/interaction/rootcommand.json
rename to common/src/commonTest/resources/json/interaction/rootcommand.json
diff --git a/common/src/test/resources/json/interaction/selectmenu.json b/common/src/commonTest/resources/json/interaction/selectmenu.json
similarity index 100%
rename from common/src/test/resources/json/interaction/selectmenu.json
rename to common/src/commonTest/resources/json/interaction/selectmenu.json
diff --git a/common/src/test/resources/json/interaction/slash_command_permissions_update.json b/common/src/commonTest/resources/json/interaction/slash_command_permissions_update.json
similarity index 100%
rename from common/src/test/resources/json/interaction/slash_command_permissions_update.json
rename to common/src/commonTest/resources/json/interaction/slash_command_permissions_update.json
diff --git a/common/src/test/resources/json/interaction/subcommand.json b/common/src/commonTest/resources/json/interaction/subcommand.json
similarity index 100%
rename from common/src/test/resources/json/interaction/subcommand.json
rename to common/src/commonTest/resources/json/interaction/subcommand.json
diff --git a/common/src/test/resources/json/message/crossposted.json b/common/src/commonTest/resources/json/message/crossposted.json
similarity index 100%
rename from common/src/test/resources/json/message/crossposted.json
rename to common/src/commonTest/resources/json/message/crossposted.json
diff --git a/common/src/test/resources/json/message/message.json b/common/src/commonTest/resources/json/message/message.json
similarity index 100%
rename from common/src/test/resources/json/message/message.json
rename to common/src/commonTest/resources/json/message/message.json
diff --git a/common/src/test/resources/json/user/user.json b/common/src/commonTest/resources/json/user/user.json
similarity index 100%
rename from common/src/test/resources/json/user/user.json
rename to common/src/commonTest/resources/json/user/user.json
diff --git a/common/src/test/resources/json/voice/voicestate.json b/common/src/commonTest/resources/json/voice/voicestate.json
similarity index 100%
rename from common/src/test/resources/json/voice/voicestate.json
rename to common/src/commonTest/resources/json/voice/voicestate.json
diff --git a/common/src/jsMain/kotlin/http/HttpEngine.kt b/common/src/jsMain/kotlin/http/HttpEngine.kt
new file mode 100644
index 00000000000..b3d5dcea53f
--- /dev/null
+++ b/common/src/jsMain/kotlin/http/HttpEngine.kt
@@ -0,0 +1,8 @@
+package dev.kord.common.http
+
+import dev.kord.common.annotation.KordInternal
+import io.ktor.client.engine.js.*
+
+/** @suppress */
+@KordInternal
+public actual typealias HttpEngine = Js
diff --git a/common/src/jvmMain/kotlin/Color.kt b/common/src/jvmMain/kotlin/Color.kt
new file mode 100644
index 00000000000..228ac673f2d
--- /dev/null
+++ b/common/src/jvmMain/kotlin/Color.kt
@@ -0,0 +1,3 @@
+package dev.kord.common
+
+public val java.awt.Color.kColor: Color get() = Color(rgb)
diff --git a/common/src/jvmMain/kotlin/ConcurrentHashMap.kt b/common/src/jvmMain/kotlin/ConcurrentHashMap.kt
new file mode 100644
index 00000000000..4fb4ddeb736
--- /dev/null
+++ b/common/src/jvmMain/kotlin/ConcurrentHashMap.kt
@@ -0,0 +1,7 @@
+package dev.kord.common
+
+import dev.kord.common.annotation.KordInternal
+
+/** @suppress */
+@KordInternal
+public actual typealias ConcurrentHashMap = java.util.concurrent.ConcurrentHashMap
diff --git a/common/src/jvmMain/kotlin/DiscordBitSetJvm.kt b/common/src/jvmMain/kotlin/DiscordBitSetJvm.kt
new file mode 100644
index 00000000000..591cae34158
--- /dev/null
+++ b/common/src/jvmMain/kotlin/DiscordBitSetJvm.kt
@@ -0,0 +1,13 @@
+package dev.kord.common
+
+import java.math.BigInteger
+import java.nio.ByteBuffer
+
+internal actual fun formatIntegerFromLittleEndianLongArray(data: LongArray): String {
+ // need to convert from little-endian data to big-endian expected by BigInteger
+ val buffer = ByteBuffer.allocate(data.size * Long.SIZE_BYTES)
+ buffer.asLongBuffer().put(data.reversedArray())
+ return BigInteger(buffer.array()).toString()
+}
+
+internal actual fun parseIntegerToBigEndianByteArray(value: String): ByteArray = BigInteger(value).toByteArray()
diff --git a/common/src/jvmMain/kotlin/Locale.kt b/common/src/jvmMain/kotlin/Locale.kt
new file mode 100644
index 00000000000..ee1b63c35c8
--- /dev/null
+++ b/common/src/jvmMain/kotlin/Locale.kt
@@ -0,0 +1,11 @@
+package dev.kord.common
+
+/**
+ * Converts this [dev.kord.common.Locale] into a [java.util.Locale].
+ */
+public fun Locale.asJavaLocale(): java.util.Locale = java.util.Locale(language, country ?: "")
+
+/**
+ * Converts this [java.util.Locale] into a [dev.kord.common.Locale].
+ */
+public val java.util.Locale.kLocale: Locale get() = Locale(language, country.ifBlank { null })
diff --git a/common/src/jvmMain/kotlin/http/HttpEngine.kt b/common/src/jvmMain/kotlin/http/HttpEngine.kt
new file mode 100644
index 00000000000..a201c8d46c7
--- /dev/null
+++ b/common/src/jvmMain/kotlin/http/HttpEngine.kt
@@ -0,0 +1,9 @@
+package dev.kord.common.http
+
+import dev.kord.common.annotation.KordInternal
+import io.ktor.client.engine.*
+import io.ktor.client.engine.cio.*
+
+/** @suppress */
+@KordInternal
+public actual object HttpEngine : HttpClientEngineFactory by CIO
diff --git a/common/src/jvmTest/kotlin/ColorTestsJvm.kt b/common/src/jvmTest/kotlin/ColorTestsJvm.kt
new file mode 100644
index 00000000000..c5e15b31c54
--- /dev/null
+++ b/common/src/jvmTest/kotlin/ColorTestsJvm.kt
@@ -0,0 +1,16 @@
+package dev.kord.common
+
+import kotlin.test.assertEquals
+
+import kotlin.test.Test
+
+class ColorTestsJvm {
+ @Test
+ fun `java to kColor conversion`() {
+ val color = java.awt.Color.decode("#DBD0B4").kColor
+
+ assertEquals(219, color.red)
+ assertEquals(208, color.green)
+ assertEquals(180, color.blue)
+ }
+}
diff --git a/common/src/jvmTest/kotlin/entity/SnowflakeTestJvm.kt b/common/src/jvmTest/kotlin/entity/SnowflakeTestJvm.kt
new file mode 100644
index 00000000000..604c0a72d55
--- /dev/null
+++ b/common/src/jvmTest/kotlin/entity/SnowflakeTestJvm.kt
@@ -0,0 +1,15 @@
+package dev.kord.common.entity
+
+import org.junit.jupiter.api.Test
+import kotlin.test.assertEquals
+
+class SnowflakeTestJvm {
+ @Test
+ fun `Snowflake's natural order works with SortedSets`() {
+ val a = Snowflake(0b0_00000_00000_000000000000_u)
+ val b = Snowflake(0b0_00000_00000_000000000001_u)
+ val c = Snowflake(0b1_00000_00000_000000000000_u)
+ assertEquals(2, sortedSetOf(a, b).size)
+ assertEquals(2, sortedSetOf(a, c).size)
+ }
+}
diff --git a/common/src/nonJvmMain/kotlin/ConcurrentHashMap.kt b/common/src/nonJvmMain/kotlin/ConcurrentHashMap.kt
new file mode 100644
index 00000000000..be329858c82
--- /dev/null
+++ b/common/src/nonJvmMain/kotlin/ConcurrentHashMap.kt
@@ -0,0 +1,8 @@
+package dev.kord.common
+
+import co.touchlab.stately.collections.ConcurrentMutableMap
+import dev.kord.common.annotation.KordInternal
+
+/** @suppress */
+@KordInternal
+public actual typealias ConcurrentHashMap = ConcurrentMutableMap
diff --git a/common/src/nonJvmMain/kotlin/DiscordBitSet.kt b/common/src/nonJvmMain/kotlin/DiscordBitSet.kt
new file mode 100644
index 00000000000..3c0e5f121a3
--- /dev/null
+++ b/common/src/nonJvmMain/kotlin/DiscordBitSet.kt
@@ -0,0 +1,15 @@
+package dev.kord.common
+
+import com.ionspin.kotlin.bignum.integer.BigInteger
+import com.ionspin.kotlin.bignum.integer.Sign
+import io.ktor.utils.io.core.*
+
+internal actual fun formatIntegerFromLittleEndianLongArray(data: LongArray) =
+ withBuffer(data.size * Long.SIZE_BYTES) {
+ // need to convert from little-endian data to big-endian expected by BigInteger
+ writeFully(data.reversedArray())
+ BigInteger.fromByteArray(readBytes(), Sign.POSITIVE).toString()
+ }
+
+internal actual fun parseIntegerToBigEndianByteArray(value: String): ByteArray =
+ BigInteger.parseString(value).toByteArray()
diff --git a/core-voice/README.md b/core-voice/README.md
new file mode 100644
index 00000000000..199acba8f34
--- /dev/null
+++ b/core-voice/README.md
@@ -0,0 +1,4 @@
+# core-voice
+
+This Module adds extensions to [core](../core) for [kord-voice](../voice). Please read the [voice](../voice)
+documentation for more information
diff --git a/core-voice/api/core-voice.api b/core-voice/api/core-voice.api
new file mode 100644
index 00000000000..fde1322aa8f
--- /dev/null
+++ b/core-voice/api/core-voice.api
@@ -0,0 +1,4 @@
+public final class dev/kord/core/behavior/channel/VoiceBaseVoiceChannelBehavior {
+ public static final fun connect (Ldev/kord/core/behavior/channel/BaseVoiceChannelBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
+}
+
diff --git a/core-voice/build.gradle.kts b/core-voice/build.gradle.kts
new file mode 100644
index 00000000000..356fca4c82b
--- /dev/null
+++ b/core-voice/build.gradle.kts
@@ -0,0 +1,9 @@
+plugins {
+ `kord-module`
+ `kord-publishing`
+}
+
+dependencies {
+ api(projects.core)
+ api(projects.voice)
+}
diff --git a/core/src/voice/kotlin/dev/kord/core/behavior/channel/BaseVoiceChannelBehavior.kt b/core-voice/src/main/kotlin/BaseVoiceChannelBehaviorExtensions.kt
similarity index 90%
rename from core/src/voice/kotlin/dev/kord/core/behavior/channel/BaseVoiceChannelBehavior.kt
rename to core-voice/src/main/kotlin/BaseVoiceChannelBehaviorExtensions.kt
index b5c920d7f0e..c6da181516d 100644
--- a/core/src/voice/kotlin/dev/kord/core/behavior/channel/BaseVoiceChannelBehavior.kt
+++ b/core-voice/src/main/kotlin/BaseVoiceChannelBehaviorExtensions.kt
@@ -17,7 +17,7 @@ import dev.kord.voice.VoiceConnectionBuilder
* @return a [VoiceConnection] representing the connection to this [VoiceConnection].
*/
@KordVoice
-suspend fun BaseVoiceChannelBehavior.connect(builder: VoiceConnectionBuilder.() -> Unit): VoiceConnection {
+public suspend fun BaseVoiceChannelBehavior.connect(builder: VoiceConnectionBuilder.() -> Unit): VoiceConnection {
val voiceConnection = VoiceConnection(
guild.gateway ?: GatewayNotFoundException.voiceConnectionGatewayNotFound(guildId),
kord.selfId,
diff --git a/core/README.md b/core/README.md
index 38e5988f516..01d53ad43a6 100644
--- a/core/README.md
+++ b/core/README.md
@@ -99,7 +99,7 @@ dependencies {
dev.kord
- kord-core
+ kord-core-jvm
{version}
```
diff --git a/core/api/core.api b/core/api/core.api
index 3920b33bd7e..3c38ed0f8ef 100644
--- a/core/api/core.api
+++ b/core/api/core.api
@@ -2085,15 +2085,14 @@ public final class dev/kord/core/builder/components/ButtonBuilderExtensionsKt {
public static final fun emoji (Ldev/kord/rest/builder/component/ButtonBuilder;Ldev/kord/core/entity/ReactionEmoji$Unicode;)V
}
-public final class dev/kord/core/builder/kord/KordBuilder {
- public fun (Ljava/lang/String;)V
- public final fun build (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
+public abstract class dev/kord/core/builder/kord/BaseKordBuilder {
+ public fun build (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
+ protected final fun buildBase (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun cache (Lkotlin/jvm/functions/Function2;)V
public final fun gateways (Lkotlin/jvm/functions/Function2;)V
public final fun getApplicationId ()Ldev/kord/common/entity/Snowflake;
public final fun getDefaultDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun getDefaultStrategy ()Ldev/kord/core/supplier/EntitySupplyStrategy;
- public final fun getEnableShutdownHook ()Z
public final fun getEventFlow ()Lkotlinx/coroutines/flow/MutableSharedFlow;
public final fun getGatewayEventInterceptor ()Ldev/kord/core/gateway/handler/GatewayEventInterceptor;
public final fun getHttpClient ()Lio/ktor/client/HttpClient;
@@ -2103,7 +2102,6 @@ public final class dev/kord/core/builder/kord/KordBuilder {
public final fun setApplicationId (Ldev/kord/common/entity/Snowflake;)V
public final fun setDefaultDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)V
public final fun setDefaultStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)V
- public final fun setEnableShutdownHook (Z)V
public final fun setEventFlow (Lkotlinx/coroutines/flow/MutableSharedFlow;)V
public final fun setGatewayEventInterceptor (Ldev/kord/core/gateway/handler/GatewayEventInterceptor;)V
public final fun setHttpClient (Lio/ktor/client/HttpClient;)V
@@ -2111,11 +2109,21 @@ public final class dev/kord/core/builder/kord/KordBuilder {
public final fun sharding (Lkotlin/jvm/functions/Function1;)V
}
+public final class dev/kord/core/builder/kord/KordBuilder : dev/kord/core/builder/kord/BaseKordBuilder {
+ public fun (Ljava/lang/String;)V
+ public fun build (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
+ public final fun getEnableShutdownHook ()Z
+ public final fun setEnableShutdownHook (Z)V
+}
+
public final class dev/kord/core/builder/kord/KordBuilderKt {
public static final synthetic fun invoke (Ldev/kord/gateway/DefaultGateway$Companion;Ldev/kord/core/ClientResources;Ldev/kord/gateway/retry/Retry;)Ldev/kord/gateway/DefaultGateway;
public static synthetic fun invoke$default (Ldev/kord/gateway/DefaultGateway$Companion;Ldev/kord/core/ClientResources;Ldev/kord/gateway/retry/Retry;ILjava/lang/Object;)Ldev/kord/gateway/DefaultGateway;
}
+public final class dev/kord/core/builder/kord/KordBuilderUtilKt {
+}
+
public final class dev/kord/core/builder/kord/KordProxyBuilder : dev/kord/core/builder/kord/RestOnlyBuilder {
public fun (Ldev/kord/common/entity/Snowflake;)V
public fun getApplicationId ()Ldev/kord/common/entity/Snowflake;
@@ -2185,8 +2193,6 @@ public final class dev/kord/core/cache/KordCacheBuilder {
public final fun forDescription (Ldev/kord/cache/api/data/DataDescription;Lkotlin/jvm/functions/Function2;)V
public final fun getDefaultGenerator ()Lkotlin/jvm/functions/Function2;
public final fun guilds (Lkotlin/jvm/functions/Function2;)V
- public final fun lruCache (I)Lkotlin/jvm/functions/Function2;
- public static synthetic fun lruCache$default (Ldev/kord/core/cache/KordCacheBuilder;IILjava/lang/Object;)Lkotlin/jvm/functions/Function2;
public final fun members (Lkotlin/jvm/functions/Function2;)V
public final fun messages (Lkotlin/jvm/functions/Function2;)V
public final fun none ()Lkotlin/jvm/functions/Function2;
@@ -2199,6 +2205,11 @@ public final class dev/kord/core/cache/KordCacheBuilder {
public final fun webhooks (Lkotlin/jvm/functions/Function2;)V
}
+public final class dev/kord/core/cache/KordCacheBuilderKt {
+ public static final fun lruCache (Ldev/kord/core/cache/KordCacheBuilder;I)Lkotlin/jvm/functions/Function2;
+ public static synthetic fun lruCache$default (Ldev/kord/core/cache/KordCacheBuilder;IILjava/lang/Object;)Lkotlin/jvm/functions/Function2;
+}
+
public final class dev/kord/core/cache/QueryKt {
public static final fun booleanEq (Ldev/kord/cache/api/QueryBuilder;Lkotlin/reflect/KProperty1;Ljava/lang/Boolean;)V
public static final fun idEq (Ldev/kord/cache/api/QueryBuilder;Lkotlin/reflect/KProperty1;Ldev/kord/common/entity/Snowflake;)V
@@ -6144,7 +6155,7 @@ public final class dev/kord/core/entity/Guild : dev/kord/core/behavior/GuildBeha
public final fun getOwnerId ()Ldev/kord/common/entity/Snowflake;
public final fun getOwnerOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getPermissions ()Ldev/kord/common/entity/Permissions;
- public final fun getPreferredLocale ()Ljava/util/Locale;
+ public final fun getPreferredLocale ()Ldev/kord/common/Locale;
public final fun getPremiumProgressBarEnabled ()Z
public final fun getPremiumSubscriptionCount ()Ljava/lang/Integer;
public final fun getPremiumTier ()Ldev/kord/common/entity/PremiumTier;
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index e65161ba483..58bca499628 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -1,42 +1,40 @@
plugins {
- java
- `kord-module`
- `kord-sampled-module`
+ `kord-multiplatform-module`
`kord-publishing`
}
-val voice: SourceSet by sourceSets.creating
-val voiceApi: Configuration by configurations.getting
-
-configurations {
- getByName("voiceImplementation") {
- extendsFrom(implementation.get())
+kotlin {
+ js {
+ nodejs {
+ testTask {
+ useMocha {
+ timeout = "10000" // KordEventDropTest is too slow for default 2 seconds timeout
+ }
+ }
+ }
}
-}
-
-dependencies {
- api(projects.common)
- api(projects.rest)
- api(projects.gateway)
- voiceApi(projects.core)
- voiceApi(projects.voice)
-
- api(libs.kord.cache.api)
- api(libs.kord.cache.map)
- ksp(projects.kspProcessors)
-
- samplesImplementation(libs.slf4j.simple)
-
- testImplementation(libs.bundles.test.implementation)
- testRuntimeOnly(libs.bundles.test.runtime)
+ sourceSets {
+ commonMain {
+ dependencies {
+ api(projects.common)
+ api(projects.rest)
+ api(projects.gateway)
+
+ api(libs.kord.cache.api)
+ api(libs.kord.cache.map)
+ }
+ }
+ jvmTest {
+ dependencies {
+ implementation(libs.mockk)
+ }
+ }
+ }
}
-java {
- registerFeature("voice") {
- usingSourceSet(voice)
- withJavadocJar()
- withSourcesJar()
- capability("dev.kord", "core-voice", version as String)
+tasks {
+ dokkaHtmlMultiModule {
+ enabled = false
}
}
diff --git a/core/live-tests/build.gradle.kts b/core/live-tests/build.gradle.kts
new file mode 100644
index 00000000000..86fe49a30fc
--- /dev/null
+++ b/core/live-tests/build.gradle.kts
@@ -0,0 +1,23 @@
+plugins {
+ `kord-internal-multiplatform-module`
+}
+
+kotlin {
+ sourceSets {
+ all {
+ applyKordOptIns()
+ }
+ commonTest {
+ dependencies {
+ implementation(projects.core)
+ implementation(projects.testKit)
+ }
+ }
+ }
+}
+
+tasks {
+ withType().configureEach {
+ enabled = !System.getenv("KORD_TEST_TOKEN").isNullOrBlank()
+ }
+}
diff --git a/core/live-tests/src/commonTest/kotlin/KordTest.kt b/core/live-tests/src/commonTest/kotlin/KordTest.kt
new file mode 100644
index 00000000000..c91db63b330
--- /dev/null
+++ b/core/live-tests/src/commonTest/kotlin/KordTest.kt
@@ -0,0 +1,18 @@
+package dev.kord.core
+
+import dev.kord.core.event.gateway.ReadyEvent
+import kotlinx.coroutines.test.runTest
+import kotlin.js.JsName
+import kotlin.test.Test
+import kotlin.test.assertFalse
+
+internal class KordTest {
+ @Test
+ @JsName("test1")
+ fun `Kord life cycle is correctly ended on shutdown`() = runTest {
+ val kord = Kord.restOnly(testToken)
+ val job = kord.on {}
+ kord.shutdown()
+ assertFalse(job.isActive)
+ }
+}
diff --git a/core/live-tests/src/commonTest/kotlin/StrategyTest.kt b/core/live-tests/src/commonTest/kotlin/StrategyTest.kt
new file mode 100644
index 00000000000..d7c0a9837ff
--- /dev/null
+++ b/core/live-tests/src/commonTest/kotlin/StrategyTest.kt
@@ -0,0 +1,52 @@
+package dev.kord.core
+
+import dev.kord.cache.api.put
+import dev.kord.core.supplier.EntitySupplyStrategy
+import kotlinx.coroutines.test.runTest
+import kotlin.js.JsName
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+
+class StrategyTest {
+
+ @Test
+ @JsName("test1")
+ fun `rest only`() = runTest {
+ withKord { kord ->
+ val fromRest = kord.with(EntitySupplyStrategy.rest).getSelfOrNull()
+ val inCache = kord.with(EntitySupplyStrategy.cache).getSelfOrNull()
+ assertNull(inCache)
+ assertNotNull(fromRest)
+ }
+ }
+
+ @Test
+ @JsName("test2")
+ fun `cache only`() = runTest {
+ withKord { kord ->
+ kord.cache.put(kord.getSelf().data)
+ val inCache = kord.with(EntitySupplyStrategy.cache).getSelfOrNull()
+ assertNotNull(inCache)
+ }
+ }
+
+ @Test
+ @JsName("test3")
+ fun `cache falls back to rest`() = runTest {
+ withKord { kord ->
+ val cache = kord.with(EntitySupplyStrategy.cache)
+ val inCache = cache.getSelfOrNull()
+
+ assertNull(inCache)
+
+ val self = kord.getSelf()
+ assertNotNull(self)
+ kord.cache.put(self.data)
+
+ assertEquals(self, cache.getSelf())
+
+ }
+ }
+}
diff --git a/core/live-tests/src/commonTest/kotlin/TestToken.kt b/core/live-tests/src/commonTest/kotlin/TestToken.kt
new file mode 100644
index 00000000000..3634fddf977
--- /dev/null
+++ b/core/live-tests/src/commonTest/kotlin/TestToken.kt
@@ -0,0 +1,42 @@
+package dev.kord.core
+
+import dev.kord.cache.map.MapDataCache
+import dev.kord.core.builder.kord.configure
+import dev.kord.core.builder.kord.getBotIdFromToken
+import dev.kord.core.cache.registerKordData
+import dev.kord.core.gateway.DefaultMasterGateway
+import dev.kord.core.gateway.handler.DefaultGatewayEventInterceptor
+import dev.kord.core.regression.CrashingHandler
+import dev.kord.core.regression.FakeGateway
+import dev.kord.core.supplier.EntitySupplyStrategy
+import dev.kord.gateway.builder.Shards
+import dev.kord.rest.service.RestClient
+import dev.kord.test.getEnv
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableSharedFlow
+
+val testToken = getEnv("KORD_TEST_TOKEN") ?: error("KORD_TEST_TOKEN is not defined")
+
+suspend inline fun withKord(block: (kord: Kord) -> Unit) {
+ val token = testToken
+ val resources = ClientResources(
+ token,
+ getBotIdFromToken(token),
+ Shards(1),
+ maxConcurrency = 1,
+ null.configure(),
+ EntitySupplyStrategy.cacheWithRestFallback,
+ )
+ val kord = Kord(
+ resources,
+ MapDataCache().also { it.registerKordData() },
+ DefaultMasterGateway(mapOf(0 to FakeGateway)),
+ RestClient(CrashingHandler(resources.httpClient, resources.token)),
+ getBotIdFromToken(token),
+ MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE),
+ Dispatchers.Default,
+ DefaultGatewayEventInterceptor(),
+ )
+ block(kord)
+ kord.shutdown()
+}
diff --git a/core/src/test/kotlin/regression/CacheMissRegression.kt b/core/live-tests/src/commonTest/kotlin/regression/CacheMissRegression.kt
similarity index 64%
rename from core/src/test/kotlin/regression/CacheMissRegression.kt
rename to core/live-tests/src/commonTest/kotlin/regression/CacheMissRegression.kt
index eba4327ae36..e547779900c 100644
--- a/core/src/test/kotlin/regression/CacheMissRegression.kt
+++ b/core/live-tests/src/commonTest/kotlin/regression/CacheMissRegression.kt
@@ -1,29 +1,19 @@
-package regression
+package dev.kord.core.regression
import dev.kord.cache.api.put
-import dev.kord.cache.map.MapDataCache
import dev.kord.common.entity.ChannelType
import dev.kord.common.entity.Snowflake
-import dev.kord.core.ClientResources
-import dev.kord.core.Kord
-import dev.kord.core.builder.kord.configure
-import dev.kord.core.builder.kord.getBotIdFromToken
import dev.kord.core.cache.data.ChannelData
-import dev.kord.core.cache.registerKordData
-import dev.kord.core.gateway.DefaultMasterGateway
-import dev.kord.core.gateway.handler.DefaultGatewayEventInterceptor
-import dev.kord.core.supplier.EntitySupplyStrategy
+import dev.kord.core.withKord
import dev.kord.gateway.Command
import dev.kord.gateway.Event
import dev.kord.gateway.Gateway
import dev.kord.gateway.GatewayConfiguration
-import dev.kord.gateway.builder.Shards
import dev.kord.rest.request.JsonRequest
import dev.kord.rest.request.MultipartRequest
import dev.kord.rest.request.Request
import dev.kord.rest.request.RequestHandler
import dev.kord.rest.route.Route
-import dev.kord.rest.service.RestClient
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.request.forms.*
@@ -31,22 +21,19 @@ import io.ktor.client.statement.*
import io.ktor.content.*
import io.ktor.http.*
import kotlinx.coroutines.CompletableDeferred
-import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
-import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.Json
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertThrows
-import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
-import kotlin.test.BeforeTest
+import kotlin.js.JsName
+import kotlin.test.Test
+import kotlin.test.assertFailsWith
import kotlin.time.Duration
@@ -116,52 +103,25 @@ class CrashingHandler(val client: HttpClient, override val token: String) : Requ
}
}
-@EnabledIfEnvironmentVariable(named = "KORD_TEST_TOKEN", matches = ".+")
class CacheMissingRegressions {
- lateinit var kord: Kord
-
- @BeforeTest
- fun setup() = runTest { //TODO, move this over to entity supplier tests instead, eventually.
- val token = System.getenv("KORD_TEST_TOKEN")
- val resources = ClientResources(
- token,
- getBotIdFromToken(token),
- Shards(1),
- maxConcurrency = 1,
- null.configure(),
- EntitySupplyStrategy.cacheWithRestFallback,
- )
- kord = Kord(
- resources,
- MapDataCache().also { it.registerKordData() },
- DefaultMasterGateway(mapOf(0 to FakeGateway)),
- RestClient(CrashingHandler(resources.httpClient, resources.token)),
- getBotIdFromToken(token),
- MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE),
- Dispatchers.Default,
- DefaultGatewayEventInterceptor(),
- )
- }
-
@Test
- fun `if data not in cache explode`() {
- val id = 5uL
- assertThrows {
- runBlocking {
- kord.getChannel(Snowflake(id))
- }
+ @JsName("test1")
+ fun `if data not in cache explode`() = runTest {
+ withKord { kord ->
+ val id = 5uL
+ assertFailsWith { kord.getChannel(Snowflake(id)) }
}
}
@Test
- fun `if data in cache don't fetch from rest`() {
- runBlocking {
+ @JsName("test2")
+ fun `if data in cache don't fetch from rest`() = runTest {
+ withKord { kord ->
val id = Snowflake(5uL)
kord.cache.put(ChannelData(id, ChannelType.GuildText))
kord.getChannel(id)
}
}
-
}
diff --git a/core/src/main/kotlin/ClientResources.kt b/core/src/commonMain/kotlin/ClientResources.kt
similarity index 100%
rename from core/src/main/kotlin/ClientResources.kt
rename to core/src/commonMain/kotlin/ClientResources.kt
diff --git a/core/src/main/kotlin/Kord.kt b/core/src/commonMain/kotlin/Kord.kt
similarity index 100%
rename from core/src/main/kotlin/Kord.kt
rename to core/src/commonMain/kotlin/Kord.kt
diff --git a/core/src/main/kotlin/KordObject.kt b/core/src/commonMain/kotlin/KordObject.kt
similarity index 100%
rename from core/src/main/kotlin/KordObject.kt
rename to core/src/commonMain/kotlin/KordObject.kt
diff --git a/core/src/main/kotlin/Unsafe.kt b/core/src/commonMain/kotlin/Unsafe.kt
similarity index 100%
rename from core/src/main/kotlin/Unsafe.kt
rename to core/src/commonMain/kotlin/Unsafe.kt
diff --git a/core/src/main/kotlin/Util.kt b/core/src/commonMain/kotlin/Util.kt
similarity index 99%
rename from core/src/main/kotlin/Util.kt
rename to core/src/commonMain/kotlin/Util.kt
index 49e8e660a49..82751017716 100644
--- a/core/src/main/kotlin/Util.kt
+++ b/core/src/commonMain/kotlin/Util.kt
@@ -476,3 +476,6 @@ public fun Intents.IntentsBuilder.enableEvent(event: KClass): Unit =
else -> Unit
}
+
+// Replacement of Objects.hash
+internal fun hash(vararg values: Any?) = values.contentHashCode()
diff --git a/core/src/main/kotlin/behavior/ChatInputCommandBehavior.kt b/core/src/commonMain/kotlin/behavior/ChatInputCommandBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/ChatInputCommandBehavior.kt
rename to core/src/commonMain/kotlin/behavior/ChatInputCommandBehavior.kt
diff --git a/core/src/main/kotlin/behavior/GlobalApplicationCommandBehavior.kt b/core/src/commonMain/kotlin/behavior/GlobalApplicationCommandBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/GlobalApplicationCommandBehavior.kt
rename to core/src/commonMain/kotlin/behavior/GlobalApplicationCommandBehavior.kt
diff --git a/core/src/main/kotlin/behavior/GuildBehavior.kt b/core/src/commonMain/kotlin/behavior/GuildBehavior.kt
similarity index 99%
rename from core/src/main/kotlin/behavior/GuildBehavior.kt
rename to core/src/commonMain/kotlin/behavior/GuildBehavior.kt
index d557377c5af..e7899b7ac8c 100644
--- a/core/src/main/kotlin/behavior/GuildBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/GuildBehavior.kt
@@ -22,6 +22,7 @@ import dev.kord.core.entity.channel.*
import dev.kord.core.entity.channel.thread.ThreadChannel
import dev.kord.core.event.guild.MembersChunkEvent
import dev.kord.core.exception.EntityNotFoundException
+import dev.kord.core.hash
import dev.kord.core.supplier.*
import dev.kord.core.supplier.EntitySupplyStrategy.Companion.rest
import dev.kord.gateway.Gateway
@@ -53,7 +54,6 @@ import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.*
import kotlinx.coroutines.flow.*
import kotlinx.datetime.Instant
-import java.util.Objects
import kotlin.contracts.InvocationKind
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
@@ -677,7 +677,7 @@ public fun GuildBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id)
+ override fun hashCode(): Int = hash(id)
override fun equals(other: Any?): Boolean = when (other) {
is GuildBehavior -> other.id == id
diff --git a/core/src/main/kotlin/behavior/GuildEmojiBehavior.kt b/core/src/commonMain/kotlin/behavior/GuildEmojiBehavior.kt
similarity index 97%
rename from core/src/main/kotlin/behavior/GuildEmojiBehavior.kt
rename to core/src/commonMain/kotlin/behavior/GuildEmojiBehavior.kt
index 31242215bdc..d71f3aa431b 100644
--- a/core/src/main/kotlin/behavior/GuildEmojiBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/GuildEmojiBehavior.kt
@@ -6,11 +6,11 @@ import dev.kord.core.cache.data.EmojiData
import dev.kord.core.entity.KordEntity
import dev.kord.core.entity.GuildEmoji
import dev.kord.core.entity.Strategizable
+import dev.kord.core.hash
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.guild.EmojiModifyBuilder
import dev.kord.rest.request.RestRequestException
-import java.util.*
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -57,7 +57,7 @@ internal fun GuildEmojiBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id)
+ override fun hashCode(): Int = hash(id)
override fun equals(other: Any?): Boolean = when (other) {
is GuildEmojiBehavior -> other.id == id
diff --git a/core/src/main/kotlin/behavior/GuildScheduledEventBehavior.kt b/core/src/commonMain/kotlin/behavior/GuildScheduledEventBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/GuildScheduledEventBehavior.kt
rename to core/src/commonMain/kotlin/behavior/GuildScheduledEventBehavior.kt
diff --git a/core/src/main/kotlin/behavior/MemberBehavior.kt b/core/src/commonMain/kotlin/behavior/MemberBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/MemberBehavior.kt
rename to core/src/commonMain/kotlin/behavior/MemberBehavior.kt
index 59ac4763568..341825bf4fb 100644
--- a/core/src/main/kotlin/behavior/MemberBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/MemberBehavior.kt
@@ -11,12 +11,12 @@ import dev.kord.core.cache.data.VoiceStateData
import dev.kord.core.cache.idEq
import dev.kord.core.entity.*
import dev.kord.core.exception.EntityNotFoundException
+import dev.kord.core.hash
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.ban.BanCreateBuilder
import dev.kord.rest.builder.member.MemberModifyBuilder
import dev.kord.rest.request.RestRequestException
-import java.util.Objects
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -193,7 +193,7 @@ public fun MemberBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is MemberBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/MessageBehavior.kt b/core/src/commonMain/kotlin/behavior/MessageBehavior.kt
similarity index 99%
rename from core/src/main/kotlin/behavior/MessageBehavior.kt
rename to core/src/commonMain/kotlin/behavior/MessageBehavior.kt
index 1619b4d2b12..fbf1b2e01ce 100644
--- a/core/src/main/kotlin/behavior/MessageBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/MessageBehavior.kt
@@ -20,7 +20,7 @@ import dev.kord.rest.builder.message.modify.WebhookMessageModifyBuilder
import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.RestClient
import kotlinx.coroutines.flow.Flow
-import java.util.Objects
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -229,7 +229,7 @@ public fun MessageBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id)
+ override fun hashCode(): Int = hash(id)
override fun equals(other: Any?): Boolean = when (other) {
is MessageBehavior -> other.id == id && other.channelId == channelId
diff --git a/core/src/main/kotlin/behavior/MessageCommandBehavior.kt b/core/src/commonMain/kotlin/behavior/MessageCommandBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/MessageCommandBehavior.kt
rename to core/src/commonMain/kotlin/behavior/MessageCommandBehavior.kt
diff --git a/core/src/main/kotlin/behavior/RoleBehavior.kt b/core/src/commonMain/kotlin/behavior/RoleBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/RoleBehavior.kt
rename to core/src/commonMain/kotlin/behavior/RoleBehavior.kt
index 28156818599..66850198adf 100644
--- a/core/src/main/kotlin/behavior/RoleBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/RoleBehavior.kt
@@ -8,6 +8,7 @@ import dev.kord.core.entity.KordEntity
import dev.kord.core.entity.Role
import dev.kord.core.entity.Strategizable
import dev.kord.core.exception.EntityNotFoundException
+import dev.kord.core.hash
import dev.kord.core.indexOfFirstOrNull
import dev.kord.core.sorted
import dev.kord.core.supplier.EntitySupplier
@@ -17,7 +18,6 @@ import dev.kord.rest.request.RestRequestException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.map
-import java.util.*
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -129,7 +129,7 @@ public fun RoleBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is RoleBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/StageInstanceBehavior.kt b/core/src/commonMain/kotlin/behavior/StageInstanceBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/StageInstanceBehavior.kt
rename to core/src/commonMain/kotlin/behavior/StageInstanceBehavior.kt
diff --git a/core/src/main/kotlin/behavior/StickerBehavior.kt b/core/src/commonMain/kotlin/behavior/StickerBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/StickerBehavior.kt
rename to core/src/commonMain/kotlin/behavior/StickerBehavior.kt
diff --git a/core/src/main/kotlin/behavior/TemplateBehavior.kt b/core/src/commonMain/kotlin/behavior/TemplateBehavior.kt
similarity index 96%
rename from core/src/main/kotlin/behavior/TemplateBehavior.kt
rename to core/src/commonMain/kotlin/behavior/TemplateBehavior.kt
index e81cfa20723..7ed3674b675 100644
--- a/core/src/main/kotlin/behavior/TemplateBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/TemplateBehavior.kt
@@ -8,7 +8,7 @@ import dev.kord.core.entity.Guild
import dev.kord.core.entity.Template
import dev.kord.rest.builder.template.GuildFromTemplateCreateBuilder
import dev.kord.rest.builder.template.GuildTemplateModifyBuilder
-import java.util.*
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -52,7 +52,7 @@ public fun TemplateBehavior(guildId: Snowflake, code: String, kord: Kord): Templ
override val guildId: Snowflake = guildId
override val kord: Kord = kord
- override fun hashCode(): Int = Objects.hash(code)
+ override fun hashCode(): Int = hash(code)
override fun equals(other: Any?): Boolean =
other is TemplateBehavior && other.code == code
diff --git a/core/src/main/kotlin/behavior/ThreadMemberBehavior.kt b/core/src/commonMain/kotlin/behavior/ThreadMemberBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/ThreadMemberBehavior.kt
rename to core/src/commonMain/kotlin/behavior/ThreadMemberBehavior.kt
diff --git a/core/src/main/kotlin/behavior/UserBehavior.kt b/core/src/commonMain/kotlin/behavior/UserBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/UserBehavior.kt
rename to core/src/commonMain/kotlin/behavior/UserBehavior.kt
index 0a91a7998f2..bc4bfe226e6 100644
--- a/core/src/main/kotlin/behavior/UserBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/UserBehavior.kt
@@ -15,7 +15,7 @@ import dev.kord.rest.json.request.DMCreateRequest
import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.RestClient
import io.ktor.http.*
-import java.util.*
+import dev.kord.core.hash
/**
* The behavior of a [Discord User](https://discord.com/developers/docs/resources/user)
@@ -145,7 +145,7 @@ public fun UserBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id)
+ override fun hashCode(): Int = hash(id)
override fun equals(other: Any?): Boolean = when (other) {
is UserBehavior -> other.id == id
diff --git a/core/src/main/kotlin/behavior/UserCommandBehavior.kt b/core/src/commonMain/kotlin/behavior/UserCommandBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/UserCommandBehavior.kt
rename to core/src/commonMain/kotlin/behavior/UserCommandBehavior.kt
diff --git a/core/src/main/kotlin/behavior/WebhookBehavior.kt b/core/src/commonMain/kotlin/behavior/WebhookBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/WebhookBehavior.kt
rename to core/src/commonMain/kotlin/behavior/WebhookBehavior.kt
index b70f37fca7c..9fae71abca0 100644
--- a/core/src/main/kotlin/behavior/WebhookBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/WebhookBehavior.kt
@@ -15,7 +15,7 @@ import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.message.create.WebhookMessageCreateBuilder
import dev.kord.rest.builder.webhook.WebhookModifyBuilder
import dev.kord.rest.request.RestRequestException
-import java.util.*
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -102,7 +102,7 @@ internal fun WebhookBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id)
+ override fun hashCode(): Int = hash(id)
override fun equals(other: Any?): Boolean = when (other) {
is WebhookBehavior -> other.id == id
diff --git a/core/src/main/kotlin/behavior/automoderation/AutoModerationRuleBehavior.kt b/core/src/commonMain/kotlin/behavior/automoderation/AutoModerationRuleBehavior.kt
similarity index 99%
rename from core/src/main/kotlin/behavior/automoderation/AutoModerationRuleBehavior.kt
rename to core/src/commonMain/kotlin/behavior/automoderation/AutoModerationRuleBehavior.kt
index a8d2359722c..9da181c459f 100644
--- a/core/src/main/kotlin/behavior/automoderation/AutoModerationRuleBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/automoderation/AutoModerationRuleBehavior.kt
@@ -17,7 +17,7 @@ import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.automoderation.*
import dev.kord.rest.request.RestRequestException
-import java.util.Objects
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
@@ -106,7 +106,7 @@ internal class AutoModerationRuleBehaviorImpl(
internal fun AutoModerationRuleBehavior.autoModerationRuleEquals(other: Any?) =
this === other || (other is AutoModerationRuleBehavior && this.id == other.id && this.guildId == other.guildId)
-internal fun AutoModerationRuleBehavior.autoModerationRuleHashCode() = Objects.hash(id, guildId)
+internal fun AutoModerationRuleBehavior.autoModerationRuleHashCode() = hash(id, guildId)
/**
* Requests to edit this [AutoModerationRule] and returns the edited rule.
diff --git a/core/src/main/kotlin/behavior/channel/BaseVoiceChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/BaseVoiceChannelBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/channel/BaseVoiceChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/BaseVoiceChannelBehavior.kt
diff --git a/core/src/main/kotlin/behavior/channel/CategorizableChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/CategorizableChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/CategorizableChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/CategorizableChannelBehavior.kt
index 21c4a0d5297..9b1f843ca23 100644
--- a/core/src/main/kotlin/behavior/channel/CategorizableChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/CategorizableChannelBehavior.kt
@@ -17,7 +17,7 @@ import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.RestClient
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
-import java.util.*
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -110,7 +110,7 @@ internal fun CategorizableChannelBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/CategoryBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/CategoryBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt
index ee163b1d680..e7057d60a8b 100644
--- a/core/src/main/kotlin/behavior/channel/CategoryBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/CategoryBehavior.kt
@@ -22,7 +22,7 @@ import dev.kord.rest.service.patchCategory
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
-import java.util.*
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -101,7 +101,7 @@ public fun CategoryBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is TopGuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/ChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/ChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/ChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/ChannelBehavior.kt
index 5db6749f6f3..42ffd8272b1 100644
--- a/core/src/main/kotlin/behavior/channel/ChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/ChannelBehavior.kt
@@ -12,7 +12,7 @@ import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.core.supplier.getChannelOf
import dev.kord.core.supplier.getChannelOfOrNull
import dev.kord.rest.request.RestRequestException
-import java.util.*
+import dev.kord.core.hash
/**
* The behavior of a [Discord Channel](https://discord.com/developers/docs/resources/channel)
@@ -101,7 +101,7 @@ public fun ChannelBehavior(id: Snowflake, kord: Kord, strategy: EntitySupplyStra
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id)
+ override fun hashCode(): Int = hash(id)
override fun equals(other: Any?): Boolean = when (other) {
is ChannelBehavior -> other.id == id
diff --git a/core/src/main/kotlin/behavior/channel/ForumChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/ForumChannelBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/channel/ForumChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/ForumChannelBehavior.kt
diff --git a/core/src/main/kotlin/behavior/channel/GuildChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/GuildChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/GuildChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/GuildChannelBehavior.kt
index 06a1a066512..63640b2ad49 100644
--- a/core/src/main/kotlin/behavior/channel/GuildChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/GuildChannelBehavior.kt
@@ -12,7 +12,7 @@ import dev.kord.core.entity.channel.TopGuildChannel
import dev.kord.core.exception.EntityNotFoundException
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
-import java.util.*
+import dev.kord.core.hash
/**
* The behavior of a Discord channel associated to a [guild].
@@ -110,7 +110,7 @@ public fun GuildChannelBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/GuildMessageChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/GuildMessageChannelBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/channel/GuildMessageChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/GuildMessageChannelBehavior.kt
diff --git a/core/src/main/kotlin/behavior/channel/MessageChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/MessageChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/MessageChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/MessageChannelBehavior.kt
index 88854a12b8b..76702092614 100644
--- a/core/src/main/kotlin/behavior/channel/MessageChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/MessageChannelBehavior.kt
@@ -8,6 +8,7 @@ import dev.kord.core.entity.Message
import dev.kord.core.entity.Strategizable
import dev.kord.core.entity.channel.MessageChannel
import dev.kord.core.exception.EntityNotFoundException
+import dev.kord.core.hash
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.message.EmbedBuilder
@@ -25,9 +26,9 @@ import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
-import java.util.Objects
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
+import kotlin.js.JsName
import kotlin.time.Duration.Companion.seconds
import kotlin.time.TimeMark
@@ -212,6 +213,7 @@ public interface MessageChannelBehavior : ChannelBehavior, Strategizable {
*
* @throws [RestRequestException] if something went wrong during the request.
*/
+ @JsName("sendTyping") // otherwise clashes with Channel.type property
public suspend fun type() {
kord.rest.channel.triggerTypingIndicator(id)
}
@@ -259,7 +261,7 @@ public fun MessageChannelBehavior(
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id)
+ override fun hashCode(): Int = hash(id)
override fun equals(other: Any?): Boolean = when (other) {
is ChannelBehavior -> other.id == id
diff --git a/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/NewsChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/NewsChannelBehavior.kt
index d188f66af30..8c8bdf030cf 100644
--- a/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/NewsChannelBehavior.kt
@@ -25,7 +25,7 @@ import dev.kord.rest.service.patchNewsChannel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.datetime.Instant
-import java.util.Objects
+import dev.kord.core.hash
import kotlin.DeprecationLevel.ERROR
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -156,7 +156,7 @@ public fun NewsChannelBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/StageChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/StageChannelBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/channel/StageChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/StageChannelBehavior.kt
diff --git a/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/TextChannelBehavior.kt
similarity index 99%
rename from core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/TextChannelBehavior.kt
index f4c33a8f91b..49e6cfab04f 100644
--- a/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/TextChannelBehavior.kt
@@ -23,7 +23,7 @@ import dev.kord.rest.service.patchTextChannel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.datetime.Instant
-import java.util.*
+import dev.kord.core.hash
import kotlin.DeprecationLevel.ERROR
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -170,7 +170,7 @@ public fun TextChannelBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/TopGuildChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/TopGuildChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/TopGuildChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/TopGuildChannelBehavior.kt
index cc6f0bec056..ed93a4edbe7 100644
--- a/core/src/main/kotlin/behavior/channel/TopGuildChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/TopGuildChannelBehavior.kt
@@ -14,7 +14,7 @@ import dev.kord.rest.service.editMemberPermissions
import dev.kord.rest.service.editRolePermission
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.withIndex
-import java.util.*
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -103,7 +103,7 @@ internal fun TopGuildChannelBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/TopGuildMessageChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/TopGuildMessageChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/TopGuildMessageChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/TopGuildMessageChannelBehavior.kt
index 8a930746d00..106b2173185 100644
--- a/core/src/main/kotlin/behavior/channel/TopGuildMessageChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/TopGuildMessageChannelBehavior.kt
@@ -9,8 +9,8 @@ import dev.kord.core.exception.EntityNotFoundException
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.webhook.WebhookCreateBuilder
-import java.util.*
import kotlin.DeprecationLevel.HIDDEN
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -78,7 +78,7 @@ internal fun TopGuildMessageChannelBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/VoiceChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/VoiceChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/VoiceChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/VoiceChannelBehavior.kt
index caa781deadd..0c1b1ed4874 100644
--- a/core/src/main/kotlin/behavior/channel/VoiceChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/VoiceChannelBehavior.kt
@@ -12,7 +12,7 @@ import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.channel.VoiceChannelModifyBuilder
import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.patchVoiceChannel
-import java.util.*
+import dev.kord.core.hash
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -73,7 +73,7 @@ public fun VoiceChannelBehavior(
override val kord: Kord = kord
override val supplier: EntitySupplier = strategy.supply(kord)
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/channel/threads/ThreadChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/threads/ThreadChannelBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/channel/threads/ThreadChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/threads/ThreadChannelBehavior.kt
diff --git a/core/src/main/kotlin/behavior/channel/threads/ThreadParentChannelBehavior.kt b/core/src/commonMain/kotlin/behavior/channel/threads/ThreadParentChannelBehavior.kt
similarity index 98%
rename from core/src/main/kotlin/behavior/channel/threads/ThreadParentChannelBehavior.kt
rename to core/src/commonMain/kotlin/behavior/channel/threads/ThreadParentChannelBehavior.kt
index 75914d7e7a7..32d1c4e4a69 100644
--- a/core/src/main/kotlin/behavior/channel/threads/ThreadParentChannelBehavior.kt
+++ b/core/src/commonMain/kotlin/behavior/channel/threads/ThreadParentChannelBehavior.kt
@@ -19,7 +19,7 @@ import dev.kord.rest.builder.channel.thread.StartThreadBuilder
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.datetime.Instant
-import java.util.*
+import dev.kord.core.hash
/**
* Behavior of channels that can contain public threads.
@@ -169,7 +169,7 @@ internal fun ThreadParentChannelBehavior(
override val supplier: EntitySupplier
get() = supplier
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
@@ -201,7 +201,7 @@ internal fun PrivateThreadParentChannelBehavior(
override val supplier: EntitySupplier
get() = supplier
- override fun hashCode(): Int = Objects.hash(id, guildId)
+ override fun hashCode(): Int = hash(id, guildId)
override fun equals(other: Any?): Boolean = when (other) {
is GuildChannelBehavior -> other.id == id && other.guildId == guildId
diff --git a/core/src/main/kotlin/behavior/interaction/ActionInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/ActionInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/ActionInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/ActionInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/ApplicationCommandInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/ApplicationCommandInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/ApplicationCommandInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/ApplicationCommandInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/AutoCompleteInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/AutoCompleteInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/AutoCompleteInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/AutoCompleteInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/ComponentInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/ComponentInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/ComponentInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/ComponentInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/DataInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/DataInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/DataInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/DataInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/GlobalInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/GlobalInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/GlobalInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/GlobalInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/GuildInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/GuildInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/GuildInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/GuildInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/InteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/InteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/InteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/InteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/ModalParentInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/ModalParentInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/ModalParentInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/ModalParentInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/followup/EphemeralFollowupMessageBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/followup/EphemeralFollowupMessageBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/followup/EphemeralFollowupMessageBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/followup/EphemeralFollowupMessageBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/followup/FollowupMessageBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/followup/FollowupMessageBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/followup/FollowupMessageBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/followup/FollowupMessageBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/followup/PublicFollowupMessageBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/followup/PublicFollowupMessageBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/followup/PublicFollowupMessageBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/followup/PublicFollowupMessageBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/DeferredEphemeralMessageInteractionBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/DeferredEphemeralMessageInteractionBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/DeferredEphemeralMessageInteractionBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/DeferredEphemeralMessageInteractionBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/DeferredMessageInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/DeferredMessageInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/DeferredMessageInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/DeferredMessageInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/DeferredPublicMessageInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/DeferredPublicMessageInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/DeferredPublicMessageInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/DeferredPublicMessageInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/EditOriginalResponse.kt b/core/src/commonMain/kotlin/behavior/interaction/response/EditOriginalResponse.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/EditOriginalResponse.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/EditOriginalResponse.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/EphemeralInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/EphemeralInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/EphemeralInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/EphemeralInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/EphemeralMessageInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/EphemeralMessageInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/EphemeralMessageInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/EphemeralMessageInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/FollowupPermittingInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/FollowupPermittingInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/FollowupPermittingInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/FollowupPermittingInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/InteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/MessageInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/MessageInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/MessageInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/MessageInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/PopupInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/PopupInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/PopupInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/PopupInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/PublicInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/PublicInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/PublicInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/PublicInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/behavior/interaction/response/PublicMesageInteractionResponseBehavior.kt b/core/src/commonMain/kotlin/behavior/interaction/response/PublicMesageInteractionResponseBehavior.kt
similarity index 100%
rename from core/src/main/kotlin/behavior/interaction/response/PublicMesageInteractionResponseBehavior.kt
rename to core/src/commonMain/kotlin/behavior/interaction/response/PublicMesageInteractionResponseBehavior.kt
diff --git a/core/src/main/kotlin/builder/component/ButtonBuilderExtensions.kt b/core/src/commonMain/kotlin/builder/component/ButtonBuilderExtensions.kt
similarity index 100%
rename from core/src/main/kotlin/builder/component/ButtonBuilderExtensions.kt
rename to core/src/commonMain/kotlin/builder/component/ButtonBuilderExtensions.kt
diff --git a/core/src/main/kotlin/builder/kord/KordBuilder.kt b/core/src/commonMain/kotlin/builder/kord/KordBuilder.kt
similarity index 95%
rename from core/src/main/kotlin/builder/kord/KordBuilder.kt
rename to core/src/commonMain/kotlin/builder/kord/KordBuilder.kt
index e55b0832da4..a30efa507e9 100644
--- a/core/src/main/kotlin/builder/kord/KordBuilder.kt
+++ b/core/src/commonMain/kotlin/builder/kord/KordBuilder.kt
@@ -36,11 +36,9 @@ import io.ktor.http.HttpHeaders.UserAgent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
-import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import kotlin.DeprecationLevel.HIDDEN
-import kotlin.concurrent.thread
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.time.Duration.Companion.seconds
@@ -64,7 +62,9 @@ public operator fun DefaultGateway.Companion.invoke(
private val logger = KotlinLogging.logger { }
private val gatewayInfoJson = Json { ignoreUnknownKeys = true }
-public class KordBuilder(public val token: String) {
+public expect class KordBuilder(token: String) : BaseKordBuilder
+
+public abstract class BaseKordBuilder internal constructor(public val token: String) {
private var shardsBuilder: (recommended: Int) -> Shards = { Shards(it) }
private var gatewayBuilder: (resources: ClientResources, shards: List) -> List =
{ resources, shards ->
@@ -92,11 +92,6 @@ public class KordBuilder(public val token: String) {
*/
public var stackTraceRecovery: Boolean = false
- /**
- * Enable adding a [Runtime.addShutdownHook] to log out of the [Gateway] when the process is killed.
- */
- public var enableShutdownHook: Boolean = true
-
/**
* The event flow used by [Kord.eventFlow] to publish [events][Kord.events].
*
@@ -236,7 +231,9 @@ public class KordBuilder(public val token: String) {
/**
* @throws KordInitializationException if something went wrong while getting the bot's gateway information.
*/
- public suspend fun build(): Kord {
+ public open suspend fun build(): Kord = buildBase()
+
+ protected suspend fun buildBase(): Kord {
val client = httpClient.configure()
val gatewayInfo = client.getGatewayInfo()
@@ -289,14 +286,6 @@ public class KordBuilder(public val token: String) {
val self = getBotIdFromToken(token)
- if (enableShutdownHook) {
- Runtime.getRuntime().addShutdownHook(thread(false) {
- runBlocking {
- gateway.detachAll()
- }
- })
- }
-
return Kord(
resources = resources,
cache = cache,
diff --git a/core/src/main/kotlin/builder/kord/KordBuilderUtil.kt b/core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt
similarity index 77%
rename from core/src/main/kotlin/builder/kord/KordBuilderUtil.kt
rename to core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt
index cc957bcbfd3..0f0d9e0dd75 100644
--- a/core/src/main/kotlin/builder/kord/KordBuilderUtil.kt
+++ b/core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt
@@ -1,9 +1,9 @@
package dev.kord.core.builder.kord
+import dev.kord.common.annotation.KordInternal
import dev.kord.common.entity.Snowflake
+import dev.kord.common.http.HttpEngine
import io.ktor.client.*
-import io.ktor.client.engine.cio.*
-import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.websocket.*
import io.ktor.serialization.kotlinx.json.*
@@ -19,7 +19,9 @@ internal fun HttpClientConfig<*>.defaultConfig() {
install(WebSockets)
}
-internal fun HttpClient?.configure(): HttpClient {
+/** @suppress */
+@KordInternal
+public fun HttpClient?.configure(): HttpClient {
if (this != null) return this.config {
defaultConfig()
}
@@ -31,7 +33,7 @@ internal fun HttpClient?.configure(): HttpClient {
isLenient = true
}
- return HttpClient(CIO) {
+ return HttpClient(HttpEngine) {
defaultConfig()
install(ContentNegotiation) {
json(json)
@@ -39,8 +41,9 @@ internal fun HttpClient?.configure(): HttpClient {
}
}
-
-internal fun getBotIdFromToken(token: String) = try {
+/** @suppress */
+@KordInternal
+public fun getBotIdFromToken(token: String): Snowflake = try {
Snowflake(token.substringBefore('.').decodeBase64String())
} catch (exception: IllegalArgumentException) {
throw IllegalArgumentException("Malformed bot token: '$token'. Make sure that your token is correct.")
diff --git a/core/src/main/kotlin/builder/kord/KordProxyBuilder.kt b/core/src/commonMain/kotlin/builder/kord/KordProxyBuilder.kt
similarity index 100%
rename from core/src/main/kotlin/builder/kord/KordProxyBuilder.kt
rename to core/src/commonMain/kotlin/builder/kord/KordProxyBuilder.kt
diff --git a/core/src/main/kotlin/builder/kord/KordRestOnlyBuilder.kt b/core/src/commonMain/kotlin/builder/kord/KordRestOnlyBuilder.kt
similarity index 100%
rename from core/src/main/kotlin/builder/kord/KordRestOnlyBuilder.kt
rename to core/src/commonMain/kotlin/builder/kord/KordRestOnlyBuilder.kt
diff --git a/core/src/main/kotlin/builder/kord/RestOnlyBuilder.kt b/core/src/commonMain/kotlin/builder/kord/RestOnlyBuilder.kt
similarity index 100%
rename from core/src/main/kotlin/builder/kord/RestOnlyBuilder.kt
rename to core/src/commonMain/kotlin/builder/kord/RestOnlyBuilder.kt
diff --git a/core/src/main/kotlin/cache/CachingGateway.kt b/core/src/commonMain/kotlin/cache/CachingGateway.kt
similarity index 100%
rename from core/src/main/kotlin/cache/CachingGateway.kt
rename to core/src/commonMain/kotlin/cache/CachingGateway.kt
diff --git a/core/src/main/kotlin/cache/DataCacheExtensions.kt b/core/src/commonMain/kotlin/cache/DataCacheExtensions.kt
similarity index 91%
rename from core/src/main/kotlin/cache/DataCacheExtensions.kt
rename to core/src/commonMain/kotlin/cache/DataCacheExtensions.kt
index 0ebc3deba6a..ec322be7f50 100644
--- a/core/src/main/kotlin/cache/DataCacheExtensions.kt
+++ b/core/src/commonMain/kotlin/cache/DataCacheExtensions.kt
@@ -2,12 +2,16 @@ package dev.kord.core.cache
import dev.kord.cache.api.DataCache
import dev.kord.cache.api.query
+import dev.kord.common.annotation.KordInternal
import dev.kord.core.cache.data.*
/**
* Registers all Kord data classes for this cache
+ *
+ * @suppress
*/
-internal suspend fun DataCache.registerKordData() = register(
+@KordInternal
+public suspend fun DataCache.registerKordData(): Unit = register(
RoleData.description,
ChannelData.description,
GuildData.description,
diff --git a/core/src/main/kotlin/cache/DataCacheView.kt b/core/src/commonMain/kotlin/cache/DataCacheView.kt
similarity index 100%
rename from core/src/main/kotlin/cache/DataCacheView.kt
rename to core/src/commonMain/kotlin/cache/DataCacheView.kt
diff --git a/core/src/main/kotlin/cache/KordCache.kt b/core/src/commonMain/kotlin/cache/KordCache.kt
similarity index 90%
rename from core/src/main/kotlin/cache/KordCache.kt
rename to core/src/commonMain/kotlin/cache/KordCache.kt
index c886b88d171..e0e304d7ec9 100644
--- a/core/src/main/kotlin/cache/KordCache.kt
+++ b/core/src/commonMain/kotlin/cache/KordCache.kt
@@ -7,10 +7,9 @@ import dev.kord.cache.api.delegate.DelegatingDataCache
import dev.kord.cache.api.delegate.EntrySupplier
import dev.kord.cache.map.MapLikeCollection
import dev.kord.cache.map.internal.MapEntryCache
-import dev.kord.cache.map.lruLinkedHashMap
+import dev.kord.common.ConcurrentHashMap
import dev.kord.common.entity.Snowflake
import dev.kord.core.cache.data.*
-import java.util.concurrent.ConcurrentHashMap
public typealias Generator = (cache: DataCache, description: DataDescription) -> DataEntryCache
@@ -20,7 +19,7 @@ public class KordCacheBuilder {
* The default behavior for all types not explicitly configured, by default a [ConcurrentHashMap] is supplied.
*/
public var defaultGenerator: Generator = { cache, description ->
- MapEntryCache(cache, description, MapLikeCollection.concurrentHashMap())
+ MapEntryCache(cache, description, MapLikeCollection.concurrentHashMap())
}
private val descriptionGenerators: MutableMap, Generator<*, *>> = mutableMapOf()
@@ -42,14 +41,6 @@ public class KordCacheBuilder {
*/
public fun none(): Generator = { _, _ -> DataEntryCache.none() }
- /**
- * A Generator creating [DataEntryCaches][DataEntryCache] with a maximum [size], removing items on last insertion.
- * Shortcut for [lruLinkedHashMap].
- */
- public fun lruCache(size: Int = 100): Generator