Skip to content

Commit

Permalink
Merge branch 'main' into kotlin-2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Sep 17, 2024
2 parents 465a8af + ad59083 commit 82bbcca
Show file tree
Hide file tree
Showing 80 changed files with 4,409 additions and 124 deletions.
16 changes: 11 additions & 5 deletions buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import org.gradle.api.NamedDomainObjectSet
import org.gradle.kotlin.dsl.assign
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

val kordOptIns = listOf(
Expand All @@ -12,16 +14,20 @@ val kordOptIns = listOf(
"dev.kord.common.annotation.KordVoice",
)

object Jvm {
const val target = 8
}

fun KotlinCommonCompilerOptions.applyKordCompilerOptions() {
internal fun KotlinCommonCompilerOptions.applyKordCommonCompilerOptions() {
allWarningsAsErrors = true
progressiveMode = true
freeCompilerArgs.add("-Xexpect-actual-classes")
}

internal const val KORD_JVM_TARGET = 8

internal fun KotlinJvmCompilerOptions.applyKordJvmCompilerOptions() {
applyKordCommonCompilerOptions()
jvmTarget = JVM_1_8
freeCompilerArgs.add("-Xjdk-release=1.8")
}

internal fun NamedDomainObjectSet<KotlinSourceSet>.applyKordTestOptIns() {
named { it.contains("test", ignoreCase = true) }.configureEach {
// allow `ExperimentalCoroutinesApi` for `TestScope.currentTime`
Expand Down
9 changes: 7 additions & 2 deletions buildSrc/src/main/kotlin/kord-internal-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ repositories {
}

kotlin {
jvmToolchain(Jvm.target)
compilerOptions {
applyKordCompilerOptions()
applyKordJvmCompilerOptions()
}
}

tasks {
withType<JavaCompile>().configureEach {
options.release = KORD_JVM_TARGET
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ repositories {
mavenLocal()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
jvm()
compilerOptions {
applyKordCommonCompilerOptions()
}

jvm {
compilerOptions {
applyKordJvmCompilerOptions()
}
}
js {
nodejs()
useCommonJs()
}
jvmToolchain(Jvm.target)

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
applyKordCompilerOptions()
}
}

tasks {
Expand Down
9 changes: 5 additions & 4 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ apiValidation {

kotlin {
explicitApi()

jvmToolchain(Jvm.target)

compilerOptions {
applyKordCompilerOptions()
applyKordJvmCompilerOptions()
optIn.addAll(kordOptIns)
}

Expand All @@ -47,6 +44,10 @@ tasks {
withType<AbstractDokkaLeafTask>().configureEach {
applyKordDokkaOptions()
}

withType<JavaCompile>().configureEach {
options.release = KORD_JVM_TARGET
}
}

publishing {
Expand Down
18 changes: 10 additions & 8 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ apiValidation {
applyKordBCVOptions()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
explicitApi()
compilerOptions {
applyKordCommonCompilerOptions()
optIn.addAll(kordOptIns)
}

jvm()
jvm {
compilerOptions {
applyKordJvmCompilerOptions()
}
}
js {
nodejs {
testTask {
Expand All @@ -41,13 +50,6 @@ kotlin {
}
useCommonJs()
}
jvmToolchain(Jvm.target)

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
applyKordCompilerOptions()
optIn.addAll(kordOptIns)
}

applyDefaultHierarchyTemplate()

Expand Down
367 changes: 359 additions & 8 deletions common/api/common.api

Large diffs are not rendered by default.

341 changes: 337 additions & 4 deletions common/api/common.klib.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public sealed class ButtonStyle(
*/
public object Link : ButtonStyle(5)

/**
* Blurple, prompts to purchase a premium offering.
*/
public object Premium : ButtonStyle(6)

internal object Serializer : KSerializer<ButtonStyle> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.ButtonStyle", PrimitiveKind.INT)
Expand All @@ -90,6 +95,7 @@ public sealed class ButtonStyle(
Success,
Danger,
Link,
Premium,
)
}

Expand All @@ -103,6 +109,7 @@ public sealed class ButtonStyle(
3 -> Success
4 -> Danger
5 -> Link
6 -> Premium
else -> Unknown(value)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
@file:Suppress(names = arrayOf("IncorrectFormatting", "ReplaceArrayOfWithLiteral",
"SpellCheckingInspection", "GrazieInspection"))

package dev.kord.common.entity

import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [EntitlementOwnerType]s in the
* [Discord Developer Documentation](https://discord.com/developers/docs/resources/entitlement#create-test-entitlement-json-params).
*/
@Serializable(with = EntitlementOwnerType.Serializer::class)
public sealed class EntitlementOwnerType(
/**
* The raw value used by Discord.
*/
public val `value`: Int,
) {
final override fun equals(other: Any?): Boolean = this === other ||
(other is EntitlementOwnerType && this.value == other.value)

final override fun hashCode(): Int = value.hashCode()

final override fun toString(): String =
if (this is Unknown) "EntitlementOwnerType.Unknown(value=$value)"
else "EntitlementOwnerType.${this::class.simpleName}"

/**
* An unknown [EntitlementOwnerType].
*
* This is used as a fallback for [EntitlementOwnerType]s that haven't been added to Kord yet.
*/
public class Unknown internal constructor(
`value`: Int,
) : EntitlementOwnerType(value)

/**
* Entitlement is owned by a guild.
*/
public object Guild : EntitlementOwnerType(1)

/**
* Entitlement is owned by a user.
*/
public object User : EntitlementOwnerType(2)

internal object Serializer : KSerializer<EntitlementOwnerType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.EntitlementOwnerType",
PrimitiveKind.INT)

override fun serialize(encoder: Encoder, `value`: EntitlementOwnerType) {
encoder.encodeInt(value.value)
}

override fun deserialize(decoder: Decoder): EntitlementOwnerType = from(decoder.decodeInt())
}

public companion object {
/**
* A [List] of all known [EntitlementOwnerType]s.
*/
public val entries: List<EntitlementOwnerType> by lazy(mode = PUBLICATION) {
listOf(
Guild,
User,
)
}

/**
* Returns an instance of [EntitlementOwnerType] with [EntitlementOwnerType.value] equal to
* the specified [value].
*/
public fun from(`value`: Int): EntitlementOwnerType = when (value) {
1 -> Guild
2 -> User
else -> Unknown(value)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
@file:Suppress(names = arrayOf("IncorrectFormatting", "ReplaceArrayOfWithLiteral",
"SpellCheckingInspection", "GrazieInspection"))

package dev.kord.common.entity

import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [EntitlementType]s in the
* [Discord Developer Documentation](https://discord.com/developers/docs/resources/entitlement#entitlement-object-entitlement-types).
*/
@Serializable(with = EntitlementType.Serializer::class)
public sealed class EntitlementType(
/**
* The raw value used by Discord.
*/
public val `value`: Int,
) {
final override fun equals(other: Any?): Boolean = this === other ||
(other is EntitlementType && this.value == other.value)

final override fun hashCode(): Int = value.hashCode()

final override fun toString(): String =
if (this is Unknown) "EntitlementType.Unknown(value=$value)"
else "EntitlementType.${this::class.simpleName}"

/**
* An unknown [EntitlementType].
*
* This is used as a fallback for [EntitlementType]s that haven't been added to Kord yet.
*/
public class Unknown internal constructor(
`value`: Int,
) : EntitlementType(value)

/**
* Entitlement that was purchased by a user.
*/
public object Purchase : EntitlementType(1)

/**
* Entitlement for a Discord Nitro subscription.
*/
public object PremiumSubscription : EntitlementType(2)

/**
* Entitlement that was gifted to a user by the developer.
*/
public object DeveloperGift : EntitlementType(3)

/**
* Entitlement that was purchased by a dev in application test mode.
*/
public object TestModePurchase : EntitlementType(4)

/**
* Entitlement that was granted when the [SKU][DiscordSku] was free.
*/
public object FreePurchase : EntitlementType(5)

/**
* Entitlement that was gifted to a user by another user.
*/
public object UserGift : EntitlementType(6)

/**
* Entitlement that was claimed by a user for free as a Nitro subscriber.
*/
public object PremiumPurchase : EntitlementType(7)

/**
* Entitlement that was purchased as an app subscription.
*/
public object ApplicationSubscription : EntitlementType(8)

internal object Serializer : KSerializer<EntitlementType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.EntitlementType",
PrimitiveKind.INT)

override fun serialize(encoder: Encoder, `value`: EntitlementType) {
encoder.encodeInt(value.value)
}

override fun deserialize(decoder: Decoder): EntitlementType = from(decoder.decodeInt())
}

public companion object {
/**
* A [List] of all known [EntitlementType]s.
*/
public val entries: List<EntitlementType> by lazy(mode = PUBLICATION) {
listOf(
Purchase,
PremiumSubscription,
DeveloperGift,
TestModePurchase,
FreePurchase,
UserGift,
PremiumPurchase,
ApplicationSubscription,
)
}

/**
* Returns an instance of [EntitlementType] with [EntitlementType.value] equal to the
* specified [value].
*/
public fun from(`value`: Int): EntitlementType = when (value) {
1 -> Purchase
2 -> PremiumSubscription
3 -> DeveloperGift
4 -> TestModePurchase
5 -> FreePurchase
6 -> UserGift
7 -> PremiumPurchase
8 -> ApplicationSubscription
else -> Unknown(value)
}
}
}
Loading

0 comments on commit 82bbcca

Please sign in to comment.