From f30f7c37934e0186b596c0edbf13fb7534477fc0 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sat, 9 Jul 2022 17:46:16 +0200 Subject: [PATCH 01/47] Add KSP processor for enum generation --- build.gradle.kts | 4 + buildSrc/build.gradle.kts | 1 + buildSrc/src/main/kotlin/Compiler.kt | 8 + .../kotlin/kord-internal-module.gradle.kts | 22 ++ .../src/main/kotlin/kord-module.gradle.kts | 19 +- common/build.gradle.kts | 3 + ksp-annotations/build.gradle.kts | 3 + .../src/main/kotlin/GenerateKordEnum.kt | 56 +++++ ksp-processors/build.gradle.kts | 9 + ksp-processors/src/main/kotlin/KSPUtils.kt | 15 ++ .../src/main/kotlin/KotlinPoetUtils.kt | 83 +++++++ .../src/main/kotlin/kordenum/KordEnum.kt | 155 ++++++++++++ .../kotlin/kordenum/KordEnumGeneration.kt | 231 ++++++++++++++++++ .../main/kotlin/kordenum/KordEnumProcessor.kt | 64 +++++ .../kordenum/KordEnumProcessorProvider.kt | 10 + ...ols.ksp.processing.SymbolProcessorProvider | 1 + settings.gradle.kts | 13 + 17 files changed, 690 insertions(+), 7 deletions(-) create mode 100644 buildSrc/src/main/kotlin/kord-internal-module.gradle.kts create mode 100644 ksp-annotations/build.gradle.kts create mode 100644 ksp-annotations/src/main/kotlin/GenerateKordEnum.kt create mode 100644 ksp-processors/build.gradle.kts create mode 100644 ksp-processors/src/main/kotlin/KSPUtils.kt create mode 100644 ksp-processors/src/main/kotlin/KotlinPoetUtils.kt create mode 100644 ksp-processors/src/main/kotlin/kordenum/KordEnum.kt create mode 100644 ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt create mode 100644 ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt create mode 100644 ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt create mode 100644 ksp-processors/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/build.gradle.kts b/build.gradle.kts index 8a951b3c20b5..ba617de58eb2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,3 +53,7 @@ configure { commitMessage.set("Update Docs") } + +apiValidation { + ignoredProjects += listOf("ksp-annotations", "ksp-processors") +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3b4cc4b6be3d..504b10bd8c82 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -17,6 +17,7 @@ dependencies { implementation(kotlin("serialization")) implementation("org.jetbrains.dokka", "dokka-gradle-plugin", "1.7.0") implementation("org.jetbrains.kotlinx", "atomicfu-gradle-plugin", "0.18.2") + implementation("com.google.devtools.ksp", "symbol-processing-gradle-plugin", "1.7.10-1.0.6") implementation(gradleApi()) implementation(localGroovy()) } diff --git a/buildSrc/src/main/kotlin/Compiler.kt b/buildSrc/src/main/kotlin/Compiler.kt index 98b00f63c291..1062a1ddd2d0 100644 --- a/buildSrc/src/main/kotlin/Compiler.kt +++ b/buildSrc/src/main/kotlin/Compiler.kt @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions + object CompilerArguments { const val time = "-opt-in=kotlin.time.ExperimentalTime" const val contracts = "-opt-in=kotlin.contracts.ExperimentalContracts" @@ -12,3 +14,9 @@ object CompilerArguments { object Jvm { const val target = "1.8" } + +fun KotlinJvmOptions.kordJvmOptions() { + jvmTarget = Jvm.target + allWarningsAsErrors = true + freeCompilerArgs += CompilerArguments.progressive +} diff --git a/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts new file mode 100644 index 000000000000..8ac0e450cfbd --- /dev/null +++ b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts @@ -0,0 +1,22 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") +} + +repositories { + mavenCentral() +} + +tasks { + withType { + sourceCompatibility = Jvm.target + targetCompatibility = Jvm.target + } + + withType { + kotlinOptions { + kordJvmOptions() + } + } +} diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 99f5c00bd2fa..82088f440206 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -6,6 +6,7 @@ plugins { kotlin("plugin.serialization") id("org.jetbrains.dokka") id("kotlinx-atomicfu") + id("com.google.devtools.ksp") `maven-publish` } @@ -22,8 +23,15 @@ dependencies { kotlin { explicitApi() - // allow ExperimentalCoroutinesApi for `runTest {}` - sourceSets["test"].languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") + sourceSets.main { + // mark ksp src dir + kotlin.srcDir("build/generated/ksp/main/kotlin") + } + + sourceSets.test { + // allow ExperimentalCoroutinesApi for `runTest {}` + languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") + } } tasks { @@ -38,17 +46,14 @@ tasks { withType { kotlinOptions { - jvmTarget = Jvm.target - allWarningsAsErrors = true - freeCompilerArgs = listOf( + kordJvmOptions() + freeCompilerArgs += listOf( CompilerArguments.time, CompilerArguments.contracts, CompilerArguments.kordPreview, CompilerArguments.kordExperimental, CompilerArguments.kordVoice, - - CompilerArguments.progressive, ) } } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 754c8ffafa9b..28ea464a6a35 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -19,6 +19,9 @@ dependencies { api(libs.bundles.common) testImplementation(libs.bundles.test.implementation) testRuntimeOnly(libs.bundles.test.runtime) + + compileOnly(projects.kspAnnotations) + ksp(projects.kspProcessors) } /* diff --git a/ksp-annotations/build.gradle.kts b/ksp-annotations/build.gradle.kts new file mode 100644 index 000000000000..e8efcb5ecf8c --- /dev/null +++ b/ksp-annotations/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + `kord-internal-module` +} diff --git a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt new file mode 100644 index 000000000000..40b34a25c4f1 --- /dev/null +++ b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt @@ -0,0 +1,56 @@ +@file:Suppress("unused") + +package dev.kord.ksp + +import kotlin.DeprecationLevel.WARNING +import kotlin.annotation.AnnotationRetention.SOURCE +import kotlin.annotation.AnnotationTarget.FILE +import dev.kord.ksp.GenerateKordEnum.ValueType.* + +/** Generate a kord enum in the same package as this file. */ +@Target(FILE) +@Retention(SOURCE) +@Repeatable +annotation class GenerateKordEnum( + /** Name of the kord enum. */ + val name: String, + /** [ValueType] of the kord enum. */ + val valueType: ValueType, + /** [Entries][Entry] of the kord enum. */ + val entries: Array, + /** KDoc for the kord enum (optional). */ + val kDoc: String = "", + /** Name of the value of the kord enum. */ + val valueName: String = "value", + /** [entries] of the kord enum that are [Deprecated]. [Entry.deprecationMessage] is required for these. */ + val deprecatedEntries: Array = [], +) { + enum class ValueType { INT, STRING } + + @Target() + @Retention(SOURCE) + annotation class Entry( + /** Name of the entry. */ + val name: String, + /** [Int] value of the entry. Only set this if [GenerateKordEnum.valueType] is [INT]. */ + val intValue: Int = DEFAULT_INT_VALUE, + /** [String] value of the entry. Only set this if [GenerateKordEnum.valueType] is [STRING]. */ + val stringValue: String = DEFAULT_STRING_VALUE, + /** KDoc for the entry (optional). */ + val kDoc: String = "", + /** [Deprecated.message] for a [deprecated entry][GenerateKordEnum.deprecatedEntries]. */ + val deprecationMessage: String = "", + /** [Deprecated.replaceWith] for a [deprecated entry][GenerateKordEnum.deprecatedEntries]. */ + val replaceWith: ReplaceWith = ReplaceWith(""), + /** [Deprecated.level] for a [deprecated entry][GenerateKordEnum.deprecatedEntries]. */ + val deprecationLevel: DeprecationLevel = WARNING, + ) { + companion object { + /** Default value for [intValue]. */ + const val DEFAULT_INT_VALUE = Int.MIN_VALUE // probably won't appear anywhere + + /** Default value for [stringValue]. */ + const val DEFAULT_STRING_VALUE = "" + } + } +} diff --git a/ksp-processors/build.gradle.kts b/ksp-processors/build.gradle.kts new file mode 100644 index 000000000000..a35aa19036c8 --- /dev/null +++ b/ksp-processors/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `kord-internal-module` +} + +dependencies { + implementation(projects.kspAnnotations) + implementation(libs.bundles.ksp.processors) + implementation(libs.bundles.common) +} diff --git a/ksp-processors/src/main/kotlin/KSPUtils.kt b/ksp-processors/src/main/kotlin/KSPUtils.kt new file mode 100644 index 000000000000..1a7928aa3091 --- /dev/null +++ b/ksp-processors/src/main/kotlin/KSPUtils.kt @@ -0,0 +1,15 @@ +package dev.kord.ksp + +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotation +import kotlin.reflect.KProperty1 + +internal inline fun Resolver.getSymbolsWithAnnotation() = + getSymbolsWithAnnotation(A::class.qualifiedName!!) + +internal inline fun KSAnnotation.isOfType() = shortName.asString() == A::class.simpleName!! + && annotationType.resolve().declaration.qualifiedName?.asString() == A::class.qualifiedName!! + +internal fun KSAnnotation.argumentsToMap() = arguments.associate { it.name!!.getShortName() to it.value!! } + +internal operator fun Map.get(parameter: KProperty1<*, *>) = get(parameter.name) diff --git a/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt b/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt new file mode 100644 index 000000000000..1e5a6e734fab --- /dev/null +++ b/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt @@ -0,0 +1,83 @@ +package dev.kord.ksp + +import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.MemberName.Companion.member +import kotlin.reflect.KClass + +// standalone + +internal inline fun fileSpec(packageName: String, fileName: String, builder: FileSpec.Builder.() -> Unit) = + FileSpec.builder(packageName, fileName).apply(builder).build() + +internal inline fun annotationSpec(builder: AnnotationSpec.Builder.() -> Unit) = + AnnotationSpec.builder(A::class).apply(builder).build() + + +// FileSpec.Builder + +internal inline fun FileSpec.Builder.addClass(className: ClassName, builder: TypeSpec.Builder.() -> Unit) = + addType(TypeSpec.classBuilder(className).apply(builder).build()) + +internal inline fun FileSpec.Builder.addAnnotation( + builder: AnnotationSpec.Builder.() -> Unit, +) = addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) + + +// TypeSpec.Builder + +internal inline fun TypeSpec.Builder.addAnnotation( + builder: AnnotationSpec.Builder.() -> Unit, +) = addAnnotation(AnnotationSpec.Companion.builder(A::class).apply(builder).build()) + +internal inline fun TypeSpec.Builder.primaryConstructor(builder: FunSpec.Builder.() -> Unit) = + primaryConstructor(FunSpec.constructorBuilder().apply(builder).build()) + +internal inline fun TypeSpec.Builder.addProperty( + name: String, + type: KClass<*>, + vararg modifiers: KModifier, + builder: PropertySpec.Builder.() -> Unit, +) = addProperty(PropertySpec.builder(name, type, *modifiers).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addProperty( + name: String, + vararg modifiers: KModifier, + builder: PropertySpec.Builder.() -> Unit, +) = addProperty(PropertySpec.builder(name, typeNameOf(), *modifiers).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addProperty( + name: String, + type: TypeName, + vararg modifiers: KModifier, + builder: PropertySpec.Builder.() -> Unit, +) = addProperty(PropertySpec.builder(name, type, *modifiers).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addFunction(name: String, builder: FunSpec.Builder.() -> Unit) = + addFunction(FunSpec.builder(name).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addClass(name: String, builder: TypeSpec.Builder.() -> Unit) = + addType(TypeSpec.classBuilder(name).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addObject(name: String, builder: TypeSpec.Builder.() -> Unit) = + addType(TypeSpec.objectBuilder(name).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, builder: TypeSpec.Builder.() -> Unit) = + addType(TypeSpec.companionObjectBuilder(name).apply(builder).build()) + + +// FunSpec.Builder + +internal inline fun FunSpec.Builder.returns() = returns(typeNameOf()) + +internal inline fun FunSpec.Builder.addParameter(name: String) = addParameter(name, typeNameOf()) + + +// PropertySpec.Builder + +internal inline fun PropertySpec.Builder.delegate(builder: CodeBlock.Builder.() -> Unit) = + delegate(CodeBlock.builder().apply(builder).build()) + + +// other + +internal inline fun > E.asMemberName() = E::class.member(name) diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt new file mode 100644 index 000000000000..b2f2c77e9cec --- /dev/null +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt @@ -0,0 +1,155 @@ +package dev.kord.ksp.kordenum + +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSType +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.ValueType +import dev.kord.ksp.GenerateKordEnum.ValueType.INT +import dev.kord.ksp.GenerateKordEnum.ValueType.STRING +import dev.kord.ksp.argumentsToMap +import dev.kord.ksp.get +import dev.kord.ksp.kordenum.KordEnum.Entry +import kotlin.DeprecationLevel.* + +/** Mapping of [GenerateKordEnum] that is easier to work with in [KordEnumProcessor]. */ +internal class KordEnum( + val name: String, + val kDoc: String?, + val valueType: ValueType, + val valueName: String, + val entries: List, + val deprecatedEntries: List, +) { + internal class Entry( + val name: String, + val kDoc: String?, + val value: Comparable<*>, + val isDeprecated: Boolean, + val deprecationMessage: String = "", + val replaceWith: ReplaceWith? = null, + val deprecationLevel: DeprecationLevel = WARNING, + ) +} + +/** + * Maps [KSAnnotation] for [GenerateKordEnum] to [KordEnum]. + * + * Returns `null` if mapping fails. + */ +internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { + val args = argumentsToMap() + + val name = args[GenerateKordEnum::name] as String + val valueType = args[GenerateKordEnum::valueType].toValueType() + val entries = args[GenerateKordEnum::entries] as List<*> + val kDoc = args[GenerateKordEnum::kDoc].toKDoc() + val valueName = args[GenerateKordEnum::valueName] as String + val deprecatedEntries = args[GenerateKordEnum::deprecatedEntries] as List<*> + + return KordEnum( + name, kDoc, valueType, valueName, + entries.map { it.toEntryOrNull(valueType, deprecated = false, logger) ?: return null }, + deprecatedEntries.map { it.toEntryOrNull(valueType, deprecated = true, logger) ?: return null }, + ) +} + +/** Maps [KSType] to [ValueType]. */ +private fun Any?.toValueType() = when (val name = (this as KSType).declaration.qualifiedName?.asString()) { + "dev.kord.ksp.GenerateKordEnum.ValueType.INT" -> INT + "dev.kord.ksp.GenerateKordEnum.ValueType.STRING" -> STRING + else -> error("Unknown GenerateKordEnum.ValueType: $name") +} + +private fun Any?.toKDoc() = (this as String).trimIndent().ifBlank { null } + +/** + * Maps [KSAnnotation] for [GenerateKordEnum.Entry] to [Entry]. + * + * Returns `null` if mapping fails. + */ +private fun Any?.toEntryOrNull(valueType: ValueType, deprecated: Boolean, logger: KSPLogger): Entry? { + val args = (this as KSAnnotation).argumentsToMap() + + val name = args[GenerateKordEnum.Entry::name] as String + val intValue = args[GenerateKordEnum.Entry::intValue] as Int + val stringValue = args[GenerateKordEnum.Entry::stringValue] as String + val kDoc = args[GenerateKordEnum.Entry::kDoc].toKDoc() + val deprecationMessage = args[GenerateKordEnum.Entry::deprecationMessage] as String + val replaceWith = args[GenerateKordEnum.Entry::replaceWith].toReplaceWith() + val deprecationLevel = args[GenerateKordEnum.Entry::deprecationLevel].toDeprecationLevel() + + val value = when (valueType) { + INT -> { + if (stringValue != GenerateKordEnum.Entry.DEFAULT_STRING_VALUE) { + logger.error("Specified stringValue for valueType $valueType", symbol = this) + return null + } + if (intValue == GenerateKordEnum.Entry.DEFAULT_INT_VALUE) { + logger.error("Didn't specify intValue for valueType $valueType", symbol = this) + return null + } + + intValue + } + STRING -> { + if (intValue != GenerateKordEnum.Entry.DEFAULT_INT_VALUE) { + logger.error("Specified intValue for valueType $valueType", symbol = this) + return null + } + if (stringValue == GenerateKordEnum.Entry.DEFAULT_STRING_VALUE) { + logger.error("Didn't specify stringValue for valueType $valueType", symbol = this) + return null + } + + stringValue + } + } + + return if (deprecated) { + if (deprecationMessage.isBlank()) { + logger.error("deprecationMessage is required", symbol = this) + return null + } + + Entry( + name, kDoc, value, isDeprecated = true, + deprecationMessage, + replaceWith.takeIf { it.expression.isNotBlank() }, + deprecationLevel, + ) + } else { + if (deprecationMessage.isNotEmpty()) { + logger.error("deprecationMessage is not allowed", symbol = this) + return null + } + if (replaceWith.expression.isNotEmpty() || replaceWith.imports.isNotEmpty()) { + logger.error("replaceWith is not allowed", symbol = this) + return null + } + if (deprecationLevel != WARNING) { + logger.error("deprecationLevel is not allowed", symbol = this) + return null + } + + Entry(name, kDoc, value, isDeprecated = false) + } +} + +/** Maps [KSAnnotation] to [ReplaceWith]. */ +private fun Any?.toReplaceWith(): ReplaceWith { + val args = (this as KSAnnotation).argumentsToMap() + + val expression = args[ReplaceWith::expression] as String + val imports = @Suppress("UNCHECKED_CAST") (args[ReplaceWith::imports] as List) + + return ReplaceWith(expression, *imports.toTypedArray()) +} + +/** Maps [KSType] to [DeprecationLevel]. */ +private fun Any?.toDeprecationLevel() = when (val name = (this as KSType).declaration.qualifiedName?.asString()) { + "kotlin.DeprecationLevel.WARNING" -> WARNING + "kotlin.DeprecationLevel.ERROR" -> ERROR + "kotlin.DeprecationLevel.HIDDEN" -> HIDDEN + else -> error("Unknown DeprecationLevel: $name") +} diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt new file mode 100644 index 000000000000..6f3c97b07189 --- /dev/null +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -0,0 +1,231 @@ +package dev.kord.ksp.kordenum + +import com.google.devtools.ksp.symbol.KSFile +import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.KModifier.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.ksp.addOriginatingKSFile +import dev.kord.ksp.* +import dev.kord.ksp.GenerateKordEnum.ValueType +import dev.kord.ksp.GenerateKordEnum.ValueType.INT +import dev.kord.ksp.GenerateKordEnum.ValueType.STRING +import dev.kord.ksp.kordenum.KordEnum.Entry +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlin.DeprecationLevel.* +import kotlin.LazyThreadSafetyMode.PUBLICATION + +private val PRIMITIVE_SERIAL_DESCRIPTOR = MemberName("kotlinx.serialization.descriptors", "PrimitiveSerialDescriptor") + +private val Entry.warningSuppressedName + get() = when { + isDeprecated -> "@Suppress(\"${ + when (deprecationLevel) { + WARNING -> "DEPRECATION" + ERROR -> "DEPRECATION_ERROR" + HIDDEN -> TODO("How can we use HIDDEN symbols? (if at all)") + } + }\")·$name" + else -> name + } + +private fun ValueType.toKClass() = when (this) { + INT -> Int::class + STRING -> String::class +} + +private fun ValueType.toEncodingPostfix() = when (this) { + INT -> "Int" + STRING -> "String" +} + +private fun ValueType.toFormat() = when (this) { + INT -> "%L" + STRING -> "%S" +} + +private fun ValueType.toPrimitiveKind() = when (this) { + INT -> PrimitiveKind.INT::class + STRING -> PrimitiveKind.STRING::class +} + +internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { + + val packageName = originatingFile.packageName.asString() + val enumName = ClassName(packageName, name) + val valueKClass = valueType.toKClass() + val encodingPostfix = valueType.toEncodingPostfix() + val valueFormat = valueType.toFormat() + + val relevantEntriesForSerializerAndCompanion = run { + + // don't keep deprecated entries with a non-deprecated replacement + val nonDeprecatedValues = entries.map { it.value }.toSet() + + entries + .plus(deprecatedEntries.filter { it.value !in nonDeprecatedValues }) + .sortedWith { e1, e2 -> + @Suppress("UNCHECKED_CAST") // values are of same type + (e1.value as Comparable>).compareTo(e2.value) + } + } + + return fileSpec(packageName, fileName = name) { + indent(" ") + addAnnotation { + addMember("%S, %S, %S", "UnusedImport", "RedundantVisibilityModifier", "IncorrectFormatting") + } + + // /** */ + // @Serializable(with = .Serializer::class) + // public sealed class (public val : ) + addClass(enumName) { + + // for ksp incremental processing + addOriginatingKSFile(originatingFile) + + kDoc?.let { addKdoc(it) } + addAnnotation { + addMember("with·=·%T.Serializer::class", enumName) + } + addModifiers(PUBLIC, SEALED) + primaryConstructor { + addParameter(valueName, valueKClass) + } + addProperty(valueName, valueKClass, PUBLIC) { + initializer(valueName) + } + + // final override fun equals + addFunction("equals") { + addModifiers(FINAL, OVERRIDE) + returns() + addParameter("other") + addStatement("return this·===·other || (other·is·%T && this.$valueName·==·other.$valueName)", enumName) + } + + // final override fun hashCode + addFunction("hashCode") { + addModifiers(FINAL, OVERRIDE) + returns() + addStatement("return $valueName.hashCode()") + } + + + // /** An unknown []. */ + // public class Unknown(: ) : () + addClass("Unknown") { + addKdoc("An unknown [%T].", enumName) + addModifiers(PUBLIC) + primaryConstructor { + addParameter(valueName, valueKClass) + } + superclass(enumName) + addSuperclassConstructorParameter(valueName) + } + + + fun TypeSpec.Builder.entry(entry: Entry) { + entry.kDoc?.let { addKdoc(it) } + addModifiers(PUBLIC) + superclass(enumName) + addSuperclassConstructorParameter(valueFormat, entry.value) + } + + // /** */ + // public object : () + for (entry in entries) { + addObject(entry.name) { + entry(entry) + } + } + + // /** */ + // @Deprecated(, , level = ) + // public object : () + for (entry in deprecatedEntries) { + addObject(entry.name) { + entry(entry) + addAnnotation { + addMember("%S", entry.deprecationMessage) + + // replacement if present + entry.replaceWith?.let { replaceWith -> + addMember("%L", annotationSpec { + addMember("%S", replaceWith.expression) + val imports = replaceWith.imports + if (imports.isNotEmpty()) { + addMember(imports.joinToString { "%S" }, *imports) + } + }) + } + + addMember("level·=·%M", entry.deprecationLevel.asMemberName()) + } + } + } + + + // internal object Serializer : KSerializer<> + addObject("Serializer") { + addModifiers(INTERNAL) + addSuperinterface(KSerializer::class.asClassName().parameterizedBy(enumName)) + + // override val descriptor + addProperty("descriptor", OVERRIDE) { + initializer( + "%M(%S, %T)", + PRIMITIVE_SERIAL_DESCRIPTOR, + enumName.canonicalName, + valueType.toPrimitiveKind(), + ) + } + + // override fun serialize + addFunction("serialize") { + addModifiers(OVERRIDE) + addParameter("encoder") + addParameter("value", enumName) + addStatement("return encoder.encode$encodingPostfix(value.$valueName)") + } + + // override fun deserialize + addFunction("deserialize") { + addModifiers(OVERRIDE) + addParameter("decoder") + beginControlFlow("return when·(val·$valueName·=·decoder.decode$encodingPostfix())") + for (entry in relevantEntriesForSerializerAndCompanion) { + addStatement("$valueFormat·->·${entry.warningSuppressedName}", entry.value) + } + addStatement("else·->·Unknown($valueName)") + endControlFlow() + } + } + + + // public companion object + addCompanionObject { + addModifiers(PUBLIC) + + // public val entries + addProperty("entries", List::class.asClassName().parameterizedBy(enumName), PUBLIC) { + delegate { + beginControlFlow("lazy(mode·=·%M)", PUBLICATION.asMemberName()) + addStatement("listOf(") + withIndent { + for (entry in relevantEntriesForSerializerAndCompanion) { + addStatement("${entry.warningSuppressedName},") + } + } + addStatement(")") + endControlFlow() + } + } + } + } + } +} diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt new file mode 100644 index 000000000000..514192695386 --- /dev/null +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt @@ -0,0 +1,64 @@ +package dev.kord.ksp.kordenum + +import com.google.devtools.ksp.processing.CodeGenerator +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.processing.SymbolProcessor +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSFile +import com.squareup.kotlinpoet.ksp.writeTo +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.getSymbolsWithAnnotation +import dev.kord.ksp.isOfType + +/** [SymbolProcessor] for [GenerateKordEnum] annotation. */ +class KordEnumProcessor(private val codeGenerator: CodeGenerator, private val logger: KSPLogger) : SymbolProcessor { + + override fun finish() { + logger.info("KordEnumProcessor received finish signal") + } + + override fun onError() { + logger.info("KordEnumProcessor received error signal") + } + + override fun process(resolver: Resolver): List { + logger.info("KordEnumProcessor got called, resolving annotations...") + + resolver + .getSymbolsWithAnnotation() + .mapNotNull { symbol -> + when (symbol) { + is KSFile -> symbol + else -> { + logger.warn("found annotation on wrong symbol", symbol) + null + } + } + } + .forEach(::processFile) + + logger.info("KordEnumProcessor finished processing annotations") + + return emptyList() // we never have to defer any symbols + } + + private fun processFile(file: KSFile) { + file.annotations + .filter { it.isOfType() } + .onEach { logger.info("found annotation", symbol = it) } + .mapNotNull { it.toKordEnumOrNull(logger) } + .forEach { generateKordEnum(it, file) } + } + + private fun generateKordEnum(kordEnum: KordEnum, originatingFile: KSFile) { + logger.info("generating ${kordEnum.name}...") + + val kordEnumFileSpec = kordEnum.generateFileSpec(originatingFile) + + // this output is isolating, see https://kotlinlang.org/docs/ksp-incremental.html#aggregating-vs-isolating + kordEnumFileSpec.writeTo(codeGenerator, aggregating = false) + + logger.info("finished generating ${kordEnum.name}") + } +} diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt new file mode 100644 index 000000000000..d72dc4c91ec6 --- /dev/null +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt @@ -0,0 +1,10 @@ +package dev.kord.ksp.kordenum + +import com.google.devtools.ksp.processing.SymbolProcessorEnvironment +import com.google.devtools.ksp.processing.SymbolProcessorProvider + +/** [SymbolProcessorProvider] for [KordEnumProcessor]. */ +class KordEnumProcessorProvider : SymbolProcessorProvider { + override fun create(environment: SymbolProcessorEnvironment) = + KordEnumProcessor(environment.codeGenerator, environment.logger) +} diff --git a/ksp-processors/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/ksp-processors/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider new file mode 100644 index 000000000000..29c136e0b63e --- /dev/null +++ b/ksp-processors/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider @@ -0,0 +1 @@ +dev.kord.ksp.kordenum.KordEnumProcessorProvider diff --git a/settings.gradle.kts b/settings.gradle.kts index b440b137bcd2..77f28b2de133 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,6 +21,8 @@ include("rest") include("core") include("voice") include("bom") +include("ksp-annotations") +include("ksp-processors") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") @@ -32,6 +34,7 @@ dependencyResolutionManagement { cache() common() tests() + kspProcessors() } } } @@ -97,3 +100,13 @@ fun VersionCatalogBuilder.tests() { ) ) } + +fun VersionCatalogBuilder.kspProcessors() { + library("ksp-api", "com.google.devtools.ksp", "symbol-processing-api").version("1.7.10-1.0.6") + + val kotlinpoet = version("kotlinpoet", "1.12.0") + library("kotlinpoet", "com.squareup", "kotlinpoet").versionRef(kotlinpoet) + library("kotlinpoet-ksp", "com.squareup", "kotlinpoet-ksp").versionRef(kotlinpoet) + + bundle("ksp-processors", listOf("ksp-api", "kotlinpoet", "kotlinpoet-ksp")) +} From c110a9280e5a878f2f275bfb4c8fbab7b1ba7491 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Thu, 14 Jul 2022 21:07:17 +0200 Subject: [PATCH 02/47] Add options to deprecate `values` property --- .../src/main/kotlin/GenerateKordEnum.kt | 9 +++++ .../src/main/kotlin/KotlinPoetUtils.kt | 7 ++++ .../src/main/kotlin/kordenum/KordEnum.kt | 36 +++++++++++++++++++ .../kotlin/kordenum/KordEnumGeneration.kt | 36 +++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt index 40b34a25c4f1..7cf954db59b9 100644 --- a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt +++ b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt @@ -2,6 +2,7 @@ package dev.kord.ksp +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE import kotlin.DeprecationLevel.WARNING import kotlin.annotation.AnnotationRetention.SOURCE import kotlin.annotation.AnnotationTarget.FILE @@ -24,8 +25,16 @@ annotation class GenerateKordEnum( val valueName: String = "value", /** [entries] of the kord enum that are [Deprecated]. [Entry.deprecationMessage] is required for these. */ val deprecatedEntries: Array = [], + + /** For migration purposes. */ + val valuesPropertyName: String = "", + /** For migration purposes. */ + val valuesPropertyType: ValuesPropertyType = NONE, + /** For migration purposes. */ + val valuesPropertyDeprecationLevel: DeprecationLevel = WARNING, ) { enum class ValueType { INT, STRING } + enum class ValuesPropertyType { NONE, SET } @Target() @Retention(SOURCE) diff --git a/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt b/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt index 1e5a6e734fab..7ebdeff0fdc7 100644 --- a/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt +++ b/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt @@ -77,6 +77,13 @@ internal inline fun FunSpec.Builder.addParameter(name: String) = add internal inline fun PropertySpec.Builder.delegate(builder: CodeBlock.Builder.() -> Unit) = delegate(CodeBlock.builder().apply(builder).build()) +internal inline fun PropertySpec.Builder.addAnnotation( + builder: AnnotationSpec.Builder.() -> Unit, +) = addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) + +internal inline fun PropertySpec.Builder.getter(builder: FunSpec.Builder.() -> Unit) = + getter(FunSpec.getterBuilder().apply(builder).build()) + // other diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt index b2f2c77e9cec..94a4112c8c23 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt @@ -4,6 +4,9 @@ import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSType import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET import dev.kord.ksp.GenerateKordEnum.ValueType import dev.kord.ksp.GenerateKordEnum.ValueType.INT import dev.kord.ksp.GenerateKordEnum.ValueType.STRING @@ -20,6 +23,11 @@ internal class KordEnum( val valueName: String, val entries: List, val deprecatedEntries: List, + + // for migration purposes + val valuesPropertyName: String?, + val valuesPropertyType: ValuesPropertyType, + val valuesPropertyDeprecationLevel: DeprecationLevel, ) { internal class Entry( val name: String, @@ -47,10 +55,31 @@ internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { val valueName = args[GenerateKordEnum::valueName] as String val deprecatedEntries = args[GenerateKordEnum::deprecatedEntries] as List<*> + val valuesPropertyName = (args[GenerateKordEnum::valuesPropertyName] as String).ifEmpty { null } + val valuesPropertyType = args[GenerateKordEnum::valuesPropertyType].toValuesPropertyType() + val valuesPropertyDeprecationLevel = args[GenerateKordEnum::valuesPropertyDeprecationLevel].toDeprecationLevel() + if (valuesPropertyName != null) { + if (valuesPropertyType == NONE) { + logger.error("Didn't specify valuesPropertyType", symbol = this) + return null + } + } else { + if (valuesPropertyType != NONE) { + logger.error("Specified valuesPropertyType", symbol = this) + return null + } + if (valuesPropertyDeprecationLevel != WARNING) { + logger.error("Specified valuesPropertyDeprecationLevel", symbol = this) + return null + } + } + return KordEnum( name, kDoc, valueType, valueName, entries.map { it.toEntryOrNull(valueType, deprecated = false, logger) ?: return null }, deprecatedEntries.map { it.toEntryOrNull(valueType, deprecated = true, logger) ?: return null }, + + valuesPropertyName, valuesPropertyType, valuesPropertyDeprecationLevel, ) } @@ -63,6 +92,13 @@ private fun Any?.toValueType() = when (val name = (this as KSType).declaration.q private fun Any?.toKDoc() = (this as String).trimIndent().ifBlank { null } +/** Maps [KSType] to [ValuesPropertyType]. */ +private fun Any?.toValuesPropertyType() = when (val name = (this as KSType).declaration.qualifiedName?.asString()) { + "dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE" -> NONE + "dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET" -> SET + else -> error("Unknown GenerateKordEnum.ValuesPropertyType: $name") +} + /** * Maps [KSAnnotation] for [GenerateKordEnum.Entry] to [Entry]. * diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 6f3c97b07189..c655fe0878de 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -9,6 +9,9 @@ import dev.kord.ksp.* import dev.kord.ksp.GenerateKordEnum.ValueType import dev.kord.ksp.GenerateKordEnum.ValueType.INT import dev.kord.ksp.GenerateKordEnum.ValueType.STRING +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET import dev.kord.ksp.kordenum.KordEnum.Entry import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable @@ -53,6 +56,16 @@ private fun ValueType.toPrimitiveKind() = when (this) { STRING -> PrimitiveKind.STRING::class } +private fun ValuesPropertyType.toClassName() = when (this) { + NONE -> error("did not expect NONE") + SET -> ClassName("kotlin.collections", "Set") +} + +private fun ValuesPropertyType.toFromListConversion() = when (this) { + NONE -> error("did not expect NONE") + SET -> ".toSet()" +} + internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { val packageName = originatingFile.packageName.asString() @@ -225,6 +238,29 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { endControlFlow() } } + + // @Deprecated( + // "Renamed to 'entries'.", + // ReplaceWith("this.entries"), + // level = , + // ) + // public val + if (valuesPropertyName != null) { + addProperty( + valuesPropertyName, + valuesPropertyType.toClassName().parameterizedBy(enumName), + PUBLIC, + ) { + addAnnotation { + addMember("%S", "Renamed to 'entries'.") + addMember("ReplaceWith(%S)", "this.entries") + addMember("level·=·%M", valuesPropertyDeprecationLevel.asMemberName()) + } + getter { + addStatement("return entries${valuesPropertyType.toFromListConversion()}") + } + } + } } } } From 35dd217674d89498fe4bf12767d4626f942977e7 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Thu, 14 Jul 2022 21:18:51 +0200 Subject: [PATCH 03/47] Generate MessageStickerType --- .../src/main/kotlin/entity/DiscordMessage.kt | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index 5194f5c945da..a729fec1bd2c 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -1,10 +1,25 @@ +@file:GenerateKordEnum( + name = "MessageStickerType", valueType = INT, + // had `public val values: Set` in companion before -> replace with `entries` + valuesPropertyName = "values", valuesPropertyDeprecationLevel = WARNING, valuesPropertyType = SET, + entries = [ + Entry("PNG", intValue = 1), + Entry("APNG", intValue = 2), + Entry("LOTTIE", intValue = 3), + ] +) + package dev.kord.common.entity +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.IntOrStringSerializer +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET import kotlinx.datetime.Instant import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName @@ -14,6 +29,7 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlin.DeprecationLevel.WARNING import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -163,35 +179,6 @@ public data class DiscordStickerItem( val formatType: MessageStickerType ) -@Serializable(with = MessageStickerType.Serializer::class) -public sealed class MessageStickerType(public val value: Int) { - public class Unknown(value: Int) : MessageStickerType(value) - public object PNG : MessageStickerType(1) - public object APNG : MessageStickerType(2) - public object LOTTIE : MessageStickerType(3) - - public companion object { - public val values: Set = setOf(PNG, APNG, LOTTIE) - } - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.MessageStickerType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): MessageStickerType = when (val value = decoder.decodeInt()) { - 1 -> PNG - 2 -> APNG - 3 -> LOTTIE - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: MessageStickerType) { - encoder.encodeInt(value.value) - } - } -} - - /** * Represents [a partial message sent in a channel within Discord](https://discord.com/developers/docs/resources/channel#message-object). * From 1c768a0fda658f70d9c3bd2a89a13ddea02f6a87 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 17 Jul 2022 14:45:44 +0200 Subject: [PATCH 04/47] Generate ChannelType --- .../src/main/kotlin/entity/DiscordChannel.kt | 171 ++++++++---------- .../src/main/kotlin/entity/DiscordMessage.kt | 2 +- .../behavior/channel/NewsChannelBehavior.kt | 2 +- .../behavior/channel/TextChannelBehavior.kt | 6 +- .../src/main/kotlin/entity/channel/Channel.kt | 5 +- .../channel/thread/TextChannelThread.kt | 2 +- .../gateway/handler/ThreadEventHandler.kt | 6 +- .../kotlin/supplier/CacheEntitySupplier.kt | 6 +- 8 files changed, 92 insertions(+), 108 deletions(-) diff --git a/common/src/main/kotlin/entity/DiscordChannel.kt b/common/src/main/kotlin/entity/DiscordChannel.kt index a5269b2f656f..5cdf12d7885a 100644 --- a/common/src/main/kotlin/entity/DiscordChannel.kt +++ b/common/src/main/kotlin/entity/DiscordChannel.kt @@ -1,12 +1,89 @@ +@file:GenerateKordEnum( + name = "ChannelType", valueType = INT, + entries = [ + Entry("GuildText", intValue = 0, kDoc = "A text channel within a server."), + Entry("DM", intValue = 1, kDoc = "A direct message between users."), + Entry("GuildVoice", intValue = 2, kDoc = "A voice channel within a server."), + Entry("GroupDM", intValue = 3, kDoc = "A direct message between multiple users."), + Entry( + "GuildCategory", intValue = 4, + kDoc = """ + An + [organizational·category](https://support.discord.com/hc/en-us/articles/115001580171-Channel-Categories-101) + that contains up to 50 channels. + """, + ), + Entry( + "GuildNews", intValue = 5, + kDoc = """ + A channel that + [users·can·follow·and·crosspost·into·their·own·server](https://support.discord.com/hc/en-us/articles/360032008192). + """, + ), + Entry("GuildNewsThread", intValue = 10, kDoc = "A temporary sub-channel within a [GuildNews] channel."), + Entry("GuildPublicThread", intValue = 11, kDoc = "A temporary sub-channel within a [GuildText] channel."), + Entry( + "GuildPrivateThread", intValue = 12, + kDoc = """ + A temporary sub-channel within a [GuildText] channel that is only viewable by those invited and those with + the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission. + """, + ), + Entry( + "GuildStageVoice", intValue = 13, + kDoc = """ + A voice channel for + [hosting·events·with·an·audience](https://support.discord.com/hc/en-us/articles/1500005513722). + """, + ), + Entry( + "GuildDirectory", intValue = 14, + kDoc = """ + The channel in a [hub](https://support.discord.com/hc/en-us/articles/4406046651927-Discord-Student-Hubs-FAQ) + containing the listed servers. + """, + ), + ], + deprecatedEntries = [ + Entry( + "GuildStore", intValue = 6, kDoc = "A channel in which game developers can sell their game on Discord.", + deprecationMessage = "Discord no longer offers the ability to purchase a license to sell PC games on " + + "Discord and store channels were removed on March 10, 2022.\n\n" + + "See https://support-dev.discord.com/hc/en-us/articles/4414590563479 for more information.", + deprecationLevel = WARNING, + ), + Entry( + "PublicNewsThread", intValue = 10, + deprecationMessage = "Renamed to 'GuildNewsThread'", + replaceWith = ReplaceWith("GuildNewsThread", "dev.kord.common.entity.ChannelType.GuildNewsThread"), + deprecationLevel = WARNING, + ), + Entry( + "PublicGuildThread", intValue = 11, + deprecationMessage = "Renamed to 'GuildPublicThread'", + replaceWith = ReplaceWith("GuildPublicThread", "dev.kord.common.entity.ChannelType.GuildPublicThread"), + deprecationLevel = WARNING, + ), + Entry( + "PrivateThread", intValue = 12, + deprecationMessage = "Renamed to 'GuildPrivateThread'", + replaceWith = ReplaceWith("GuildPrivateThread", "dev.kord.common.entity.ChannelType.GuildPrivateThread"), + deprecationLevel = WARNING, + ), + ], +) + package dev.kord.common.entity -import dev.kord.common.entity.Permission.ManageThreads import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.DurationInMinutesSerializer import dev.kord.common.serialization.DurationInSeconds +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.datetime.Instant import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName @@ -88,98 +165,6 @@ public data class DiscordChannel( val member: Optional = Optional.Missing() ) -@Serializable(with = ChannelType.Serializer::class) -public sealed class ChannelType(public val value: Int) { - - /** The default code for unknown values. */ - public class Unknown(value: Int) : ChannelType(value) - - /** A text channel within a server. */ - public object GuildText : ChannelType(0) - - /** A direct message between users. */ - public object DM : ChannelType(1) - - /** A voice channel within a server. */ - public object GuildVoice : ChannelType(2) - - /** A direct message between multiple users. */ - public object GroupDM : ChannelType(3) - - /** - * An [organizational category](https://support.discord.com/hc/en-us/articles/115001580171-Channel-Categories-101) - * that contains up to 50 channels. - */ - public object GuildCategory : ChannelType(4) - - /** - * A channel that - * [users can follow and crosspost into their own server](https://support.discord.com/hc/en-us/articles/360032008192). - */ - public object GuildNews : ChannelType(5) - - /** A channel in which game developers can sell their game on Discord. */ - @Deprecated( - """ - Discord no longer offers the ability to purchase a license to sell PC games on Discord and store channels were - removed on March 10, 2022. - - See https://support-dev.discord.com/hc/en-us/articles/4414590563479 for more information. - """, - level = WARNING, - ) - public object GuildStore : ChannelType(6) - - /** A temporary sub-channel within a [GuildNews] channel. */ - public object PublicNewsThread : ChannelType(10) - - /** A temporary sub-channel within a [GuildText] channel. */ - public object PublicGuildThread : ChannelType(11) - - /** - * A temporary sub-channel within a [GuildText] channel that is only viewable by those invited and those with the - * [ManageThreads] permission. - */ - public object PrivateThread : ChannelType(12) - - /** - * A voice channel for - * [hosting events with an audience](https://support.discord.com/hc/en-us/articles/1500005513722). - */ - public object GuildStageVoice : ChannelType(13) - - /** - * The channel in a [hub](https://support.discord.com/hc/en-us/articles/4406046651927-Discord-Student-Hubs-FAQ) - * containing the listed servers. - */ - public object GuildDirectory : ChannelType(14) - - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("type", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): ChannelType = when (val code = decoder.decodeInt()) { - 0 -> GuildText - 1 -> DM - 2 -> GuildVoice - 3 -> GroupDM - 4 -> GuildCategory - 5 -> GuildNews - 6 -> @Suppress("DEPRECATION") GuildStore - 10 -> PublicNewsThread - 11 -> PublicGuildThread - 12 -> PrivateThread - 13 -> GuildStageVoice - 14 -> GuildDirectory - else -> Unknown(code) - } - - override fun serialize(encoder: Encoder, value: ChannelType) = encoder.encodeInt(value.value) - } - -} - @Serializable public data class Overwrite( val id: Snowflake, diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index a729fec1bd2c..59404c207055 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -6,7 +6,7 @@ Entry("PNG", intValue = 1), Entry("APNG", intValue = 2), Entry("LOTTIE", intValue = 3), - ] + ], ) package dev.kord.common.entity diff --git a/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt b/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt index 3f37230a1cc3..fc8ba60627be 100644 --- a/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt +++ b/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt @@ -87,7 +87,7 @@ public interface NewsChannelBehavior : ThreadParentChannelBehavior { archiveDuration: ArchiveDuration = ArchiveDuration.Day, reason: String? = null ): NewsChannelThread { - return unsafeStartThread(name, archiveDuration, ChannelType.PublicNewsThread) { this.reason = reason } as NewsChannelThread + return unsafeStartThread(name, archiveDuration, ChannelType.GuildNewsThread) { this.reason = reason } as NewsChannelThread } public suspend fun startPublicThreadWithMessage( diff --git a/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt b/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt index 94f7024e6425..1f1432e3a2e6 100644 --- a/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt +++ b/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt @@ -73,7 +73,7 @@ public interface TextChannelBehavior : PrivateThreadParentChannelBehavior { return unsafeStartThread( name, archiveDuration, - ChannelType.PublicGuildThread, + ChannelType.GuildPublicThread, builder ) as TextChannelThread } @@ -83,8 +83,8 @@ public interface TextChannelBehavior : PrivateThreadParentChannelBehavior { archiveDuration: ArchiveDuration = ArchiveDuration.Day, builder: StartThreadBuilder.() -> Unit = {} ): TextChannelThread { - val startBuilder = StartThreadBuilder(name, archiveDuration, ChannelType.PrivateThread).apply(builder) - return unsafeStartThread(startBuilder.name, startBuilder.autoArchiveDuration, ChannelType.PrivateThread, builder) as TextChannelThread + val startBuilder = StartThreadBuilder(name, archiveDuration, ChannelType.GuildPrivateThread).apply(builder) + return unsafeStartThread(startBuilder.name, startBuilder.autoArchiveDuration, ChannelType.GuildPrivateThread, builder) as TextChannelThread } public suspend fun startPublicThreadWithMessage( diff --git a/core/src/main/kotlin/entity/channel/Channel.kt b/core/src/main/kotlin/entity/channel/Channel.kt index b9e25eb9c37d..59638ec2b5ed 100644 --- a/core/src/main/kotlin/entity/channel/Channel.kt +++ b/core/src/main/kotlin/entity/channel/Channel.kt @@ -50,9 +50,8 @@ public interface Channel : ChannelBehavior { GuildCategory -> Category(data, kord) GuildNews -> NewsChannel(data, kord) @Suppress("DEPRECATION") GuildStore -> @Suppress("DEPRECATION") StoreChannel(data, kord) - PublicNewsThread -> NewsChannelThread(data, kord) - PrivateThread -> TextChannelThread(data, kord) - PublicGuildThread -> TextChannelThread(data, kord) + GuildNewsThread -> NewsChannelThread(data, kord) + GuildPrivateThread, GuildPublicThread -> TextChannelThread(data, kord) else -> { if (data.threadMetadata.value == null) Channel(data, kord, strategy.supply(kord)) diff --git a/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt b/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt index b02116aea81e..5dbbdba60e29 100644 --- a/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt +++ b/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt @@ -22,7 +22,7 @@ public class TextChannelThread( /** * Whether this thread is private. */ - public val isPrivate: Boolean get() = data.type == ChannelType.PrivateThread + public val isPrivate: Boolean get() = data.type == ChannelType.GuildPrivateThread /** * Whether non-moderators can add other non-moderators to a thread. diff --git a/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt b/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt index 9c93815022ca..a669c919d5bb 100644 --- a/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt +++ b/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt @@ -77,14 +77,14 @@ public class ThreadEventHandler( val channel = DeletedThreadChannel(channelData, kord) val old = cachedData?.let { Channel.from(cachedData, kord) } val coreEvent = when (channel.type) { - is ChannelType.PublicNewsThread -> NewsChannelThreadDeleteEvent( + ChannelType.GuildNewsThread -> NewsChannelThreadDeleteEvent( channel, old as? NewsChannelThread, shard, coroutineScope = coroutineScope ) - is ChannelType.PrivateThread, - is ChannelType.GuildText -> TextChannelThreadDeleteEvent(channel, old as? TextChannelThread, shard, coroutineScope) + ChannelType.GuildPrivateThread, + ChannelType.GuildPublicThread -> TextChannelThreadDeleteEvent(channel, old as? TextChannelThread, shard, coroutineScope) else -> UnknownChannelThreadDeleteEvent(channel, old as? ThreadChannel, shard, coroutineScope) } diff --git a/core/src/main/kotlin/supplier/CacheEntitySupplier.kt b/core/src/main/kotlin/supplier/CacheEntitySupplier.kt index 04debe6b0b71..64206b0219cb 100644 --- a/core/src/main/kotlin/supplier/CacheEntitySupplier.kt +++ b/core/src/main/kotlin/supplier/CacheEntitySupplier.kt @@ -335,7 +335,7 @@ public class CacheEntitySupplier(private val kord: Kord) : EntitySupplier { it.threadMetadata.value?.archived == true && time != null && (before == null || time < before) - && (it.type == ChannelType.PublicGuildThread || it.type == ChannelType.PublicNewsThread) + && (it.type == ChannelType.GuildPublicThread || it.type == ChannelType.GuildNewsThread) } .limit(limit) .mapNotNull { Channel.from(it, kord) as? ThreadChannel } @@ -356,7 +356,7 @@ public class CacheEntitySupplier(private val kord: Kord) : EntitySupplier { it.threadMetadata.value?.archived == true && time != null && (before == null || time < before) - && it.type == ChannelType.PrivateThread + && it.type == ChannelType.GuildPrivateThread } .limit(limit) .mapNotNull { Channel.from(it, kord) as? ThreadChannel } @@ -379,7 +379,7 @@ public class CacheEntitySupplier(private val kord: Kord) : EntitySupplier { .filter { it.threadMetadata.value?.archived == true && (before == null || it.id < before) - && it.type == ChannelType.PrivateThread + && it.type == ChannelType.GuildPrivateThread && it.member !is Optional.Missing } .limit(limit) From eb2be55b7cd0c63ac02bdec16edb361671332c50 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Tue, 19 Jul 2022 20:53:25 +0200 Subject: [PATCH 05/47] Suppress errors for `HIDDEN` entries --- ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index c655fe0878de..bfd933227609 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -29,8 +29,7 @@ private val Entry.warningSuppressedName isDeprecated -> "@Suppress(\"${ when (deprecationLevel) { WARNING -> "DEPRECATION" - ERROR -> "DEPRECATION_ERROR" - HIDDEN -> TODO("How can we use HIDDEN symbols? (if at all)") + ERROR, HIDDEN -> "DEPRECATION_ERROR" } }\")·$name" else -> name From 4ef0576b2011ca15f0bdd689d372c1bef5e3c7bf Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 24 Jul 2022 19:37:39 +0200 Subject: [PATCH 06/47] Use annotation constructors, small other changes --- .../src/main/kotlin/entity/DiscordChannel.kt | 4 +- .../src/main/kotlin/GenerateKordEnum.kt | 13 +-- ksp-processors/src/main/kotlin/KSPUtils.kt | 4 +- .../src/main/kotlin/KotlinPoetUtils.kt | 49 +++++---- .../src/main/kotlin/kordenum/KordEnum.kt | 31 +++--- .../kotlin/kordenum/KordEnumGeneration.kt | 101 ++++++++---------- 6 files changed, 96 insertions(+), 106 deletions(-) diff --git a/common/src/main/kotlin/entity/DiscordChannel.kt b/common/src/main/kotlin/entity/DiscordChannel.kt index 2bcca6954a70..0282bb793afb 100644 --- a/common/src/main/kotlin/entity/DiscordChannel.kt +++ b/common/src/main/kotlin/entity/DiscordChannel.kt @@ -48,8 +48,8 @@ Entry( "GuildStore", intValue = 6, kDoc = "A channel in which game developers can sell their game on Discord.", deprecationMessage = "Discord no longer offers the ability to purchase a license to sell PC games on " + - "Discord and store channels were removed on March 10, 2022.\n\n" + - "See https://support-dev.discord.com/hc/en-us/articles/4414590563479 for more information.", + "Discord and store channels were removed on March 10, 2022. See " + + "https://support-dev.discord.com/hc/en-us/articles/4414590563479 for more information.", deprecationLevel = ERROR, ), Entry( diff --git a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt index 7cf954db59b9..de526ac62b9b 100644 --- a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt +++ b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt @@ -1,17 +1,18 @@ -@file:Suppress("unused") - package dev.kord.ksp +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType +import dev.kord.ksp.GenerateKordEnum.ValueType.INT +import dev.kord.ksp.GenerateKordEnum.ValueType.STRING import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE import kotlin.DeprecationLevel.WARNING import kotlin.annotation.AnnotationRetention.SOURCE import kotlin.annotation.AnnotationTarget.FILE -import dev.kord.ksp.GenerateKordEnum.ValueType.* /** Generate a kord enum in the same package as this file. */ -@Target(FILE) -@Retention(SOURCE) @Repeatable +@Retention(SOURCE) +@Target(FILE) annotation class GenerateKordEnum( /** Name of the kord enum. */ val name: String, @@ -36,8 +37,8 @@ annotation class GenerateKordEnum( enum class ValueType { INT, STRING } enum class ValuesPropertyType { NONE, SET } - @Target() @Retention(SOURCE) + @Target() // only use as argument for `@GenerateKordEnum(...)` annotation class Entry( /** Name of the entry. */ val name: String, diff --git a/ksp-processors/src/main/kotlin/KSPUtils.kt b/ksp-processors/src/main/kotlin/KSPUtils.kt index 1a7928aa3091..ff2ded55e8a4 100644 --- a/ksp-processors/src/main/kotlin/KSPUtils.kt +++ b/ksp-processors/src/main/kotlin/KSPUtils.kt @@ -4,8 +4,8 @@ import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotation import kotlin.reflect.KProperty1 -internal inline fun Resolver.getSymbolsWithAnnotation() = - getSymbolsWithAnnotation(A::class.qualifiedName!!) +internal inline fun Resolver.getSymbolsWithAnnotation(inDepth: Boolean = false) = + getSymbolsWithAnnotation(A::class.qualifiedName!!, inDepth) internal inline fun KSAnnotation.isOfType() = shortName.asString() == A::class.simpleName!! && annotationType.resolve().declaration.qualifiedName?.asString() == A::class.qualifiedName!! diff --git a/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt b/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt index 7ebdeff0fdc7..7b0c755a8bff 100644 --- a/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt +++ b/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt @@ -2,43 +2,36 @@ package dev.kord.ksp import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.MemberName.Companion.member -import kotlin.reflect.KClass // standalone -internal inline fun fileSpec(packageName: String, fileName: String, builder: FileSpec.Builder.() -> Unit) = +internal inline fun FileSpec(packageName: String, fileName: String, builder: FileSpec.Builder.() -> Unit) = FileSpec.builder(packageName, fileName).apply(builder).build() -internal inline fun annotationSpec(builder: AnnotationSpec.Builder.() -> Unit) = - AnnotationSpec.builder(A::class).apply(builder).build() - // FileSpec.Builder internal inline fun FileSpec.Builder.addClass(className: ClassName, builder: TypeSpec.Builder.() -> Unit) = addType(TypeSpec.classBuilder(className).apply(builder).build()) -internal inline fun FileSpec.Builder.addAnnotation( - builder: AnnotationSpec.Builder.() -> Unit, -) = addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) +@DelicateKotlinPoetApi("See 'AnnotationSpec.get'") +internal fun FileSpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = + addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) // TypeSpec.Builder internal inline fun TypeSpec.Builder.addAnnotation( builder: AnnotationSpec.Builder.() -> Unit, -) = addAnnotation(AnnotationSpec.Companion.builder(A::class).apply(builder).build()) +) = addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) + +@DelicateKotlinPoetApi("See 'AnnotationSpec.get'") +internal fun TypeSpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = + addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) internal inline fun TypeSpec.Builder.primaryConstructor(builder: FunSpec.Builder.() -> Unit) = primaryConstructor(FunSpec.constructorBuilder().apply(builder).build()) -internal inline fun TypeSpec.Builder.addProperty( - name: String, - type: KClass<*>, - vararg modifiers: KModifier, - builder: PropertySpec.Builder.() -> Unit, -) = addProperty(PropertySpec.builder(name, type, *modifiers).apply(builder).build()) - internal inline fun TypeSpec.Builder.addProperty( name: String, vararg modifiers: KModifier, @@ -69,7 +62,14 @@ internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, bu internal inline fun FunSpec.Builder.returns() = returns(typeNameOf()) -internal inline fun FunSpec.Builder.addParameter(name: String) = addParameter(name, typeNameOf()) +internal inline fun FunSpec.Builder.addParameter(name: String, vararg modifiers: KModifier) = + addParameter(name, typeNameOf(), *modifiers) + +internal inline fun FunSpec.Builder.withControlFlow( + controlFlow: String, + vararg args: Any, + builder: FunSpec.Builder.() -> Unit, +) = beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() // PropertySpec.Builder @@ -77,14 +77,23 @@ internal inline fun FunSpec.Builder.addParameter(name: String) = add internal inline fun PropertySpec.Builder.delegate(builder: CodeBlock.Builder.() -> Unit) = delegate(CodeBlock.builder().apply(builder).build()) -internal inline fun PropertySpec.Builder.addAnnotation( - builder: AnnotationSpec.Builder.() -> Unit, -) = addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) +@DelicateKotlinPoetApi("See 'AnnotationSpec.get'") +internal fun PropertySpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = + addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) internal inline fun PropertySpec.Builder.getter(builder: FunSpec.Builder.() -> Unit) = getter(FunSpec.getterBuilder().apply(builder).build()) +// CodeBlock.Builder + +internal inline fun CodeBlock.Builder.withControlFlow( + controlFlow: String, + vararg args: Any?, + builder: CodeBlock.Builder.() -> Unit, +) = beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() + + // other internal inline fun > E.asMemberName() = E::class.member(name) diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt index 94a4112c8c23..83b7caea2079 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt @@ -4,12 +4,12 @@ import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSType import dev.kord.ksp.GenerateKordEnum -import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType -import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE -import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET import dev.kord.ksp.GenerateKordEnum.ValueType import dev.kord.ksp.GenerateKordEnum.ValueType.INT import dev.kord.ksp.GenerateKordEnum.ValueType.STRING +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE +import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET import dev.kord.ksp.argumentsToMap import dev.kord.ksp.get import dev.kord.ksp.kordenum.KordEnum.Entry @@ -34,9 +34,9 @@ internal class KordEnum( val kDoc: String?, val value: Comparable<*>, val isDeprecated: Boolean, - val deprecationMessage: String = "", - val replaceWith: ReplaceWith? = null, - val deprecationLevel: DeprecationLevel = WARNING, + val deprecationMessage: String, + val replaceWith: ReplaceWith, + val deprecationLevel: DeprecationLevel, ) } @@ -76,8 +76,8 @@ internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { return KordEnum( name, kDoc, valueType, valueName, - entries.map { it.toEntryOrNull(valueType, deprecated = false, logger) ?: return null }, - deprecatedEntries.map { it.toEntryOrNull(valueType, deprecated = true, logger) ?: return null }, + entries.map { it.toEntryOrNull(valueType, isDeprecated = false, logger) ?: return null }, + deprecatedEntries.map { it.toEntryOrNull(valueType, isDeprecated = true, logger) ?: return null }, valuesPropertyName, valuesPropertyType, valuesPropertyDeprecationLevel, ) @@ -104,7 +104,7 @@ private fun Any?.toValuesPropertyType() = when (val name = (this as KSType).decl * * Returns `null` if mapping fails. */ -private fun Any?.toEntryOrNull(valueType: ValueType, deprecated: Boolean, logger: KSPLogger): Entry? { +private fun Any?.toEntryOrNull(valueType: ValueType, isDeprecated: Boolean, logger: KSPLogger): Entry? { val args = (this as KSAnnotation).argumentsToMap() val name = args[GenerateKordEnum.Entry::name] as String @@ -142,18 +142,11 @@ private fun Any?.toEntryOrNull(valueType: ValueType, deprecated: Boolean, logger } } - return if (deprecated) { + if (isDeprecated) { if (deprecationMessage.isBlank()) { logger.error("deprecationMessage is required", symbol = this) return null } - - Entry( - name, kDoc, value, isDeprecated = true, - deprecationMessage, - replaceWith.takeIf { it.expression.isNotBlank() }, - deprecationLevel, - ) } else { if (deprecationMessage.isNotEmpty()) { logger.error("deprecationMessage is not allowed", symbol = this) @@ -167,9 +160,9 @@ private fun Any?.toEntryOrNull(valueType: ValueType, deprecated: Boolean, logger logger.error("deprecationLevel is not allowed", symbol = this) return null } - - Entry(name, kDoc, value, isDeprecated = false) } + + return Entry(name, kDoc, value, isDeprecated, deprecationMessage, replaceWith, deprecationLevel) } /** Maps [KSAnnotation] to [ReplaceWith]. */ diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index bfd933227609..5eba80853a67 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlin.DeprecationLevel.* import kotlin.LazyThreadSafetyMode.PUBLICATION +import com.squareup.kotlinpoet.INT as INT_CLASS_NAME +import com.squareup.kotlinpoet.SET as SET_CLASS_NAME +import com.squareup.kotlinpoet.STRING as STRING_CLASS_NAME private val PRIMITIVE_SERIAL_DESCRIPTOR = MemberName("kotlinx.serialization.descriptors", "PrimitiveSerialDescriptor") @@ -35,9 +38,9 @@ private val Entry.warningSuppressedName else -> name } -private fun ValueType.toKClass() = when (this) { - INT -> Int::class - STRING -> String::class +private fun ValueType.toClassName() = when (this) { + INT -> INT_CLASS_NAME + STRING -> STRING_CLASS_NAME } private fun ValueType.toEncodingPostfix() = when (this) { @@ -56,12 +59,12 @@ private fun ValueType.toPrimitiveKind() = when (this) { } private fun ValuesPropertyType.toClassName() = when (this) { - NONE -> error("did not expect NONE") - SET -> ClassName("kotlin.collections", "Set") + NONE -> error("did not expect $this") + SET -> SET_CLASS_NAME } private fun ValuesPropertyType.toFromListConversion() = when (this) { - NONE -> error("did not expect NONE") + NONE -> error("did not expect $this") SET -> ".toSet()" } @@ -69,7 +72,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { val packageName = originatingFile.packageName.asString() val enumName = ClassName(packageName, name) - val valueKClass = valueType.toKClass() + val valueTypeName = valueType.toClassName() val encodingPostfix = valueType.toEncodingPostfix() val valueFormat = valueType.toFormat() @@ -86,15 +89,14 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } } - return fileSpec(packageName, fileName = name) { + return FileSpec(packageName, fileName = name) { indent(" ") - addAnnotation { - addMember("%S, %S, %S", "UnusedImport", "RedundantVisibilityModifier", "IncorrectFormatting") - } + @OptIn(DelicateKotlinPoetApi::class) // `AnnotationSpec.get` is ok for `Suppress` + addAnnotation(Suppress("RedundantVisibilityModifier", "IncorrectFormatting", "ReplaceArrayOfWithLiteral")) // /** */ // @Serializable(with = .Serializer::class) - // public sealed class (public val : ) + // public sealed class (public val : ]. */ - // public class Unknown(: ) : () + // public class Unknown(: ) : () addClass("Unknown") { addKdoc("An unknown [%T].", enumName) addModifiers(PUBLIC) primaryConstructor { - addParameter(valueName, valueKClass) + addParameter(valueName, valueTypeName) } superclass(enumName) addSuperclassConstructorParameter(valueName) @@ -157,27 +159,13 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } // /** */ - // @Deprecated(, , level = ) + // @Deprecated(, , ) // public object : () for (entry in deprecatedEntries) { addObject(entry.name) { entry(entry) - addAnnotation { - addMember("%S", entry.deprecationMessage) - - // replacement if present - entry.replaceWith?.let { replaceWith -> - addMember("%L", annotationSpec { - addMember("%S", replaceWith.expression) - val imports = replaceWith.imports - if (imports.isNotEmpty()) { - addMember(imports.joinToString { "%S" }, *imports) - } - }) - } - - addMember("level·=·%M", entry.deprecationLevel.asMemberName()) - } + @OptIn(DelicateKotlinPoetApi::class) // `AnnotationSpec.get` is ok for `Deprecated` + addAnnotation(Deprecated(entry.deprecationMessage, entry.replaceWith, entry.deprecationLevel)) } } @@ -209,12 +197,12 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addFunction("deserialize") { addModifiers(OVERRIDE) addParameter("decoder") - beginControlFlow("return when·(val·$valueName·=·decoder.decode$encodingPostfix())") - for (entry in relevantEntriesForSerializerAndCompanion) { - addStatement("$valueFormat·->·${entry.warningSuppressedName}", entry.value) + withControlFlow("return when·(val·$valueName·=·decoder.decode$encodingPostfix())") { + for (entry in relevantEntriesForSerializerAndCompanion) { + addStatement("$valueFormat·->·${entry.warningSuppressedName}", entry.value) + } + addStatement("else·->·Unknown($valueName)") } - addStatement("else·->·Unknown($valueName)") - endControlFlow() } } @@ -224,37 +212,36 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addModifiers(PUBLIC) // public val entries - addProperty("entries", List::class.asClassName().parameterizedBy(enumName), PUBLIC) { + addProperty("entries", LIST.parameterizedBy(enumName), PUBLIC) { delegate { - beginControlFlow("lazy(mode·=·%M)", PUBLICATION.asMemberName()) - addStatement("listOf(") - withIndent { - for (entry in relevantEntriesForSerializerAndCompanion) { - addStatement("${entry.warningSuppressedName},") + withControlFlow("lazy(mode·=·%M)", PUBLICATION.asMemberName()) { + addStatement("listOf(") + withIndent { + for (entry in relevantEntriesForSerializerAndCompanion) { + addStatement("${entry.warningSuppressedName},") + } } + addStatement(")") } - addStatement(")") - endControlFlow() } } - // @Deprecated( - // "Renamed to 'entries'.", - // ReplaceWith("this.entries"), - // level = , - // ) - // public val + // @Deprecated("Renamed to 'entries'.", ReplaceWith("this.entries"), ) + // public val if (valuesPropertyName != null) { addProperty( valuesPropertyName, valuesPropertyType.toClassName().parameterizedBy(enumName), PUBLIC, ) { - addAnnotation { - addMember("%S", "Renamed to 'entries'.") - addMember("ReplaceWith(%S)", "this.entries") - addMember("level·=·%M", valuesPropertyDeprecationLevel.asMemberName()) - } + @OptIn(DelicateKotlinPoetApi::class) // `AnnotationSpec.get` is ok for `Deprecated` + addAnnotation( + Deprecated( + "Renamed to 'entries'.", + ReplaceWith("this.entries", imports = emptyArray()), + valuesPropertyDeprecationLevel, + ) + ) getter { addStatement("return entries${valuesPropertyType.toFromListConversion()}") } From 56360df6d46432bf17ee5669b297a1592c3da070 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 26 Aug 2022 19:50:31 +0200 Subject: [PATCH 07/47] Fix errors after merge --- buildSrc/src/main/kotlin/Compiler.kt | 2 +- .../kotlin/kord-internal-module.gradle.kts | 4 ++-- common/api/common.api | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/Compiler.kt b/buildSrc/src/main/kotlin/Compiler.kt index a6e2153ad3cc..fdaab3af2ca1 100644 --- a/buildSrc/src/main/kotlin/Compiler.kt +++ b/buildSrc/src/main/kotlin/Compiler.kt @@ -18,7 +18,7 @@ object Jvm { } fun KotlinJvmOptions.kordJvmOptions() { - jvmTarget = Jvm.target + jvmTarget = Jvm.targetString allWarningsAsErrors = true freeCompilerArgs += CompilerArguments.progressive } diff --git a/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts index 8ac0e450cfbd..1c07b5bca0c4 100644 --- a/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts @@ -10,8 +10,8 @@ repositories { tasks { withType { - sourceCompatibility = Jvm.target - targetCompatibility = Jvm.target + sourceCompatibility = Jvm.targetString + targetCompatibility = Jvm.targetString } withType { diff --git a/common/api/common.api b/common/api/common.api index dfab18a467e2..50435d5988c3 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -1191,10 +1191,13 @@ public final class dev/kord/common/entity/ButtonStyle$Unknown : dev/kord/common/ public abstract class dev/kord/common/entity/ChannelType { public static final field Companion Ldev/kord/common/entity/ChannelType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/ChannelType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -1218,6 +1221,18 @@ public final class dev/kord/common/entity/ChannelType$GuildNews : dev/kord/commo public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildNews; } +public final class dev/kord/common/entity/ChannelType$GuildNewsThread : dev/kord/common/entity/ChannelType { + public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildNewsThread; +} + +public final class dev/kord/common/entity/ChannelType$GuildPrivateThread : dev/kord/common/entity/ChannelType { + public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildPrivateThread; +} + +public final class dev/kord/common/entity/ChannelType$GuildPublicThread : dev/kord/common/entity/ChannelType { + public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildPublicThread; +} + public final class dev/kord/common/entity/ChannelType$GuildStageVoice : dev/kord/common/entity/ChannelType { public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildStageVoice; } @@ -6438,7 +6453,9 @@ public final class dev/kord/common/entity/MessageReactionRemoveData$Companion { public abstract class dev/kord/common/entity/MessageStickerType { public static final field Companion Ldev/kord/common/entity/MessageStickerType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/MessageStickerType$APNG : dev/kord/common/entity/MessageStickerType { @@ -6446,6 +6463,7 @@ public final class dev/kord/common/entity/MessageStickerType$APNG : dev/kord/com } public final class dev/kord/common/entity/MessageStickerType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun getValues ()Ljava/util/Set; public final fun serializer ()Lkotlinx/serialization/KSerializer; } From f8b515573db5020e43ca6cf53038fa1ffa6884b6 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 26 Aug 2022 20:26:35 +0200 Subject: [PATCH 08/47] Include generated symbols in dokka output --- buildSrc/src/main/kotlin/kord-module.gradle.kts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 7fd5e7484880..0cce0be44e39 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -81,6 +81,9 @@ tasks { externalDocumentationLink("https://kotlinlang.org/api/kotlinx.serialization/") externalDocumentationLink("https://api.ktor.io/") + // include docs for files generated by ksp + suppressGeneratedFiles.set(false) + // don't list `TweetNaclFast` in docs perPackageOption { matchingRegex.set("""com\.iwebpp\.crypto""") From af13bbb9ad860f521c0bf5c52b9e781351c61f0f Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 26 Aug 2022 22:06:15 +0200 Subject: [PATCH 09/47] Check ksp output into vcs --- .gitignore | 6 +- .../dev/kord/common/entity/ChannelType.kt | 171 ++++++++++++++++++ .../kord/common/entity/MessageStickerType.kt | 79 ++++++++ .../kotlin/kordenum/KordEnumGeneration.kt | 2 + 4 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt diff --git a/.gitignore b/.gitignore index b0e37fe09644..e87f660a34c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ .gradle/ .idea/ -build/ out/ dokka/ + +**/build/* +!**/build/generated/ +# re-exclude BuildConfigGenerated.kt +common/build/generated/source/buildConfig/main/main/dev/kord/common/BuildConfigGenerated.kt diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt new file mode 100644 index 000000000000..0da7e435c5cc --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -0,0 +1,171 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +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 +import kotlin.LazyThreadSafetyMode.PUBLICATION + +@Serializable(with = ChannelType.Serializer::class) +public sealed class ChannelType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || (other is ChannelType + && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [ChannelType]. + */ + public class Unknown( + `value`: Int, + ) : ChannelType(value) + + /** + * A text channel within a server. + */ + public object GuildText : ChannelType(0) + + /** + * A direct message between users. + */ + public object DM : ChannelType(1) + + /** + * A voice channel within a server. + */ + public object GuildVoice : ChannelType(2) + + /** + * A direct message between multiple users. + */ + public object GroupDM : ChannelType(3) + + /** + * An + * [organizational category](https://support.discord.com/hc/en-us/articles/115001580171-Channel-Categories-101) + * that contains up to 50 channels. + */ + public object GuildCategory : ChannelType(4) + + /** + * A channel that + * [users can follow and crosspost into their own server](https://support.discord.com/hc/en-us/articles/360032008192). + */ + public object GuildNews : ChannelType(5) + + /** + * A temporary sub-channel within a [GuildNews] channel. + */ + public object GuildNewsThread : ChannelType(10) + + /** + * A temporary sub-channel within a [GuildText] channel. + */ + public object GuildPublicThread : ChannelType(11) + + /** + * A temporary sub-channel within a [GuildText] channel that is only viewable by those invited + * and those with + * the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission. + */ + public object GuildPrivateThread : ChannelType(12) + + /** + * A voice channel for + * [hosting events with an audience](https://support.discord.com/hc/en-us/articles/1500005513722). + */ + public object GuildStageVoice : ChannelType(13) + + /** + * The channel in a + * [hub](https://support.discord.com/hc/en-us/articles/4406046651927-Discord-Student-Hubs-FAQ) + * containing the listed servers. + */ + public object GuildDirectory : ChannelType(14) + + /** + * A channel in which game developers can sell their game on Discord. + * + * @suppress + */ + @Deprecated( + level = DeprecationLevel.ERROR, + message = + "Discord no longer offers the ability to purchase a license to sell PC games on Discord and store channels were removed on March 10, 2022. See https://support-dev.discord.com/hc/en-us/articles/4414590563479 for more information.", + ) + public object GuildStore : ChannelType(6) + + @Deprecated( + message = "Renamed to 'GuildNewsThread'", + replaceWith = ReplaceWith(expression = "GuildNewsThread", imports = + arrayOf("dev.kord.common.entity.ChannelType.GuildNewsThread")), + ) + public object PublicNewsThread : ChannelType(10) + + @Deprecated( + message = "Renamed to 'GuildPublicThread'", + replaceWith = ReplaceWith(expression = "GuildPublicThread", imports = + arrayOf("dev.kord.common.entity.ChannelType.GuildPublicThread")), + ) + public object PublicGuildThread : ChannelType(11) + + @Deprecated( + message = "Renamed to 'GuildPrivateThread'", + replaceWith = ReplaceWith(expression = "GuildPrivateThread", imports = + arrayOf("dev.kord.common.entity.ChannelType.GuildPrivateThread")), + ) + public object PrivateThread : ChannelType(12) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ChannelType", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ChannelType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> GuildText + 1 -> DM + 2 -> GuildVoice + 3 -> GroupDM + 4 -> GuildCategory + 5 -> GuildNews + 6 -> @Suppress("DEPRECATION_ERROR") GuildStore + 10 -> GuildNewsThread + 11 -> GuildPublicThread + 12 -> GuildPrivateThread + 13 -> GuildStageVoice + 14 -> GuildDirectory + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + GuildText, + DM, + GuildVoice, + GroupDM, + GuildCategory, + GuildNews, + @Suppress("DEPRECATION_ERROR") GuildStore, + GuildNewsThread, + GuildPublicThread, + GuildPrivateThread, + GuildStageVoice, + GuildDirectory, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt new file mode 100644 index 000000000000..7020c0b8ba0d --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt @@ -0,0 +1,79 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Deprecated +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.Set +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 + +@Serializable(with = MessageStickerType.Serializer::class) +public sealed class MessageStickerType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is MessageStickerType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [MessageStickerType]. + */ + public class Unknown( + `value`: Int, + ) : MessageStickerType(value) + + public object PNG : MessageStickerType(1) + + public object APNG : MessageStickerType(2) + + public object LOTTIE : MessageStickerType(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.MessageStickerType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: MessageStickerType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> PNG + 2 -> APNG + 3 -> LOTTIE + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + PNG, + APNG, + LOTTIE, + ) + } + + + @Deprecated( + message = "Renamed to 'entries'.", + replaceWith = ReplaceWith(expression = "this.entries", imports = arrayOf()), + ) + public val values: Set + get() = entries.toSet() + } +} diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 5eba80853a67..588d4090027c 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -91,6 +91,8 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { return FileSpec(packageName, fileName = name) { indent(" ") + addFileComment("THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT!") + @OptIn(DelicateKotlinPoetApi::class) // `AnnotationSpec.get` is ok for `Suppress` addAnnotation(Suppress("RedundantVisibilityModifier", "IncorrectFormatting", "ReplaceArrayOfWithLiteral")) From f6f9bb20699f5a076e7bfbc66a3df4c9442e1d8e Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 26 Aug 2022 22:10:51 +0200 Subject: [PATCH 10/47] Rename `kordJvmOptions()` to `applyKordKotlinOptions()` --- buildSrc/src/main/kotlin/Compiler.kt | 2 +- buildSrc/src/main/kotlin/kord-internal-module.gradle.kts | 2 +- buildSrc/src/main/kotlin/kord-module.gradle.kts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/Compiler.kt b/buildSrc/src/main/kotlin/Compiler.kt index fdaab3af2ca1..d0e75c32e579 100644 --- a/buildSrc/src/main/kotlin/Compiler.kt +++ b/buildSrc/src/main/kotlin/Compiler.kt @@ -17,7 +17,7 @@ object Jvm { const val targetInt = 8 } -fun KotlinJvmOptions.kordJvmOptions() { +fun KotlinJvmOptions.applyKordKotlinOptions() { jvmTarget = Jvm.targetString allWarningsAsErrors = true freeCompilerArgs += CompilerArguments.progressive diff --git a/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts index 1c07b5bca0c4..723a330e392c 100644 --- a/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-internal-module.gradle.kts @@ -16,7 +16,7 @@ tasks { withType { kotlinOptions { - kordJvmOptions() + applyKordKotlinOptions() } } } diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 0cce0be44e39..8d5c1bc7a373 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -44,7 +44,7 @@ tasks { withType { kotlinOptions { - kordJvmOptions() + applyKordKotlinOptions() freeCompilerArgs += listOf( CompilerArguments.time, CompilerArguments.contracts, From 22c212ce3e4ac29e99ee56459332a3175affaad6 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 26 Aug 2022 22:30:55 +0200 Subject: [PATCH 11/47] Hardcode deprecation level for values property --- .../kotlin/dev/kord/common/entity/ChannelType.kt | 10 +++++++++- common/src/main/kotlin/entity/DiscordChannel.kt | 9 +++------ common/src/main/kotlin/entity/DiscordMessage.kt | 9 ++++----- ksp-annotations/src/main/kotlin/GenerateKordEnum.kt | 3 +-- ksp-processors/src/main/kotlin/kordenum/KordEnum.kt | 10 ++-------- .../src/main/kotlin/kordenum/KordEnumGeneration.kt | 5 +++-- .../src/main/kotlin/kordenum/KordEnumProcessor.kt | 13 +++---------- 7 files changed, 25 insertions(+), 34 deletions(-) diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index 0da7e435c5cc..a02e6c402ce0 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -4,6 +4,15 @@ package dev.kord.common.entity +import kotlin.Any +import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith +import kotlin.Suppress +import kotlin.collections.List import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -11,7 +20,6 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlin.LazyThreadSafetyMode.PUBLICATION @Serializable(with = ChannelType.Serializer::class) public sealed class ChannelType( diff --git a/common/src/main/kotlin/entity/DiscordChannel.kt b/common/src/main/kotlin/entity/DiscordChannel.kt index cd378de93ecd..c75ac1c9fe17 100644 --- a/common/src/main/kotlin/entity/DiscordChannel.kt +++ b/common/src/main/kotlin/entity/DiscordChannel.kt @@ -55,21 +55,18 @@ ), Entry( "PublicNewsThread", intValue = 10, - deprecationMessage = "Renamed to 'GuildNewsThread'", + deprecationMessage = "Renamed to 'GuildNewsThread'", deprecationLevel = WARNING, replaceWith = ReplaceWith("GuildNewsThread", "dev.kord.common.entity.ChannelType.GuildNewsThread"), - deprecationLevel = WARNING, ), Entry( "PublicGuildThread", intValue = 11, - deprecationMessage = "Renamed to 'GuildPublicThread'", + deprecationMessage = "Renamed to 'GuildPublicThread'", deprecationLevel = WARNING, replaceWith = ReplaceWith("GuildPublicThread", "dev.kord.common.entity.ChannelType.GuildPublicThread"), - deprecationLevel = WARNING, ), Entry( "PrivateThread", intValue = 12, - deprecationMessage = "Renamed to 'GuildPrivateThread'", + deprecationMessage = "Renamed to 'GuildPrivateThread'", deprecationLevel = WARNING, replaceWith = ReplaceWith("GuildPrivateThread", "dev.kord.common.entity.ChannelType.GuildPrivateThread"), - deprecationLevel = WARNING, ), ], ) diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index e875a6fc35af..be5ef2d3a288 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -1,7 +1,7 @@ @file:GenerateKordEnum( name = "MessageStickerType", valueType = INT, // had `public val values: Set` in companion before -> replace with `entries` - valuesPropertyName = "values", valuesPropertyDeprecationLevel = WARNING, valuesPropertyType = SET, + valuesPropertyName = "values", valuesPropertyType = SET, entries = [ Entry("PNG", intValue = 1), Entry("APNG", intValue = 2), @@ -11,14 +11,14 @@ package dev.kord.common.entity -import dev.kord.ksp.GenerateKordEnum -import dev.kord.ksp.GenerateKordEnum.Entry -import dev.kord.ksp.GenerateKordEnum.ValueType.INT import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.IntOrStringSerializer +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET import kotlinx.datetime.Instant import kotlinx.serialization.KSerializer @@ -29,7 +29,6 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlin.DeprecationLevel.WARNING import kotlin.contracts.InvocationKind import kotlin.contracts.contract diff --git a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt index de526ac62b9b..3394a5d55e79 100644 --- a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt +++ b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt @@ -27,12 +27,11 @@ annotation class GenerateKordEnum( /** [entries] of the kord enum that are [Deprecated]. [Entry.deprecationMessage] is required for these. */ val deprecatedEntries: Array = [], + // TODO remove eventually /** For migration purposes. */ val valuesPropertyName: String = "", /** For migration purposes. */ val valuesPropertyType: ValuesPropertyType = NONE, - /** For migration purposes. */ - val valuesPropertyDeprecationLevel: DeprecationLevel = WARNING, ) { enum class ValueType { INT, STRING } enum class ValuesPropertyType { NONE, SET } diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt index 83b7caea2079..5d1034e4b7d7 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt @@ -24,10 +24,9 @@ internal class KordEnum( val entries: List, val deprecatedEntries: List, - // for migration purposes + // for migration purposes, TODO remove eventually val valuesPropertyName: String?, val valuesPropertyType: ValuesPropertyType, - val valuesPropertyDeprecationLevel: DeprecationLevel, ) { internal class Entry( val name: String, @@ -57,7 +56,6 @@ internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { val valuesPropertyName = (args[GenerateKordEnum::valuesPropertyName] as String).ifEmpty { null } val valuesPropertyType = args[GenerateKordEnum::valuesPropertyType].toValuesPropertyType() - val valuesPropertyDeprecationLevel = args[GenerateKordEnum::valuesPropertyDeprecationLevel].toDeprecationLevel() if (valuesPropertyName != null) { if (valuesPropertyType == NONE) { logger.error("Didn't specify valuesPropertyType", symbol = this) @@ -68,10 +66,6 @@ internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { logger.error("Specified valuesPropertyType", symbol = this) return null } - if (valuesPropertyDeprecationLevel != WARNING) { - logger.error("Specified valuesPropertyDeprecationLevel", symbol = this) - return null - } } return KordEnum( @@ -79,7 +73,7 @@ internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { entries.map { it.toEntryOrNull(valueType, isDeprecated = false, logger) ?: return null }, deprecatedEntries.map { it.toEntryOrNull(valueType, isDeprecated = true, logger) ?: return null }, - valuesPropertyName, valuesPropertyType, valuesPropertyDeprecationLevel, + valuesPropertyName, valuesPropertyType, ) } diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 588d4090027c..9bf6c35e9d10 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -228,7 +228,8 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } } - // @Deprecated("Renamed to 'entries'.", ReplaceWith("this.entries"), ) + // TODO bump deprecation level and remove eventually + // @Deprecated("Renamed to 'entries'.", ReplaceWith("this.entries"), level = WARNING) // public val if (valuesPropertyName != null) { addProperty( @@ -241,7 +242,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { Deprecated( "Renamed to 'entries'.", ReplaceWith("this.entries", imports = emptyArray()), - valuesPropertyDeprecationLevel, + level = WARNING, ) ) getter { diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt index 514192695386..302cbf812eaf 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt @@ -27,15 +27,8 @@ class KordEnumProcessor(private val codeGenerator: CodeGenerator, private val lo resolver .getSymbolsWithAnnotation() - .mapNotNull { symbol -> - when (symbol) { - is KSFile -> symbol - else -> { - logger.warn("found annotation on wrong symbol", symbol) - null - } - } - } + .onEach { if (it !is KSFile) logger.warn("found annotation on wrong symbol", symbol = it) } + .filterIsInstance() .forEach(::processFile) logger.info("KordEnumProcessor finished processing annotations") @@ -48,7 +41,7 @@ class KordEnumProcessor(private val codeGenerator: CodeGenerator, private val lo .filter { it.isOfType() } .onEach { logger.info("found annotation", symbol = it) } .mapNotNull { it.toKordEnumOrNull(logger) } - .forEach { generateKordEnum(it, file) } + .forEach { generateKordEnum(it, originatingFile = file) } } private fun generateKordEnum(kordEnum: KordEnum, originatingFile: KSFile) { From 3d5b2d8e6968b325c60250a038c06f2febc4cd22 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sat, 27 Aug 2022 12:13:52 +0200 Subject: [PATCH 12/47] Wrapper class for annotation arguments --- ksp-processors/build.gradle.kts | 2 +- ksp-processors/src/main/kotlin/KSPUtils.kt | 9 +++++++-- ksp-processors/src/main/kotlin/kordenum/KordEnum.kt | 9 ++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ksp-processors/build.gradle.kts b/ksp-processors/build.gradle.kts index a35aa19036c8..3de1931298c4 100644 --- a/ksp-processors/build.gradle.kts +++ b/ksp-processors/build.gradle.kts @@ -5,5 +5,5 @@ plugins { dependencies { implementation(projects.kspAnnotations) implementation(libs.bundles.ksp.processors) - implementation(libs.bundles.common) + implementation(libs.kotlinx.serialization) // use types directly } diff --git a/ksp-processors/src/main/kotlin/KSPUtils.kt b/ksp-processors/src/main/kotlin/KSPUtils.kt index ff2ded55e8a4..be0176599880 100644 --- a/ksp-processors/src/main/kotlin/KSPUtils.kt +++ b/ksp-processors/src/main/kotlin/KSPUtils.kt @@ -10,6 +10,11 @@ internal inline fun Resolver.getSymbolsWithAnnotation(i internal inline fun KSAnnotation.isOfType() = shortName.asString() == A::class.simpleName!! && annotationType.resolve().declaration.qualifiedName?.asString() == A::class.qualifiedName!! -internal fun KSAnnotation.argumentsToMap() = arguments.associate { it.name!!.getShortName() to it.value!! } +internal class AnnotationArguments private constructor(private val map: Map) { + internal operator fun get(parameter: KProperty1) = map[parameter.name] -internal operator fun Map.get(parameter: KProperty1<*, *>) = get(parameter.name) + internal companion object { + internal val KSAnnotation.annotationArguments + get() = AnnotationArguments(arguments.associate { it.name!!.getShortName() to it.value!! }) + } +} diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt index 5d1034e4b7d7..d5fe04e2f23c 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt @@ -3,6 +3,7 @@ package dev.kord.ksp.kordenum import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSType +import dev.kord.ksp.AnnotationArguments.Companion.annotationArguments import dev.kord.ksp.GenerateKordEnum import dev.kord.ksp.GenerateKordEnum.ValueType import dev.kord.ksp.GenerateKordEnum.ValueType.INT @@ -10,8 +11,6 @@ import dev.kord.ksp.GenerateKordEnum.ValueType.STRING import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.NONE import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET -import dev.kord.ksp.argumentsToMap -import dev.kord.ksp.get import dev.kord.ksp.kordenum.KordEnum.Entry import kotlin.DeprecationLevel.* @@ -45,7 +44,7 @@ internal class KordEnum( * Returns `null` if mapping fails. */ internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { - val args = argumentsToMap() + val args = annotationArguments val name = args[GenerateKordEnum::name] as String val valueType = args[GenerateKordEnum::valueType].toValueType() @@ -99,7 +98,7 @@ private fun Any?.toValuesPropertyType() = when (val name = (this as KSType).decl * Returns `null` if mapping fails. */ private fun Any?.toEntryOrNull(valueType: ValueType, isDeprecated: Boolean, logger: KSPLogger): Entry? { - val args = (this as KSAnnotation).argumentsToMap() + val args = (this as KSAnnotation).annotationArguments val name = args[GenerateKordEnum.Entry::name] as String val intValue = args[GenerateKordEnum.Entry::intValue] as Int @@ -161,7 +160,7 @@ private fun Any?.toEntryOrNull(valueType: ValueType, isDeprecated: Boolean, logg /** Maps [KSAnnotation] to [ReplaceWith]. */ private fun Any?.toReplaceWith(): ReplaceWith { - val args = (this as KSAnnotation).argumentsToMap() + val args = (this as KSAnnotation).annotationArguments val expression = args[ReplaceWith::expression] as String val imports = @Suppress("UNCHECKED_CAST") (args[ReplaceWith::imports] as List) From 6e861625eed4720a2f2b1fafc4a36713135938d5 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Thu, 1 Sep 2022 23:49:08 +0200 Subject: [PATCH 13/47] Rollback renames --- common/api/common.api | 12 ------ .../dev/kord/common/entity/ChannelType.kt | 40 +++++-------------- .../src/main/kotlin/entity/DiscordChannel.kt | 22 ++-------- .../behavior/channel/NewsChannelBehavior.kt | 2 +- .../behavior/channel/TextChannelBehavior.kt | 6 +-- .../src/main/kotlin/entity/channel/Channel.kt | 4 +- .../channel/thread/TextChannelThread.kt | 2 +- .../gateway/handler/ThreadEventHandler.kt | 6 +-- .../kotlin/supplier/CacheEntitySupplier.kt | 6 +-- 9 files changed, 25 insertions(+), 75 deletions(-) diff --git a/common/api/common.api b/common/api/common.api index 50435d5988c3..81610648752f 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -1221,18 +1221,6 @@ public final class dev/kord/common/entity/ChannelType$GuildNews : dev/kord/commo public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildNews; } -public final class dev/kord/common/entity/ChannelType$GuildNewsThread : dev/kord/common/entity/ChannelType { - public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildNewsThread; -} - -public final class dev/kord/common/entity/ChannelType$GuildPrivateThread : dev/kord/common/entity/ChannelType { - public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildPrivateThread; -} - -public final class dev/kord/common/entity/ChannelType$GuildPublicThread : dev/kord/common/entity/ChannelType { - public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildPublicThread; -} - public final class dev/kord/common/entity/ChannelType$GuildStageVoice : dev/kord/common/entity/ChannelType { public static final field INSTANCE Ldev/kord/common/entity/ChannelType$GuildStageVoice; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index a02e6c402ce0..b66630e85733 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -10,7 +10,6 @@ import kotlin.Deprecated import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION -import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -73,19 +72,19 @@ public sealed class ChannelType( /** * A temporary sub-channel within a [GuildNews] channel. */ - public object GuildNewsThread : ChannelType(10) + public object PublicNewsThread : ChannelType(10) /** * A temporary sub-channel within a [GuildText] channel. */ - public object GuildPublicThread : ChannelType(11) + public object PublicGuildThread : ChannelType(11) /** * A temporary sub-channel within a [GuildText] channel that is only viewable by those invited * and those with * the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission. */ - public object GuildPrivateThread : ChannelType(12) + public object PrivateThread : ChannelType(12) /** * A voice channel for @@ -112,27 +111,6 @@ public sealed class ChannelType( ) public object GuildStore : ChannelType(6) - @Deprecated( - message = "Renamed to 'GuildNewsThread'", - replaceWith = ReplaceWith(expression = "GuildNewsThread", imports = - arrayOf("dev.kord.common.entity.ChannelType.GuildNewsThread")), - ) - public object PublicNewsThread : ChannelType(10) - - @Deprecated( - message = "Renamed to 'GuildPublicThread'", - replaceWith = ReplaceWith(expression = "GuildPublicThread", imports = - arrayOf("dev.kord.common.entity.ChannelType.GuildPublicThread")), - ) - public object PublicGuildThread : ChannelType(11) - - @Deprecated( - message = "Renamed to 'GuildPrivateThread'", - replaceWith = ReplaceWith(expression = "GuildPrivateThread", imports = - arrayOf("dev.kord.common.entity.ChannelType.GuildPrivateThread")), - ) - public object PrivateThread : ChannelType(12) - internal object Serializer : KSerializer { public override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.ChannelType", PrimitiveKind.INT) @@ -148,9 +126,9 @@ public sealed class ChannelType( 4 -> GuildCategory 5 -> GuildNews 6 -> @Suppress("DEPRECATION_ERROR") GuildStore - 10 -> GuildNewsThread - 11 -> GuildPublicThread - 12 -> GuildPrivateThread + 10 -> PublicNewsThread + 11 -> PublicGuildThread + 12 -> PrivateThread 13 -> GuildStageVoice 14 -> GuildDirectory else -> Unknown(value) @@ -167,9 +145,9 @@ public sealed class ChannelType( GuildCategory, GuildNews, @Suppress("DEPRECATION_ERROR") GuildStore, - GuildNewsThread, - GuildPublicThread, - GuildPrivateThread, + PublicNewsThread, + PublicGuildThread, + PrivateThread, GuildStageVoice, GuildDirectory, ) diff --git a/common/src/main/kotlin/entity/DiscordChannel.kt b/common/src/main/kotlin/entity/DiscordChannel.kt index c75ac1c9fe17..ba94d14c902f 100644 --- a/common/src/main/kotlin/entity/DiscordChannel.kt +++ b/common/src/main/kotlin/entity/DiscordChannel.kt @@ -20,10 +20,10 @@ [users·can·follow·and·crosspost·into·their·own·server](https://support.discord.com/hc/en-us/articles/360032008192). """, ), - Entry("GuildNewsThread", intValue = 10, kDoc = "A temporary sub-channel within a [GuildNews] channel."), - Entry("GuildPublicThread", intValue = 11, kDoc = "A temporary sub-channel within a [GuildText] channel."), + Entry("PublicNewsThread", intValue = 10, kDoc = "A temporary sub-channel within a [GuildNews] channel."), + Entry("PublicGuildThread", intValue = 11, kDoc = "A temporary sub-channel within a [GuildText] channel."), Entry( - "GuildPrivateThread", intValue = 12, + "PrivateThread", intValue = 12, kDoc = """ A temporary sub-channel within a [GuildText] channel that is only viewable by those invited and those with the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission. @@ -53,21 +53,6 @@ "https://support-dev.discord.com/hc/en-us/articles/4414590563479 for more information.", deprecationLevel = ERROR, ), - Entry( - "PublicNewsThread", intValue = 10, - deprecationMessage = "Renamed to 'GuildNewsThread'", deprecationLevel = WARNING, - replaceWith = ReplaceWith("GuildNewsThread", "dev.kord.common.entity.ChannelType.GuildNewsThread"), - ), - Entry( - "PublicGuildThread", intValue = 11, - deprecationMessage = "Renamed to 'GuildPublicThread'", deprecationLevel = WARNING, - replaceWith = ReplaceWith("GuildPublicThread", "dev.kord.common.entity.ChannelType.GuildPublicThread"), - ), - Entry( - "PrivateThread", intValue = 12, - deprecationMessage = "Renamed to 'GuildPrivateThread'", deprecationLevel = WARNING, - replaceWith = ReplaceWith("GuildPrivateThread", "dev.kord.common.entity.ChannelType.GuildPrivateThread"), - ), ], ) @@ -92,7 +77,6 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlin.DeprecationLevel.ERROR -import kotlin.DeprecationLevel.WARNING import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes diff --git a/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt b/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt index fc8ba60627be..3f37230a1cc3 100644 --- a/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt +++ b/core/src/main/kotlin/behavior/channel/NewsChannelBehavior.kt @@ -87,7 +87,7 @@ public interface NewsChannelBehavior : ThreadParentChannelBehavior { archiveDuration: ArchiveDuration = ArchiveDuration.Day, reason: String? = null ): NewsChannelThread { - return unsafeStartThread(name, archiveDuration, ChannelType.GuildNewsThread) { this.reason = reason } as NewsChannelThread + return unsafeStartThread(name, archiveDuration, ChannelType.PublicNewsThread) { this.reason = reason } as NewsChannelThread } public suspend fun startPublicThreadWithMessage( diff --git a/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt b/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt index 1f1432e3a2e6..94f7024e6425 100644 --- a/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt +++ b/core/src/main/kotlin/behavior/channel/TextChannelBehavior.kt @@ -73,7 +73,7 @@ public interface TextChannelBehavior : PrivateThreadParentChannelBehavior { return unsafeStartThread( name, archiveDuration, - ChannelType.GuildPublicThread, + ChannelType.PublicGuildThread, builder ) as TextChannelThread } @@ -83,8 +83,8 @@ public interface TextChannelBehavior : PrivateThreadParentChannelBehavior { archiveDuration: ArchiveDuration = ArchiveDuration.Day, builder: StartThreadBuilder.() -> Unit = {} ): TextChannelThread { - val startBuilder = StartThreadBuilder(name, archiveDuration, ChannelType.GuildPrivateThread).apply(builder) - return unsafeStartThread(startBuilder.name, startBuilder.autoArchiveDuration, ChannelType.GuildPrivateThread, builder) as TextChannelThread + val startBuilder = StartThreadBuilder(name, archiveDuration, ChannelType.PrivateThread).apply(builder) + return unsafeStartThread(startBuilder.name, startBuilder.autoArchiveDuration, ChannelType.PrivateThread, builder) as TextChannelThread } public suspend fun startPublicThreadWithMessage( diff --git a/core/src/main/kotlin/entity/channel/Channel.kt b/core/src/main/kotlin/entity/channel/Channel.kt index 5cf0f00fe0f6..8bcf7932582a 100644 --- a/core/src/main/kotlin/entity/channel/Channel.kt +++ b/core/src/main/kotlin/entity/channel/Channel.kt @@ -50,8 +50,8 @@ public interface Channel : ChannelBehavior { GuildCategory -> Category(data, kord) GuildNews -> NewsChannel(data, kord) @Suppress("DEPRECATION_ERROR") GuildStore -> @Suppress("DEPRECATION_ERROR") StoreChannel(data, kord) - GuildNewsThread -> NewsChannelThread(data, kord) - GuildPrivateThread, GuildPublicThread -> TextChannelThread(data, kord) + PublicNewsThread -> NewsChannelThread(data, kord) + PrivateThread, PublicGuildThread -> TextChannelThread(data, kord) else -> { if (data.threadMetadata.value == null) Channel(data, kord, strategy.supply(kord)) diff --git a/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt b/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt index 5dbbdba60e29..b02116aea81e 100644 --- a/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt +++ b/core/src/main/kotlin/entity/channel/thread/TextChannelThread.kt @@ -22,7 +22,7 @@ public class TextChannelThread( /** * Whether this thread is private. */ - public val isPrivate: Boolean get() = data.type == ChannelType.GuildPrivateThread + public val isPrivate: Boolean get() = data.type == ChannelType.PrivateThread /** * Whether non-moderators can add other non-moderators to a thread. diff --git a/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt b/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt index d064e33eb352..0be861339f5b 100644 --- a/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt +++ b/core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt @@ -72,14 +72,14 @@ internal class ThreadEventHandler : BaseGatewayEventHandler() { val channel = DeletedThreadChannel(channelData, kord) val old = cachedData?.let { Channel.from(cachedData, kord) } val coreEvent = when (channel.type) { - ChannelType.GuildNewsThread -> NewsChannelThreadDeleteEvent( + ChannelType.PublicNewsThread -> NewsChannelThreadDeleteEvent( channel, old as? NewsChannelThread, shard, context?.get(), ) - ChannelType.GuildPrivateThread, - ChannelType.GuildPublicThread -> TextChannelThreadDeleteEvent(channel, old as? TextChannelThread, shard, context?.get()) + ChannelType.PrivateThread, + ChannelType.PublicGuildThread -> TextChannelThreadDeleteEvent(channel, old as? TextChannelThread, shard, context?.get()) else -> UnknownChannelThreadDeleteEvent(channel, old as? ThreadChannel, shard, context?.get()) } diff --git a/core/src/main/kotlin/supplier/CacheEntitySupplier.kt b/core/src/main/kotlin/supplier/CacheEntitySupplier.kt index 64206b0219cb..04debe6b0b71 100644 --- a/core/src/main/kotlin/supplier/CacheEntitySupplier.kt +++ b/core/src/main/kotlin/supplier/CacheEntitySupplier.kt @@ -335,7 +335,7 @@ public class CacheEntitySupplier(private val kord: Kord) : EntitySupplier { it.threadMetadata.value?.archived == true && time != null && (before == null || time < before) - && (it.type == ChannelType.GuildPublicThread || it.type == ChannelType.GuildNewsThread) + && (it.type == ChannelType.PublicGuildThread || it.type == ChannelType.PublicNewsThread) } .limit(limit) .mapNotNull { Channel.from(it, kord) as? ThreadChannel } @@ -356,7 +356,7 @@ public class CacheEntitySupplier(private val kord: Kord) : EntitySupplier { it.threadMetadata.value?.archived == true && time != null && (before == null || time < before) - && it.type == ChannelType.GuildPrivateThread + && it.type == ChannelType.PrivateThread } .limit(limit) .mapNotNull { Channel.from(it, kord) as? ThreadChannel } @@ -379,7 +379,7 @@ public class CacheEntitySupplier(private val kord: Kord) : EntitySupplier { .filter { it.threadMetadata.value?.archived == true && (before == null || it.id < before) - && it.type == ChannelType.GuildPrivateThread + && it.type == ChannelType.PrivateThread && it.member !is Optional.Missing } .limit(limit) From e1e741bc5d617643324d74df9c827c3d9426f0af Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 00:30:08 +0200 Subject: [PATCH 14/47] Generate `AuditLogEvent` --- common/api/common.api | 3 + .../dev/kord/common/entity/AuditLogEvent.kt | 420 ++++++++++++++++++ .../dev/kord/common/entity/ChannelType.kt | 2 +- common/src/main/kotlin/entity/AuditLog.kt | 185 +++----- 4 files changed, 485 insertions(+), 125 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt diff --git a/common/api/common.api b/common/api/common.api index c41753eccf7c..8972dbcdb084 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -877,7 +877,9 @@ public final class dev/kord/common/entity/AuditLogEntryOptionalInfo$Companion { public abstract class dev/kord/common/entity/AuditLogEvent { public static final field Companion Ldev/kord/common/entity/AuditLogEvent$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/AuditLogEvent$ApplicationCommandPermissionUpdate : dev/kord/common/entity/AuditLogEvent { @@ -929,6 +931,7 @@ public final class dev/kord/common/entity/AuditLogEvent$ChannelUpdate : dev/kord } public final class dev/kord/common/entity/AuditLogEvent$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt new file mode 100644 index 000000000000..844b22e09c64 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt @@ -0,0 +1,420 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = AuditLogEvent.Serializer::class) +public sealed class AuditLogEvent( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is AuditLogEvent && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [AuditLogEvent]. + */ + public class Unknown( + `value`: Int, + ) : AuditLogEvent(value) + + /** + * Server settings were updated. + */ + public object GuildUpdate : AuditLogEvent(1) + + /** + * Channel was created. + */ + public object ChannelCreate : AuditLogEvent(10) + + /** + * Channel settings were updated + */ + public object ChannelUpdate : AuditLogEvent(11) + + /** + * Channel was deleted. + */ + public object ChannelDelete : AuditLogEvent(12) + + /** + * Permission overwrite was added to a channel. + */ + public object ChannelOverwriteCreate : AuditLogEvent(13) + + /** + * Permission overwrite was updated for a channel. + */ + public object ChannelOverwriteUpdate : AuditLogEvent(14) + + /** + * Permission overwrite was deleted from a channel. + */ + public object ChannelOverwriteDelete : AuditLogEvent(15) + + /** + * Member was removed from server. + */ + public object MemberKick : AuditLogEvent(20) + + /** + * Members were pruned from server. + */ + public object MemberPrune : AuditLogEvent(21) + + /** + * Member was banned from server. + */ + public object MemberBanAdd : AuditLogEvent(22) + + /** + * Server ban was lifted for a member. + */ + public object MemberBanRemove : AuditLogEvent(23) + + /** + * Member was updated in server. + */ + public object MemberUpdate : AuditLogEvent(24) + + /** + * Member was added or removed from a role. + */ + public object MemberRoleUpdate : AuditLogEvent(25) + + /** + * Member was moved to a different voice channel. + */ + public object MemberMove : AuditLogEvent(26) + + /** + * Member was disconnected from a voice channel. + */ + public object MemberDisconnect : AuditLogEvent(27) + + /** + * Bot user was added to server. + */ + public object BotAdd : AuditLogEvent(28) + + /** + * Role was created. + */ + public object RoleCreate : AuditLogEvent(30) + + /** + * Role was edited. + */ + public object RoleUpdate : AuditLogEvent(31) + + /** + * Role was deleted. + */ + public object RoleDelete : AuditLogEvent(32) + + /** + * Server invite was created. + */ + public object InviteCreate : AuditLogEvent(40) + + /** + * Server invite was updated. + */ + public object InviteUpdate : AuditLogEvent(41) + + /** + * Server invite was deleted. + */ + public object InviteDelete : AuditLogEvent(42) + + /** + * Webhook was created. + */ + public object WebhookCreate : AuditLogEvent(50) + + /** + * Webhook properties or channel were updated. + */ + public object WebhookUpdate : AuditLogEvent(51) + + /** + * Webhook was deleted. + */ + public object WebhookDelete : AuditLogEvent(52) + + /** + * Emoji was created. + */ + public object EmojiCreate : AuditLogEvent(60) + + /** + * Emoji name was updated. + */ + public object EmojiUpdate : AuditLogEvent(61) + + /** + * Emoji was deleted. + */ + public object EmojiDelete : AuditLogEvent(62) + + /** + * Single message was deleted. + */ + public object MessageDelete : AuditLogEvent(72) + + /** + * Multiple messages were deleted. + */ + public object MessageBulkDelete : AuditLogEvent(73) + + /** + * Message was pinned to a channel + */ + public object MessagePin : AuditLogEvent(74) + + /** + * Message was unpinned from a channel. + */ + public object MessageUnpin : AuditLogEvent(75) + + /** + * App was added to server. + */ + public object IntegrationCreate : AuditLogEvent(80) + + /** + * App was updated (as an example, its scopes were updated). + */ + public object IntegrationUpdate : AuditLogEvent(81) + + /** + * App was removed from server. + */ + public object IntegrationDelete : AuditLogEvent(82) + + /** + * Stage instance was created (stage channel becomes live). + */ + public object StageInstanceCreate : AuditLogEvent(83) + + /** + * Stage instance details were updated. + */ + public object StageInstanceUpdate : AuditLogEvent(84) + + /** + * Stage instance was deleted (stage channel no longer live). + */ + public object StageInstanceDelete : AuditLogEvent(85) + + /** + * Sticker was created. + */ + public object StickerCreate : AuditLogEvent(90) + + /** + * Sticker details were updated. + */ + public object StickerUpdate : AuditLogEvent(91) + + /** + * Sticker was deleted. + */ + public object StickerDelete : AuditLogEvent(92) + + /** + * Event was created. + */ + public object GuildScheduledEventCreate : AuditLogEvent(100) + + /** + * Event was updated. + */ + public object GuildScheduledEventUpdate : AuditLogEvent(101) + + /** + * Event was cancelled. + */ + public object GuildScheduledEventDelete : AuditLogEvent(102) + + /** + * Thread was created in a channel. + */ + public object ThreadCreate : AuditLogEvent(110) + + /** + * Thread was updated. + */ + public object ThreadUpdate : AuditLogEvent(111) + + /** + * Thread was deleted. + */ + public object ThreadDelete : AuditLogEvent(112) + + /** + * Permissions were updated for a command. + */ + public object ApplicationCommandPermissionUpdate : AuditLogEvent(121) + + /** + * Auto Moderation rule was created. + */ + public object AutoModerationRuleCreate : AuditLogEvent(140) + + /** + * Auto Moderation rule was updated. + */ + public object AutoModerationRuleUpdate : AuditLogEvent(141) + + /** + * Auto Moderation rule was deleted. + */ + public object AutoModerationRuleDelete : AuditLogEvent(142) + + /** + * Message was blocked by AutoMod (according to a rule). + */ + public object AutoModerationBlockMessage : AuditLogEvent(143) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.AuditLogEvent", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: AuditLogEvent) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> GuildUpdate + 10 -> ChannelCreate + 11 -> ChannelUpdate + 12 -> ChannelDelete + 13 -> ChannelOverwriteCreate + 14 -> ChannelOverwriteUpdate + 15 -> ChannelOverwriteDelete + 20 -> MemberKick + 21 -> MemberPrune + 22 -> MemberBanAdd + 23 -> MemberBanRemove + 24 -> MemberUpdate + 25 -> MemberRoleUpdate + 26 -> MemberMove + 27 -> MemberDisconnect + 28 -> BotAdd + 30 -> RoleCreate + 31 -> RoleUpdate + 32 -> RoleDelete + 40 -> InviteCreate + 41 -> InviteUpdate + 42 -> InviteDelete + 50 -> WebhookCreate + 51 -> WebhookUpdate + 52 -> WebhookDelete + 60 -> EmojiCreate + 61 -> EmojiUpdate + 62 -> EmojiDelete + 72 -> MessageDelete + 73 -> MessageBulkDelete + 74 -> MessagePin + 75 -> MessageUnpin + 80 -> IntegrationCreate + 81 -> IntegrationUpdate + 82 -> IntegrationDelete + 83 -> StageInstanceCreate + 84 -> StageInstanceUpdate + 85 -> StageInstanceDelete + 90 -> StickerCreate + 91 -> StickerUpdate + 92 -> StickerDelete + 100 -> GuildScheduledEventCreate + 101 -> GuildScheduledEventUpdate + 102 -> GuildScheduledEventDelete + 110 -> ThreadCreate + 111 -> ThreadUpdate + 112 -> ThreadDelete + 121 -> ApplicationCommandPermissionUpdate + 140 -> AutoModerationRuleCreate + 141 -> AutoModerationRuleUpdate + 142 -> AutoModerationRuleDelete + 143 -> AutoModerationBlockMessage + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + GuildUpdate, + ChannelCreate, + ChannelUpdate, + ChannelDelete, + ChannelOverwriteCreate, + ChannelOverwriteUpdate, + ChannelOverwriteDelete, + MemberKick, + MemberPrune, + MemberBanAdd, + MemberBanRemove, + MemberUpdate, + MemberRoleUpdate, + MemberMove, + MemberDisconnect, + BotAdd, + RoleCreate, + RoleUpdate, + RoleDelete, + InviteCreate, + InviteUpdate, + InviteDelete, + WebhookCreate, + WebhookUpdate, + WebhookDelete, + EmojiCreate, + EmojiUpdate, + EmojiDelete, + MessageDelete, + MessageBulkDelete, + MessagePin, + MessageUnpin, + IntegrationCreate, + IntegrationUpdate, + IntegrationDelete, + StageInstanceCreate, + StageInstanceUpdate, + StageInstanceDelete, + StickerCreate, + StickerUpdate, + StickerDelete, + GuildScheduledEventCreate, + GuildScheduledEventUpdate, + GuildScheduledEventDelete, + ThreadCreate, + ThreadUpdate, + ThreadDelete, + ApplicationCommandPermissionUpdate, + AutoModerationRuleCreate, + AutoModerationRuleUpdate, + AutoModerationRuleDelete, + AutoModerationBlockMessage, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index b66630e85733..83e808cb8655 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -107,7 +107,7 @@ public sealed class ChannelType( @Deprecated( level = DeprecationLevel.ERROR, message = - "Discord no longer offers the ability to purchase a license to sell PC games on Discord and store channels were removed on March 10, 2022. See https://support-dev.discord.com/hc/en-us/articles/4414590563479 for more information.", + "Discord no longer offers the ability to purchase a license to sell PC games on Discord and store channels were removed on March 10, 2022. See https://support-dev.discord.com/hc/en-us/articles/6309018858647-Self-serve-Game-Selling-Deprecation for more information.", ) public object GuildStore : ChannelType(6) diff --git a/common/src/main/kotlin/entity/AuditLog.kt b/common/src/main/kotlin/entity/AuditLog.kt index 83c755210705..2295f72d71d3 100644 --- a/common/src/main/kotlin/entity/AuditLog.kt +++ b/common/src/main/kotlin/entity/AuditLog.kt @@ -1,3 +1,61 @@ +@file:GenerateKordEnum( + name = "AuditLogEvent", valueType = INT, + entries = [ + Entry("GuildUpdate", intValue = 1, kDoc = "Server settings were updated."), + Entry("ChannelCreate", intValue = 10, kDoc = "Channel was created."), + Entry("ChannelUpdate", intValue = 11, kDoc = "Channel settings were updated"), + Entry("ChannelDelete", intValue = 12, kDoc = "Channel was deleted."), + Entry("ChannelOverwriteCreate", intValue = 13, kDoc = "Permission overwrite was added to a channel."), + Entry("ChannelOverwriteUpdate", intValue = 14, kDoc = "Permission overwrite was updated for a channel."), + Entry("ChannelOverwriteDelete", intValue = 15, kDoc = "Permission overwrite was deleted from a channel."), + Entry("MemberKick", intValue = 20, kDoc = "Member was removed from server."), + Entry("MemberPrune", intValue = 21, kDoc = "Members were pruned from server."), + Entry("MemberBanAdd", intValue = 22, kDoc = "Member was banned from server."), + Entry("MemberBanRemove", intValue = 23, kDoc = "Server ban was lifted for a member."), + Entry("MemberUpdate", intValue = 24, kDoc = "Member was updated in server."), + Entry("MemberRoleUpdate", intValue = 25, kDoc = "Member was added or removed from a role."), + Entry("MemberMove", intValue = 26, kDoc = "Member was moved to a different voice channel."), + Entry("MemberDisconnect", intValue = 27, kDoc = "Member was disconnected from a voice channel."), + Entry("BotAdd", intValue = 28, kDoc = "Bot user was added to server."), + Entry("RoleCreate", intValue = 30, kDoc = "Role was created."), + Entry("RoleUpdate", intValue = 31, kDoc = "Role was edited."), + Entry("RoleDelete", intValue = 32, kDoc = "Role was deleted."), + Entry("InviteCreate", intValue = 40, kDoc = "Server invite was created."), + Entry("InviteUpdate", intValue = 41, kDoc = "Server invite was updated."), + Entry("InviteDelete", intValue = 42, kDoc = "Server invite was deleted."), + Entry("WebhookCreate", intValue = 50, kDoc = "Webhook was created."), + Entry("WebhookUpdate", intValue = 51, kDoc = "Webhook properties or channel were updated."), + Entry("WebhookDelete", intValue = 52, kDoc = "Webhook was deleted."), + Entry("EmojiCreate", intValue = 60, kDoc = "Emoji was created."), + Entry("EmojiUpdate", intValue = 61, kDoc = "Emoji name was updated."), + Entry("EmojiDelete", intValue = 62, kDoc = "Emoji was deleted."), + Entry("MessageDelete", intValue = 72, kDoc = "Single message was deleted."), + Entry("MessageBulkDelete", intValue = 73, kDoc = "Multiple messages were deleted."), + Entry("MessagePin", intValue = 74, kDoc = "Message was pinned to a channel"), + Entry("MessageUnpin", intValue = 75, kDoc = "Message was unpinned from a channel."), + Entry("IntegrationCreate", intValue = 80, kDoc = "App was added to server."), + Entry("IntegrationUpdate", intValue = 81, kDoc = "App was updated (as an example, its scopes were updated)."), + Entry("IntegrationDelete", intValue = 82, kDoc = "App was removed from server."), + Entry("StageInstanceCreate", intValue = 83, kDoc = "Stage instance was created (stage channel becomes live)."), + Entry("StageInstanceUpdate", intValue = 84, kDoc = "Stage instance details were updated."), + Entry("StageInstanceDelete", intValue = 85, kDoc = "Stage instance was deleted (stage channel no longer live)."), + Entry("StickerCreate", intValue = 90, kDoc = "Sticker was created."), + Entry("StickerUpdate", intValue = 91, kDoc = "Sticker details were updated."), + Entry("StickerDelete", intValue = 92, kDoc = "Sticker was deleted."), + Entry("GuildScheduledEventCreate", intValue = 100, kDoc = "Event was created."), + Entry("GuildScheduledEventUpdate", intValue = 101, kDoc = "Event was updated."), + Entry("GuildScheduledEventDelete", intValue = 102, kDoc = "Event was cancelled."), + Entry("ThreadCreate", intValue = 110, kDoc = "Thread was created in a channel."), + Entry("ThreadUpdate", intValue = 111, kDoc = "Thread was updated."), + Entry("ThreadDelete", intValue = 112, kDoc = "Thread was deleted."), + Entry("ApplicationCommandPermissionUpdate", intValue = 121, kDoc = "Permissions were updated for a command."), + Entry("AutoModerationRuleCreate", intValue = 140, kDoc = "Auto Moderation rule was created."), + Entry("AutoModerationRuleUpdate", intValue = 141, kDoc = "Auto Moderation rule was updated."), + Entry("AutoModerationRuleDelete", intValue = 142, kDoc = "Auto Moderation rule was deleted."), + Entry("AutoModerationBlockMessage", intValue = 143, kDoc = "Message was blocked by AutoMod (according to a rule)."), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional @@ -6,6 +64,9 @@ import dev.kord.common.entity.optional.orEmpty import dev.kord.common.serialization.DurationInDaysSerializer import dev.kord.common.serialization.DurationInSecondsSerializer import dev.kord.common.serialization.IntOrStringSerializer +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.datetime.Instant import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @@ -436,127 +497,3 @@ public sealed class AuditLogChangeKey(public val name: String, public val ser } } } - -@Serializable(with = AuditLogEvent.Serializer::class) -public sealed class AuditLogEvent(public val value: Int) { - public class Unknown(value: Int) : AuditLogEvent(value) - public object GuildUpdate : AuditLogEvent(1) - public object ChannelCreate : AuditLogEvent(10) - public object ChannelUpdate : AuditLogEvent(11) - public object ChannelDelete : AuditLogEvent(12) - public object ChannelOverwriteCreate : AuditLogEvent(13) - public object ChannelOverwriteUpdate : AuditLogEvent(14) - public object ChannelOverwriteDelete : AuditLogEvent(15) - public object MemberKick : AuditLogEvent(20) - public object MemberPrune : AuditLogEvent(21) - public object MemberBanAdd : AuditLogEvent(22) - public object MemberBanRemove : AuditLogEvent(23) - public object MemberUpdate : AuditLogEvent(24) - public object MemberRoleUpdate : AuditLogEvent(25) - public object MemberMove : AuditLogEvent(26) - public object MemberDisconnect : AuditLogEvent(27) - public object BotAdd : AuditLogEvent(28) - public object RoleCreate : AuditLogEvent(30) - public object RoleUpdate : AuditLogEvent(31) - public object RoleDelete : AuditLogEvent(32) - public object InviteCreate : AuditLogEvent(40) - public object InviteUpdate : AuditLogEvent(41) - public object InviteDelete : AuditLogEvent(42) - public object WebhookCreate : AuditLogEvent(50) - public object WebhookUpdate : AuditLogEvent(51) - public object WebhookDelete : AuditLogEvent(52) - public object EmojiCreate : AuditLogEvent(60) - public object EmojiUpdate : AuditLogEvent(61) - public object EmojiDelete : AuditLogEvent(62) - public object MessageDelete : AuditLogEvent(72) - public object MessageBulkDelete : AuditLogEvent(73) - public object MessagePin : AuditLogEvent(74) - public object MessageUnpin : AuditLogEvent(75) - public object IntegrationCreate : AuditLogEvent(80) - public object IntegrationUpdate : AuditLogEvent(81) - public object IntegrationDelete : AuditLogEvent(82) - public object StageInstanceCreate : AuditLogEvent(83) - public object StageInstanceUpdate : AuditLogEvent(84) - public object StageInstanceDelete : AuditLogEvent(85) - public object StickerCreate : AuditLogEvent(90) - public object StickerUpdate : AuditLogEvent(91) - public object StickerDelete : AuditLogEvent(92) - public object GuildScheduledEventCreate : AuditLogEvent(100) - public object GuildScheduledEventUpdate : AuditLogEvent(101) - public object GuildScheduledEventDelete : AuditLogEvent(102) - public object ThreadCreate : AuditLogEvent(110) - public object ThreadUpdate : AuditLogEvent(111) - public object ThreadDelete : AuditLogEvent(112) - public object ApplicationCommandPermissionUpdate : AuditLogEvent(121) - public object AutoModerationRuleCreate : AuditLogEvent(140) - public object AutoModerationRuleUpdate : AuditLogEvent(141) - public object AutoModerationRuleDelete : AuditLogEvent(142) - public object AutoModerationBlockMessage : AuditLogEvent(143) - - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.AuditLogEvent", PrimitiveKind.INT) - - override fun serialize(encoder: Encoder, value: AuditLogEvent) { - encoder.encodeInt(value.value) - } - - override fun deserialize(decoder: Decoder): AuditLogEvent = when (val value = decoder.decodeInt()) { - 1 -> GuildUpdate - 10 -> ChannelCreate - 11 -> ChannelUpdate - 12 -> ChannelDelete - 13 -> ChannelOverwriteCreate - 14 -> ChannelOverwriteUpdate - 15 -> ChannelOverwriteDelete - 20 -> MemberKick - 21 -> MemberPrune - 22 -> MemberBanAdd - 23 -> MemberBanRemove - 24 -> MemberUpdate - 25 -> MemberRoleUpdate - 26 -> MemberMove - 27 -> MemberDisconnect - 28 -> BotAdd - 30 -> RoleCreate - 31 -> RoleUpdate - 32 -> RoleDelete - 40 -> InviteCreate - 41 -> InviteUpdate - 42 -> InviteDelete - 50 -> WebhookCreate - 51 -> WebhookUpdate - 52 -> WebhookDelete - 60 -> EmojiCreate - 61 -> EmojiUpdate - 62 -> EmojiDelete - 72 -> MessageDelete - 73 -> MessageBulkDelete - 74 -> MessagePin - 75 -> MessageUnpin - 80 -> IntegrationCreate - 81 -> IntegrationUpdate - 82 -> IntegrationDelete - 83 -> StageInstanceCreate - 84 -> StageInstanceUpdate - 85 -> StageInstanceDelete - 90 -> StickerCreate - 91 -> StickerUpdate - 92 -> StickerDelete - 100 -> GuildScheduledEventCreate - 101 -> GuildScheduledEventUpdate - 102 -> GuildScheduledEventDelete - 110 -> ThreadCreate - 111 -> ThreadUpdate - 112 -> ThreadDelete - 121 -> ApplicationCommandPermissionUpdate - 140 -> AutoModerationRuleCreate - 141 -> AutoModerationRuleUpdate - 142 -> AutoModerationRuleDelete - 143 -> AutoModerationBlockMessage - else -> Unknown(value) - } - } - -} From da2767738311cfa135a07510fbb1ff4cfdb72968 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 01:08:29 +0200 Subject: [PATCH 15/47] Generate `AutoModerationRuleTriggerType`, `AutoModerationRuleKeywordPresetType`, `AutoModerationRuleEventType` and `AutoModerationActionType` --- common/api/common.api | 4 + .../common/entity/AutoModerationActionType.kt | 87 +++++++ .../entity/AutoModerationRuleEventType.kt | 67 +++++ .../AutoModerationRuleKeywordPresetType.kt | 81 ++++++ .../entity/AutoModerationRuleTriggerType.kt | 97 +++++++ .../dev/kord/common/entity/ChannelType.kt | 4 +- .../src/main/kotlin/entity/AutoModeration.kt | 237 +++++------------- .../src/main/kotlin/GenerateKordEnum.kt | 2 + .../src/main/kotlin/kordenum/KordEnum.kt | 4 +- .../kotlin/kordenum/KordEnumGeneration.kt | 4 +- 10 files changed, 406 insertions(+), 181 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt diff --git a/common/api/common.api b/common/api/common.api index 8972dbcdb084..09e1b4793c72 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -1112,6 +1112,7 @@ public final class dev/kord/common/entity/AutoModerationActionType$BlockMessage } public final class dev/kord/common/entity/AutoModerationActionType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -1136,6 +1137,7 @@ public abstract class dev/kord/common/entity/AutoModerationRuleEventType { } public final class dev/kord/common/entity/AutoModerationRuleEventType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -1156,6 +1158,7 @@ public abstract class dev/kord/common/entity/AutoModerationRuleKeywordPresetType } public final class dev/kord/common/entity/AutoModerationRuleKeywordPresetType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -1184,6 +1187,7 @@ public abstract class dev/kord/common/entity/AutoModerationRuleTriggerType { } public final class dev/kord/common/entity/AutoModerationRuleTriggerType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt new file mode 100644 index 000000000000..d2ad29aeec1a --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt @@ -0,0 +1,87 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * The type of action. + */ +@Serializable(with = AutoModerationActionType.Serializer::class) +public sealed class AutoModerationActionType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is AutoModerationActionType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [AutoModerationActionType]. + */ + public class Unknown( + `value`: Int, + ) : AutoModerationActionType(value) + + /** + * Blocks the content of a message according to the rule. + */ + public object BlockMessage : AutoModerationActionType(1) + + /** + * Logs user content to a specified channel. + */ + public object SendAlertMessage : AutoModerationActionType(2) + + /** + * Timeout user for a specified duration. + * + * A [Timeout] action can only be set up for + * [Keyword][dev.kord.common.entity.AutoModerationRuleTriggerType.Keyword] and + * [MentionSpam][dev.kord.common.entity.AutoModerationRuleTriggerType.MentionSpam] rules. The + * [ModerateMembers][dev.kord.common.entity.Permission.ModerateMembers] permission is required to + * use the [Timeout] action type. + */ + public object Timeout : AutoModerationActionType(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationActionType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: AutoModerationActionType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> BlockMessage + 2 -> SendAlertMessage + 3 -> Timeout + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + BlockMessage, + SendAlertMessage, + Timeout, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt new file mode 100644 index 000000000000..d46d4a928098 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt @@ -0,0 +1,67 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Indicates in what event context a rule should be checked. + */ +@Serializable(with = AutoModerationRuleEventType.Serializer::class) +public sealed class AutoModerationRuleEventType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is AutoModerationRuleEventType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [AutoModerationRuleEventType]. + */ + public class Unknown( + `value`: Int, + ) : AutoModerationRuleEventType(value) + + /** + * When a member sends or edits a message in the guild. + */ + public object MessageSend : AutoModerationRuleEventType(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleEventType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: AutoModerationRuleEventType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> MessageSend + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + MessageSend, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt new file mode 100644 index 000000000000..0647744ef399 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt @@ -0,0 +1,81 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * An internally pre-defined wordset which will be searched for in content. + */ +@Serializable(with = AutoModerationRuleKeywordPresetType.Serializer::class) +public sealed class AutoModerationRuleKeywordPresetType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is AutoModerationRuleKeywordPresetType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [AutoModerationRuleKeywordPresetType]. + */ + public class Unknown( + `value`: Int, + ) : AutoModerationRuleKeywordPresetType(value) + + /** + * Words that may be considered forms of swearing or cursing. + */ + public object Profanity : AutoModerationRuleKeywordPresetType(1) + + /** + * Words that refer to sexually explicit behavior or activity. + */ + public object SexualContent : AutoModerationRuleKeywordPresetType(2) + + /** + * Personal insults or words that may be considered hate speech. + */ + public object Slurs : AutoModerationRuleKeywordPresetType(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleKeywordPresetType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, + `value`: AutoModerationRuleKeywordPresetType) = encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Profanity + 2 -> SexualContent + 3 -> Slurs + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Profanity, + SexualContent, + Slurs, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt new file mode 100644 index 000000000000..4937d70dc4ae --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt @@ -0,0 +1,97 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import dev.kord.common.`annotation`.KordExperimental +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Characterizes the type of content which can trigger the rule. + */ +@Serializable(with = AutoModerationRuleTriggerType.Serializer::class) +public sealed class AutoModerationRuleTriggerType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is AutoModerationRuleTriggerType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [AutoModerationRuleTriggerType]. + */ + public class Unknown( + `value`: Int, + ) : AutoModerationRuleTriggerType(value) + + /** + * Check if content contains words from a user defined list of keywords. + */ + public object Keyword : AutoModerationRuleTriggerType(1) + + /** + * Check if content represents generic spam. + * + * This [trigger type][AutoModerationRuleTriggerType] is not yet released, so it cannot be used + * in most servers. + */ + @KordExperimental + public object Spam : AutoModerationRuleTriggerType(3) + + /** + * Check if content contains words from internal pre-defined wordsets. + */ + public object KeywordPreset : AutoModerationRuleTriggerType(4) + + /** + * Check if content contains more mentions than allowed. + * + * This [trigger type][AutoModerationRuleTriggerType] is not yet released, so it cannot be used + * in most servers. + */ + @KordExperimental + public object MentionSpam : AutoModerationRuleTriggerType(5) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleTriggerType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: AutoModerationRuleTriggerType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Keyword + 3 -> Spam + 4 -> KeywordPreset + 5 -> MentionSpam + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Keyword, + Spam, + KeywordPreset, + MentionSpam, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index 83e808cb8655..f209801a358b 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -24,8 +24,8 @@ import kotlinx.serialization.encoding.Encoder public sealed class ChannelType( public val `value`: Int, ) { - public final override fun equals(other: Any?): Boolean = this === other || (other is ChannelType - && this.value == other.value) + public final override fun equals(other: Any?): Boolean = this === other || + (other is ChannelType && this.value == other.value) public final override fun hashCode(): Int = value.hashCode() diff --git a/common/src/main/kotlin/entity/AutoModeration.kt b/common/src/main/kotlin/entity/AutoModeration.kt index a8a56ece30f4..c3712b7fb452 100644 --- a/common/src/main/kotlin/entity/AutoModeration.kt +++ b/common/src/main/kotlin/entity/AutoModeration.kt @@ -1,20 +1,71 @@ +@file:GenerateKordEnum( + name = "AutoModerationRuleTriggerType", valueType = INT, + kDoc = "Characterizes the type of content which can trigger the rule.", + entries = [ + Entry("Keyword", intValue = 1, kDoc = "Check if content contains words from a user defined list of keywords."), + Entry( + "Spam", intValue = 3, isKordExperimental = true, + kDoc = "Check if content represents generic spam.\n\nThis [trigger type][AutoModerationRuleTriggerType] " + + "is not yet released, so it cannot be used in most servers." + ), + Entry( + "KeywordPreset", intValue = 4, + kDoc = "Check if content contains words from internal pre-defined wordsets." + ), + Entry( + "MentionSpam", intValue = 5, isKordExperimental = true, + kDoc = "Check if content contains more mentions than allowed.\n\nThis [trigger type][" + + "AutoModerationRuleTriggerType] is not yet released, so it cannot be used in most servers." + ), + ], +) + +@file:GenerateKordEnum( + name = "AutoModerationRuleKeywordPresetType", valueType = INT, + kDoc = "An internally pre-defined wordset which will be searched for in content.", + entries = [ + Entry("Profanity", intValue = 1, kDoc = "Words that may be considered forms of swearing or cursing."), + Entry("SexualContent", intValue = 2, kDoc = "Words that refer to sexually explicit behavior or activity."), + Entry("Slurs", intValue = 3, kDoc = "Personal insults or words that may be considered hate speech."), + ], +) + +@file:GenerateKordEnum( + name = "AutoModerationRuleEventType", valueType = INT, + kDoc = "Indicates in what event context a rule should be checked.", + entries = [ + Entry("MessageSend", intValue = 1, kDoc = "When a member sends or edits a message in the guild."), + ], +) + +@file:GenerateKordEnum( + name = "AutoModerationActionType", valueType = INT, + kDoc = "The type of action.", + entries = [ + Entry("BlockMessage", intValue = 1, kDoc = "Blocks the content of a message according to the rule."), + Entry("SendAlertMessage", intValue = 2, kDoc = "Logs user content to a specified channel."), + Entry( + "Timeout", intValue = 3, + kDoc = "Timeout user for a specified duration.\n\nA [Timeout] action can only be set up for " + + "[Keyword][dev.kord.common.entity.AutoModerationRuleTriggerType.Keyword] and " + + "[MentionSpam][dev.kord.common.entity.AutoModerationRuleTriggerType.MentionSpam] rules. The " + + "[ModerateMembers][dev.kord.common.entity.Permission.ModerateMembers] permission is required to " + + "use the [Timeout] action type." + ), + ], +) + package dev.kord.common.entity -import dev.kord.common.annotation.KordExperimental -import dev.kord.common.entity.AutoModerationRuleTriggerType.Keyword -import dev.kord.common.entity.AutoModerationRuleTriggerType.MentionSpam -import dev.kord.common.entity.Permission.ModerateMembers import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.DurationInSeconds -import kotlinx.serialization.KSerializer +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.descriptors.PrimitiveKind -import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder @Serializable public data class DiscordAutoModerationRule( @@ -38,59 +89,6 @@ public data class DiscordAutoModerationRule( val exemptChannels: List, ) -/** Characterizes the type of content which can trigger the rule. */ -@Serializable(with = AutoModerationRuleTriggerType.Serializer::class) -public sealed class AutoModerationRuleTriggerType(public val value: Int) { - - final override fun equals(other: Any?): Boolean = - this === other || (other is AutoModerationRuleTriggerType && this.value == other.value) - - final override fun hashCode(): Int = value - - - /** An unknown [AutoModerationRuleTriggerType]. */ - public class Unknown(value: Int) : AutoModerationRuleTriggerType(value) - - /** Check if content contains words from a user defined list of keywords. */ - public object Keyword : AutoModerationRuleTriggerType(1) - - /** - * Check if content represents generic spam. - * - * This [trigger type][AutoModerationRuleTriggerType] is not yet released, so it cannot be used in most servers. - */ - @KordExperimental - public object Spam : AutoModerationRuleTriggerType(3) - - /** Check if content contains words from internal pre-defined wordsets. */ - public object KeywordPreset : AutoModerationRuleTriggerType(4) - - /** - * Check if content contains more mentions than allowed. - * - * This [trigger type][AutoModerationRuleTriggerType] is not yet released, so it cannot be used in most servers. - */ - @KordExperimental - public object MentionSpam : AutoModerationRuleTriggerType(5) - - - internal object Serializer : KSerializer { - - override val descriptor = - PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleTriggerType", PrimitiveKind.INT) - - override fun serialize(encoder: Encoder, value: AutoModerationRuleTriggerType) = encoder.encodeInt(value.value) - - override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { - 1 -> Keyword - 3 -> Spam - 4 -> KeywordPreset - 5 -> MentionSpam - else -> Unknown(value) - } - } -} - @Serializable public data class DiscordAutoModerationRuleTriggerMetadata( @SerialName("keyword_filter") @@ -102,127 +100,12 @@ public data class DiscordAutoModerationRuleTriggerMetadata( val mentionTotalLimit: OptionalInt = OptionalInt.Missing, ) -/** An internally pre-defined wordset which will be searched for in content. */ -@Serializable(with = AutoModerationRuleKeywordPresetType.Serializer::class) -public sealed class AutoModerationRuleKeywordPresetType(public val value: Int) { - - final override fun equals(other: Any?): Boolean = - this === other || (other is AutoModerationRuleKeywordPresetType && this.value == other.value) - - final override fun hashCode(): Int = value - - - /** An unknown [AutoModerationRuleKeywordPresetType]. */ - public class Unknown(value: Int) : AutoModerationRuleKeywordPresetType(value) - - /** Words that may be considered forms of swearing or cursing. */ - public object Profanity : AutoModerationRuleKeywordPresetType(1) - - /** Words that refer to sexually explicit behavior or activity. */ - public object SexualContent : AutoModerationRuleKeywordPresetType(2) - - /** Personal insults or words that may be considered hate speech. */ - public object Slurs : AutoModerationRuleKeywordPresetType(3) - - - internal object Serializer : KSerializer { - - override val descriptor = - PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleKeywordPresetType", PrimitiveKind.INT) - - override fun serialize(encoder: Encoder, value: AutoModerationRuleKeywordPresetType) = - encoder.encodeInt(value.value) - - override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { - 1 -> Profanity - 2 -> SexualContent - 3 -> Slurs - else -> Unknown(value) - } - } -} - -/** Indicates in what event context a rule should be checked. */ -@Serializable(with = AutoModerationRuleEventType.Serializer::class) -public sealed class AutoModerationRuleEventType(public val value: Int) { - - final override fun equals(other: Any?): Boolean = - this === other || (other is AutoModerationRuleEventType && this.value == other.value) - - final override fun hashCode(): Int = value - - - /** An unknown [AutoModerationRuleEventType]. */ - public class Unknown(value: Int) : AutoModerationRuleEventType(value) - - /** When a member sends or edits a message in the guild. */ - public object MessageSend : AutoModerationRuleEventType(1) - - - internal object Serializer : KSerializer { - - override val descriptor = - PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleEventType", PrimitiveKind.INT) - - override fun serialize(encoder: Encoder, value: AutoModerationRuleEventType) = encoder.encodeInt(value.value) - - override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { - 1 -> MessageSend - else -> Unknown(value) - } - } -} - @Serializable public data class DiscordAutoModerationAction( val type: AutoModerationActionType, val metadata: Optional = Optional.Missing(), ) -/** The type of action. */ -@Serializable(with = AutoModerationActionType.Serializer::class) -public sealed class AutoModerationActionType(public val value: Int) { - - final override fun equals(other: Any?): Boolean = - this === other || (other is AutoModerationActionType && this.value == other.value) - - final override fun hashCode(): Int = value - - - /** An unknown [AutoModerationActionType]. */ - public class Unknown(value: Int) : AutoModerationActionType(value) - - /** Blocks the content of a message according to the rule. */ - public object BlockMessage : AutoModerationActionType(1) - - /** Logs user content to a specified channel. */ - public object SendAlertMessage : AutoModerationActionType(2) - - /** - * Timeout user for a specified duration. - * - * A [Timeout] action can only be set up for [Keyword] and [MentionSpam] rules. The [ModerateMembers] permission is - * required to use the [Timeout] action type. - */ - public object Timeout : AutoModerationActionType(3) - - - internal object Serializer : KSerializer { - - override val descriptor = - PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationActionType", PrimitiveKind.INT) - - override fun serialize(encoder: Encoder, value: AutoModerationActionType) = encoder.encodeInt(value.value) - - override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { - 1 -> BlockMessage - 2 -> SendAlertMessage - 3 -> Timeout - else -> Unknown(value) - } - } -} - @Serializable public data class DiscordAutoModerationActionMetadata( @SerialName("channel_id") diff --git a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt index 3394a5d55e79..344897b0f205 100644 --- a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt +++ b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt @@ -47,6 +47,8 @@ annotation class GenerateKordEnum( val stringValue: String = DEFAULT_STRING_VALUE, /** KDoc for the entry (optional). */ val kDoc: String = "", + /** Whether to add `@KordExperimental` to this entry. */ + val isKordExperimental: Boolean = false, /** [Deprecated.message] for a [deprecated entry][GenerateKordEnum.deprecatedEntries]. */ val deprecationMessage: String = "", /** [Deprecated.replaceWith] for a [deprecated entry][GenerateKordEnum.deprecatedEntries]. */ diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt index d5fe04e2f23c..5e77b8fada19 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt @@ -31,6 +31,7 @@ internal class KordEnum( val name: String, val kDoc: String?, val value: Comparable<*>, + val isKordExperimental: Boolean, val isDeprecated: Boolean, val deprecationMessage: String, val replaceWith: ReplaceWith, @@ -104,6 +105,7 @@ private fun Any?.toEntryOrNull(valueType: ValueType, isDeprecated: Boolean, logg val intValue = args[GenerateKordEnum.Entry::intValue] as Int val stringValue = args[GenerateKordEnum.Entry::stringValue] as String val kDoc = args[GenerateKordEnum.Entry::kDoc].toKDoc() + val isKordExperimental = args[GenerateKordEnum.Entry::isKordExperimental] as Boolean val deprecationMessage = args[GenerateKordEnum.Entry::deprecationMessage] as String val replaceWith = args[GenerateKordEnum.Entry::replaceWith].toReplaceWith() val deprecationLevel = args[GenerateKordEnum.Entry::deprecationLevel].toDeprecationLevel() @@ -155,7 +157,7 @@ private fun Any?.toEntryOrNull(valueType: ValueType, isDeprecated: Boolean, logg } } - return Entry(name, kDoc, value, isDeprecated, deprecationMessage, replaceWith, deprecationLevel) + return Entry(name, kDoc, value, isKordExperimental, isDeprecated, deprecationMessage, replaceWith, deprecationLevel) } /** Maps [KSAnnotation] to [ReplaceWith]. */ diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 9bf6c35e9d10..5dda4f4b79f8 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -26,6 +26,7 @@ import com.squareup.kotlinpoet.SET as SET_CLASS_NAME import com.squareup.kotlinpoet.STRING as STRING_CLASS_NAME private val PRIMITIVE_SERIAL_DESCRIPTOR = MemberName("kotlinx.serialization.descriptors", "PrimitiveSerialDescriptor") +private val KORD_EXPERIMENTAL = ClassName("dev.kord.common.annotation", "KordExperimental") private val Entry.warningSuppressedName get() = when { @@ -121,7 +122,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addModifiers(FINAL, OVERRIDE) returns() addParameter("other") - addStatement("return this·===·other || (other·is·%T && this.$valueName·==·other.$valueName)", enumName) + addStatement("return this·===·other || (other·is·%T·&&·this.$valueName·==·other.$valueName)", enumName) } // final override fun hashCode @@ -147,6 +148,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { fun TypeSpec.Builder.entry(entry: Entry) { entry.kDoc?.let { addKdoc(it) } + if (entry.isKordExperimental) addAnnotation(KORD_EXPERIMENTAL) addModifiers(PUBLIC) superclass(enumName) addSuperclassConstructorParameter(valueFormat, entry.value) From 5dfba4fb7135aae70da5d1bc369da03d79b9f3dd Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 15:28:55 +0200 Subject: [PATCH 16/47] Generate `OverwriteType` and `VideoQualityMode` --- common/api/common.api | 4 ++ .../dev/kord/common/entity/OverwriteType.kt | 64 +++++++++++++++++ .../kord/common/entity/VideoQualityMode.kt | 71 +++++++++++++++++++ .../src/main/kotlin/entity/DiscordChannel.kt | 71 ++++--------------- 4 files changed, 152 insertions(+), 58 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt diff --git a/common/api/common.api b/common/api/common.api index 09e1b4793c72..3187faf25689 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -6983,10 +6983,13 @@ public final class dev/kord/common/entity/Overwrite$Companion { public abstract class dev/kord/common/entity/OverwriteType { public static final field Companion Ldev/kord/common/entity/OverwriteType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/OverwriteType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -7732,6 +7735,7 @@ public final class dev/kord/common/entity/VideoQualityMode$Auto : dev/kord/commo } public final class dev/kord/common/entity/VideoQualityMode$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt new file mode 100644 index 000000000000..9a47e6928ce1 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt @@ -0,0 +1,64 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = OverwriteType.Serializer::class) +public sealed class OverwriteType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is OverwriteType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [OverwriteType]. + */ + public class Unknown( + `value`: Int, + ) : OverwriteType(value) + + public object Role : OverwriteType(0) + + public object Member : OverwriteType(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.OverwriteType", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: OverwriteType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> Role + 1 -> Member + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Role, + Member, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt new file mode 100644 index 000000000000..7d314f147385 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt @@ -0,0 +1,71 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = VideoQualityMode.Serializer::class) +public sealed class VideoQualityMode( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is VideoQualityMode && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [VideoQualityMode]. + */ + public class Unknown( + `value`: Int, + ) : VideoQualityMode(value) + + /** + * Discord chooses the quality for optimal performance. + */ + public object Auto : VideoQualityMode(1) + + /** + * 720p. + */ + public object Full : VideoQualityMode(2) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.VideoQualityMode", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: VideoQualityMode) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Auto + 2 -> Full + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Auto, + Full, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordChannel.kt b/common/src/main/kotlin/entity/DiscordChannel.kt index ce4714f43c8c..0bd43fd54faa 100644 --- a/common/src/main/kotlin/entity/DiscordChannel.kt +++ b/common/src/main/kotlin/entity/DiscordChannel.kt @@ -57,6 +57,19 @@ ], ) +@file:GenerateKordEnum( + name = "VideoQualityMode", valueType = INT, + entries = [ + Entry("Auto", intValue = 1, kDoc = "Discord chooses the quality for optimal performance."), + Entry("Full", intValue = 2, kDoc = "720p."), + ], +) + +@file:GenerateKordEnum( + name = "OverwriteType", valueType = INT, + entries = [Entry("Role", intValue = 0), Entry("Member", intValue = 1)], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional @@ -72,8 +85,6 @@ import kotlinx.datetime.Instant import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName 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 @@ -157,62 +168,6 @@ public data class Overwrite( val deny: Permissions, ) -@Serializable(with = OverwriteType.Serializer::class) -public sealed class OverwriteType(public val value: Int) { - - public class Unknown(value: Int) : OverwriteType(value) - public object Role : OverwriteType(0) - public object Member : OverwriteType(1) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.Overwrite.Type", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): OverwriteType = when (val value = decoder.decodeInt()) { - 0 -> Role - 1 -> Member - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: OverwriteType) { - encoder.encodeInt(value.value) - } - } -} - -@Serializable(with = VideoQualityMode.Serializer::class) -public sealed class VideoQualityMode(public val value: Int) { - - final override fun equals(other: Any?): Boolean = - this === other || (other is VideoQualityMode && other.value == this.value) - - final override fun hashCode(): Int = value - - - /** An unknown Video Quality Mode. */ - public class Unknown(value: Int) : VideoQualityMode(value) - - /** Discord chooses the quality for optimal performance. */ - public object Auto : VideoQualityMode(1) - - /** 720p. */ - public object Full : VideoQualityMode(2) - - - internal object Serializer : KSerializer { - override val descriptor = - PrimitiveSerialDescriptor("dev.kord.common.entity.VideoQualityMode", PrimitiveKind.INT) - - override fun serialize(encoder: Encoder, value: VideoQualityMode) = encoder.encodeInt(value.value) - - override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { - 1 -> Auto - 2 -> Full - else -> Unknown(value) - } - } -} - @Serializable public data class DiscordThreadMetadata( val archived: Boolean, From c39aaff4f094a360a719996692a38568396f62c7 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 16:09:36 +0200 Subject: [PATCH 17/47] Generate `ComponentType`, `ButtonStyle` and `TextInputStyle` --- common/api/common.api | 44 ++-- .../dev/kord/common/entity/AuditLogEvent.kt | 2 + .../common/entity/AutoModerationActionType.kt | 3 + .../entity/AutoModerationRuleEventType.kt | 3 + .../AutoModerationRuleKeywordPresetType.kt | 3 + .../entity/AutoModerationRuleTriggerType.kt | 3 + .../dev/kord/common/entity/ButtonStyle.kt | 99 +++++++++ .../dev/kord/common/entity/ChannelType.kt | 2 + .../dev/kord/common/entity/ComponentType.kt | 86 ++++++++ .../kord/common/entity/MessageStickerType.kt | 2 + .../dev/kord/common/entity/OverwriteType.kt | 2 + .../dev/kord/common/entity/TextInputStyle.kt | 76 +++++++ .../kord/common/entity/VideoQualityMode.kt | 2 + .../src/main/kotlin/entity/AutoModeration.kt | 4 +- .../main/kotlin/entity/DiscordComponent.kt | 193 ++++-------------- .../kotlin/kordenum/KordEnumGeneration.kt | 5 +- 16 files changed, 350 insertions(+), 179 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt diff --git a/common/api/common.api b/common/api/common.api index 3187faf25689..8bfa69fda6f6 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -1281,9 +1281,16 @@ public final class dev/kord/common/entity/BulkDeleteData$Companion { } public abstract class dev/kord/common/entity/ButtonStyle { - public static final field Serializer Ldev/kord/common/entity/ButtonStyle$Serializer; + public static final field Companion Ldev/kord/common/entity/ButtonStyle$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I +} + +public final class dev/kord/common/entity/ButtonStyle$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } public final class dev/kord/common/entity/ButtonStyle$Danger : dev/kord/common/entity/ButtonStyle { @@ -1302,15 +1309,6 @@ public final class dev/kord/common/entity/ButtonStyle$Secondary : dev/kord/commo public static final field INSTANCE Ldev/kord/common/entity/ButtonStyle$Secondary; } -public final class dev/kord/common/entity/ButtonStyle$Serializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/ButtonStyle; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/ButtonStyle;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - public final class dev/kord/common/entity/ButtonStyle$Success : dev/kord/common/entity/ButtonStyle { public static final field INSTANCE Ldev/kord/common/entity/ButtonStyle$Success; } @@ -1649,9 +1647,11 @@ public final class dev/kord/common/entity/CommandGroup : dev/kord/common/entity/ } public abstract class dev/kord/common/entity/ComponentType { - public static final field Serializer Ldev/kord/common/entity/ComponentType$Serializer; + public static final field Companion Ldev/kord/common/entity/ComponentType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/ComponentType$ActionRow : dev/kord/common/entity/ComponentType { @@ -1662,17 +1662,13 @@ public final class dev/kord/common/entity/ComponentType$Button : dev/kord/common public static final field INSTANCE Ldev/kord/common/entity/ComponentType$Button; } -public final class dev/kord/common/entity/ComponentType$SelectMenu : dev/kord/common/entity/ComponentType { - public static final field INSTANCE Ldev/kord/common/entity/ComponentType$SelectMenu; +public final class dev/kord/common/entity/ComponentType$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public final class dev/kord/common/entity/ComponentType$Serializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/ComponentType; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/ComponentType;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; +public final class dev/kord/common/entity/ComponentType$SelectMenu : dev/kord/common/entity/ComponentType { + public static final field INSTANCE Ldev/kord/common/entity/ComponentType$SelectMenu; } public final class dev/kord/common/entity/ComponentType$TextInput : dev/kord/common/entity/ComponentType { @@ -7590,8 +7586,16 @@ public final class dev/kord/common/entity/TeamMembershipState$Unknown : dev/kord } public abstract class dev/kord/common/entity/TextInputStyle { + public static final field Companion Ldev/kord/common/entity/TextInputStyle$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I +} + +public final class dev/kord/common/entity/TextInputStyle$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } public final class dev/kord/common/entity/TextInputStyle$Paragraph : dev/kord/common/entity/TextInputStyle { diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt index 844b22e09c64..42f34963ce7e 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt @@ -29,6 +29,8 @@ public sealed class AuditLogEvent( /** * An unknown [AuditLogEvent]. + * + * This is used as a fallback for [AuditLogEvent]s that haven't been added to Kord yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt index d2ad29aeec1a..bded2a1ab683 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt @@ -32,6 +32,9 @@ public sealed class AutoModerationActionType( /** * An unknown [AutoModerationActionType]. + * + * This is used as a fallback for [AutoModerationActionType]s that haven't been added to Kord + * yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt index d46d4a928098..53277d626377 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt @@ -32,6 +32,9 @@ public sealed class AutoModerationRuleEventType( /** * An unknown [AutoModerationRuleEventType]. + * + * This is used as a fallback for [AutoModerationRuleEventType]s that haven't been added to Kord + * yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt index 0647744ef399..05af1af6be66 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt @@ -32,6 +32,9 @@ public sealed class AutoModerationRuleKeywordPresetType( /** * An unknown [AutoModerationRuleKeywordPresetType]. + * + * This is used as a fallback for [AutoModerationRuleKeywordPresetType]s that haven't been added + * to Kord yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt index 4937d70dc4ae..424ea409f39c 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt @@ -33,6 +33,9 @@ public sealed class AutoModerationRuleTriggerType( /** * An unknown [AutoModerationRuleTriggerType]. + * + * This is used as a fallback for [AutoModerationRuleTriggerType]s that haven't been added to + * Kord yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt new file mode 100644 index 000000000000..75f6121495b5 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt @@ -0,0 +1,99 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Style of a [button][dev.kord.common.entity.ComponentType.Button]. + * + * A preview of the different styles can be found + * [here](https://discord.com/developers/docs/interactions/message-components#button-object-button-styles). + */ +@Serializable(with = ButtonStyle.Serializer::class) +public sealed class ButtonStyle( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is ButtonStyle && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [ButtonStyle]. + * + * This is used as a fallback for [ButtonStyle]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : ButtonStyle(value) + + /** + * Blurple. + */ + public object Primary : ButtonStyle(1) + + /** + * Grey. + */ + public object Secondary : ButtonStyle(2) + + /** + * Green. + */ + public object Success : ButtonStyle(3) + + /** + * Red. + */ + public object Danger : ButtonStyle(4) + + /** + * Grey, navigates to a URL. + */ + public object Link : ButtonStyle(5) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ButtonStyle", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ButtonStyle) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Primary + 2 -> Secondary + 3 -> Success + 4 -> Danger + 5 -> Link + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Primary, + Secondary, + Success, + Danger, + Link, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index f209801a358b..2180850dda45 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -31,6 +31,8 @@ public sealed class ChannelType( /** * An unknown [ChannelType]. + * + * This is used as a fallback for [ChannelType]s that haven't been added to Kord yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt new file mode 100644 index 000000000000..496c3eb31a87 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt @@ -0,0 +1,86 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = ComponentType.Serializer::class) +public sealed class ComponentType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is ComponentType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [ComponentType]. + * + * This is used as a fallback for [ComponentType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : ComponentType(value) + + /** + * A container for other components. + */ + public object ActionRow : ComponentType(1) + + /** + * A button object. + */ + public object Button : ComponentType(2) + + /** + * A select menu for picking from choices. + */ + public object SelectMenu : ComponentType(3) + + /** + * A text input object. + */ + public object TextInput : ComponentType(4) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ComponentType", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ComponentType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> ActionRow + 2 -> Button + 3 -> SelectMenu + 4 -> TextInput + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + ActionRow, + Button, + SelectMenu, + TextInput, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt index 7020c0b8ba0d..868a099c6f7b 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt @@ -32,6 +32,8 @@ public sealed class MessageStickerType( /** * An unknown [MessageStickerType]. + * + * This is used as a fallback for [MessageStickerType]s that haven't been added to Kord yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt index 9a47e6928ce1..e4622d10029a 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt @@ -29,6 +29,8 @@ public sealed class OverwriteType( /** * An unknown [OverwriteType]. + * + * This is used as a fallback for [OverwriteType]s that haven't been added to Kord yet. */ public class Unknown( `value`: Int, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt new file mode 100644 index 000000000000..5d1ad73ecb8b --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt @@ -0,0 +1,76 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Style of a [text input][dev.kord.common.entity.ComponentType.TextInput] + */ +@Serializable(with = TextInputStyle.Serializer::class) +public sealed class TextInputStyle( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is TextInputStyle && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [TextInputStyle]. + * + * This is used as a fallback for [TextInputStyle]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : TextInputStyle(value) + + /** + * A single-line input. + */ + public object Short : TextInputStyle(1) + + /** + * A multi-line input. + */ + public object Paragraph : TextInputStyle(2) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.TextInputStyle", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: TextInputStyle) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Short + 2 -> Paragraph + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Short, + Paragraph, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt index 7d314f147385..8ede6a80e222 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt @@ -29,6 +29,8 @@ public sealed class VideoQualityMode( /** * An unknown [VideoQualityMode]. + * + * This is used as a fallback for [VideoQualityMode]s that haven't been added to Kord yet. */ public class Unknown( `value`: Int, diff --git a/common/src/main/kotlin/entity/AutoModeration.kt b/common/src/main/kotlin/entity/AutoModeration.kt index c3712b7fb452..a9864d19c696 100644 --- a/common/src/main/kotlin/entity/AutoModeration.kt +++ b/common/src/main/kotlin/entity/AutoModeration.kt @@ -5,7 +5,7 @@ Entry("Keyword", intValue = 1, kDoc = "Check if content contains words from a user defined list of keywords."), Entry( "Spam", intValue = 3, isKordExperimental = true, - kDoc = "Check if content represents generic spam.\n\nThis [trigger type][AutoModerationRuleTriggerType] " + + kDoc = "Check if content represents generic spam.\n\nThis [trigger·type][AutoModerationRuleTriggerType] " + "is not yet released, so it cannot be used in most servers." ), Entry( @@ -14,7 +14,7 @@ ), Entry( "MentionSpam", intValue = 5, isKordExperimental = true, - kDoc = "Check if content contains more mentions than allowed.\n\nThis [trigger type][" + + kDoc = "Check if content contains more mentions than allowed.\n\nThis [trigger·type][" + "AutoModerationRuleTriggerType] is not yet released, so it cannot be used in most servers." ), ], diff --git a/common/src/main/kotlin/entity/DiscordComponent.kt b/common/src/main/kotlin/entity/DiscordComponent.kt index 5d97a1fb5035..942c22c26559 100644 --- a/common/src/main/kotlin/entity/DiscordComponent.kt +++ b/common/src/main/kotlin/entity/DiscordComponent.kt @@ -1,21 +1,48 @@ +@file:GenerateKordEnum( + name = "ComponentType", valueType = INT, + entries = [ + Entry("ActionRow", intValue = 1, kDoc = "A container for other components."), + Entry("Button", intValue = 2, kDoc = "A button object."), + Entry("SelectMenu", intValue = 3, kDoc = "A select menu for picking from choices."), + Entry("TextInput", intValue = 4, kDoc = "A text input object."), + ], +) + +@file:GenerateKordEnum( + name = "ButtonStyle", valueType = INT, + kDoc = "Style of a [button][dev.kord.common.entity.ComponentType.Button].\n\nA preview of the different styles " + + "can be found " + + "[here](https://discord.com/developers/docs/interactions/message-components#button-object-button-styles).", + entries = [ + Entry("Primary", intValue = 1, kDoc = "Blurple."), + Entry("Secondary", intValue = 2, kDoc = "Grey."), + Entry("Success", intValue = 3, kDoc = "Green."), + Entry("Danger", intValue = 4, kDoc = "Red."), + Entry("Link", intValue = 5, kDoc = "Grey, navigates to a URL."), + ], +) + +@file:GenerateKordEnum( + name = "TextInputStyle", valueType = INT, + kDoc = "Style of a [text·input][dev.kord.common.entity.ComponentType.TextInput]", + entries = [ + Entry("Short", intValue = 1, kDoc = "A single-line input."), + Entry("Paragraph", intValue = 2, kDoc = "A multi-line input."), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.OptionalInt +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName 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 -import kotlinx.serialization.json.JsonContentPolymorphicSerializer -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.intOrNull -import kotlinx.serialization.json.jsonObject -import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.* /** * Represent a [interactable component within a message sent in Discord](https://discord.com/developers/docs/interactions/message-components#what-are-components). @@ -120,149 +147,3 @@ public data class DiscordTextInputComponent( override val required: OptionalBoolean = OptionalBoolean.Missing, override val value: Optional = Optional.Missing() ) : DiscordComponent() - -/** - * Representation of different [DiscordComponent] types. - * - * @property value the raw type value used by the Discord API - */ -@Serializable(with = ComponentType.Serializer::class) -public sealed class ComponentType(public val value: Int) { - /** - * Fallback type used for types that haven't been added to Kord yet. - */ - public class Unknown(value: Int) : ComponentType(value) - - /** - * A container for other components. - */ - public object ActionRow : ComponentType(1) - - /** - * A clickable button. - */ - public object Button : ComponentType(2) - - /** - * A select menu for picking from choices. - */ - public object SelectMenu : ComponentType(3) - - /** - * A text input object. - */ - public object TextInput : ComponentType(4) - - public companion object Serializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("ComponentType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): ComponentType = - when (val value = decoder.decodeInt()) { - 1 -> ActionRow - 2 -> Button - 3 -> SelectMenu - 4 -> TextInput - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: ComponentType): Unit = encoder.encodeInt(value.value) - } -} - -/** - * Representation of different ButtonStyles. - * - * A cheat sheet on how the styles look like can be found [here](https://discord.com/assets/7bb017ce52cfd6575e21c058feb3883b.png) - * - * @see ComponentType.Button - */ -@Serializable(with = ButtonStyle.Serializer::class) -public sealed class ButtonStyle(public val value: Int) { - - /** - * A fallback style used for styles that haven't been added to Kord yet. - */ - public class Unknown(value: Int) : ButtonStyle(value) - - /** - * Blurple. - * Requires: [DiscordComponent.customId] - */ - public object Primary : ButtonStyle(1) - - /** - * Grey. - * Requires: [DiscordComponent.customId] - */ - public object Secondary : ButtonStyle(2) - - /** - * Green - * Requires: [DiscordComponent.customId] - */ - public object Success : ButtonStyle(3) - - /** - * Red. - * Requires: [DiscordComponent.customId] - */ - public object Danger : ButtonStyle(4) - - /** - * Grey, navigates to an URL. - * Requires: [DiscordComponent.url] - */ - public object Link : ButtonStyle(5) - - public companion object Serializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Button", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): ButtonStyle = - when (val value = decoder.decodeInt()) { - 1 -> Primary - 2 -> Secondary - 3 -> Success - 4 -> Danger - 5 -> Link - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: ButtonStyle): Unit = encoder.encodeInt(value.value) - } -} - -/** - * Representation of different TextInputStyles. - * - * @see ComponentType.TextInput - */ -@Serializable(with = TextInputStyle.Serializer::class) -public sealed class TextInputStyle(public val value: Int) { - /** - * A fallback style used for styles that haven't been added to Kord yet. - */ - public class Unknown(value: Int) : TextInputStyle(value) - - /** - * A single-line input. - */ - public object Short : TextInputStyle(1) - - /** - * A multi-line input. - */ - public object Paragraph : TextInputStyle(2) - - internal companion object Serializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("TextInput", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): TextInputStyle = - when (val value = decoder.decodeInt()) { - 1 -> Short - 2 -> Paragraph - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: TextInputStyle): Unit = encoder.encodeInt(value.value) - } -} \ No newline at end of file diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 5dda4f4b79f8..4aecc0f691f5 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -136,7 +136,10 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { // /** An unknown []. */ // public class Unknown(: ) : () addClass("Unknown") { - addKdoc("An unknown [%T].", enumName) + addKdoc( + "An unknown [%1T].\n\nThis is used as a fallback for [%1T]s that haven't been added to Kord yet.", + enumName, + ) addModifiers(PUBLIC) primaryConstructor { addParameter(valueName, valueTypeName) From b2ec6434b4d6d8c4288207df67307d3f6a9f02d2 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 16:18:34 +0200 Subject: [PATCH 18/47] Generate `DiscordConnectionVisibility` --- common/api/common.api | 3 + .../entity/DiscordConnectionVisibility.kt | 74 +++++++++++++++++++ .../main/kotlin/entity/DiscordConnection.kt | 49 +++--------- .../kotlin/kordenum/KordEnumGeneration.kt | 1 - 4 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt diff --git a/common/api/common.api b/common/api/common.api index 8bfa69fda6f6..fadcefae65b7 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -2822,10 +2822,13 @@ public final class dev/kord/common/entity/DiscordConnection$Companion { public abstract class dev/kord/common/entity/DiscordConnectionVisibility { public static final field Companion Ldev/kord/common/entity/DiscordConnectionVisibility$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/DiscordConnectionVisibility$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt new file mode 100644 index 000000000000..026064e5f922 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt @@ -0,0 +1,74 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = DiscordConnectionVisibility.Serializer::class) +public sealed class DiscordConnectionVisibility( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is DiscordConnectionVisibility && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [DiscordConnectionVisibility]. + * + * This is used as a fallback for [DiscordConnectionVisibility]s that haven't been added to Kord + * yet. + */ + public class Unknown( + `value`: Int, + ) : DiscordConnectionVisibility(value) + + /** + * Invisible to everyone except the user themselves. + */ + public object None : DiscordConnectionVisibility(0) + + /** + * Visible to everyone. + */ + public object Everyone : DiscordConnectionVisibility(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.DiscordConnectionVisibility", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: DiscordConnectionVisibility) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> None + 1 -> Everyone + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + None, + Everyone, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordConnection.kt b/common/src/main/kotlin/entity/DiscordConnection.kt index 274a8083e4cf..5794c0e82e1f 100644 --- a/common/src/main/kotlin/entity/DiscordConnection.kt +++ b/common/src/main/kotlin/entity/DiscordConnection.kt @@ -1,15 +1,20 @@ +@file:GenerateKordEnum( + name = "DiscordConnectionVisibility", valueType = INT, + entries = [ + Entry("None", intValue = 0, kDoc = "Invisible to everyone except the user themselves."), + Entry("Everyone", intValue = 1, kDoc = "Visible to everyone."), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean -import kotlinx.serialization.KSerializer +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.SerialName 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 /** * A representation of the D[Discord Connection Object structure](https://discord.com/developers/docs/resources/user#connection-object). @@ -39,35 +44,3 @@ public data class DiscordConnection( val showActivity: Boolean, val visibility: DiscordConnectionVisibility, ) - -@Serializable(with = DiscordConnectionVisibility.Serializer::class) -public sealed class DiscordConnectionVisibility(public val value: Int) { - public class Unknown(value: Int) : DiscordConnectionVisibility(value) - - /** - * The connection is invisible to everyone except the user themselves. - */ - public object None : DiscordConnectionVisibility(0) - - /** - * The connection is visible to everyone. - */ - public object Everyone : DiscordConnectionVisibility(1) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.DiscordConnectionVisibility", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): DiscordConnectionVisibility = - when (val value = decoder.decodeInt()) { - 0 -> None - 1 -> Everyone - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: DiscordConnectionVisibility) { - encoder.encodeInt(value.value) - } - } - -} diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 4aecc0f691f5..7bedef43d095 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -133,7 +133,6 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } - // /** An unknown []. */ // public class Unknown(: ) : () addClass("Unknown") { addKdoc( From 780113e706d46b61ee1452d2325ebb9b2718c002 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 16:56:00 +0200 Subject: [PATCH 19/47] Generate `GuildFeature` --- common/api/common.api | 1 + .../dev/kord/common/entity/GuildFeature.kt | 232 ++++++++++++++++++ common/src/main/kotlin/entity/DiscordGuild.kt | 200 ++++++--------- .../kotlin/kordenum/KordEnumGeneration.kt | 8 + 4 files changed, 312 insertions(+), 129 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt diff --git a/common/api/common.api b/common/api/common.api index fadcefae65b7..487fc7651245 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -6056,6 +6056,7 @@ public final class dev/kord/common/entity/GuildFeature$Community : dev/kord/comm } public final class dev/kord/common/entity/GuildFeature$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt new file mode 100644 index 000000000000..3819a2e8121e --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt @@ -0,0 +1,232 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Deprecated +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = GuildFeature.Serializer::class) +public sealed class GuildFeature( + public val `value`: String, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is GuildFeature && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + public final override fun toString(): String = "GuildFeature(value=$value)" + + /** + * An unknown [GuildFeature]. + * + * This is used as a fallback for [GuildFeature]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: String, + ) : GuildFeature(value) + + /** + * Guild has access to set an animated guild banner image. + */ + public object AnimatedBanner : GuildFeature("ANIMATED_BANNER") + + /** + * Guild has access to set an animated guild icon. + */ + public object AnimatedIcon : GuildFeature("ANIMATED_ICON") + + /** + * Guild has set up auto moderation rules. + */ + public object AutoModeration : GuildFeature("AUTO_MODERATION") + + /** + * Guild has access to set a guild banner image. + */ + public object Banner : GuildFeature("BANNER") + + /** + * Guild can enable welcome screen, Membership Screening, stage channels and discovery, and + * receives community updates. + */ + public object Community : GuildFeature("COMMUNITY") + + /** + * Guild is able to be discovered in the directory. + */ + public object Discoverable : GuildFeature("DISCOVERABLE") + + /** + * Guild is able to be featured in the directory. + */ + public object Featurable : GuildFeature("FEATURABLE") + + /** + * Guild has access to set an invite splash background. + */ + public object InviteSplash : GuildFeature("INVITE_SPLASH") + + /** + * Guild has enabled Membership Screening. + */ + public object MemberVerificationGateEnabled : GuildFeature("MEMBER_VERIFICATION_GATE_ENABLED") + + /** + * Guild has enabled monetization. + */ + public object MonetizationEnabled : GuildFeature("MONETIZATION_ENABLED") + + /** + * Guild has increased custom sticker slots. + */ + public object MoreStickers : GuildFeature("MORE_STICKERS") + + /** + * Guild has access to create announcement channels. + */ + public object News : GuildFeature("NEWS") + + /** + * Guild is partnered. + */ + public object Partnered : GuildFeature("PARTNERED") + + /** + * Guild can be previewed before joining via Membership Screening or the directory. + */ + public object PreviewEnabled : GuildFeature("PREVIEW_ENABLED") + + /** + * Guild has access to create private threads + */ + public object PrivateThreads : GuildFeature("PRIVATE_THREADS") + + /** + * Guild is able to set role icons. + */ + public object RoleIcons : GuildFeature("ROLE_ICONS") + + /** + * Guild has enabled ticketed events. + */ + public object TicketedEventsEnabled : GuildFeature("TICKETED_EVENTS_ENABLED") + + /** + * Guild has access to set a vanity URL. + */ + public object VanityUrl : GuildFeature("VANITY_URL") + + /** + * Guild is verified. + */ + public object Verified : GuildFeature("VERIFIED") + + /** + * Guild has access to set 384kbps bitrate in voice (previously VIP voice servers). + */ + public object VIPRegions : GuildFeature("VIP_REGIONS") + + /** + * Guild has enabled the welcome screen. + */ + public object WelcomeScreenEnabled : GuildFeature("WELCOME_SCREEN_ENABLED") + + /** + * Guild has access to the three-day archive time for threads + * + * @suppress. + */ + @Deprecated(message = "Thread archive durations are no longer boost locked.") + public object ThreeDayThreadArchive : GuildFeature("THREE_DAY_THREAD_ARCHIVE") + + /** + * Guild has access to the seven day archive time for threads. + * + * @suppress + */ + @Deprecated(message = "Thread archive durations are no longer boost locked.") + public object SevenDayThreadArchive : GuildFeature("SEVEN_DAY_THREAD_ARCHIVE") + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.GuildFeature", + PrimitiveKind.STRING) + + public override fun serialize(encoder: Encoder, `value`: GuildFeature) = + encoder.encodeString(value.value) + + public override fun deserialize(decoder: Decoder) = + when (val value = decoder.decodeString()) { + "ANIMATED_BANNER" -> AnimatedBanner + "ANIMATED_ICON" -> AnimatedIcon + "AUTO_MODERATION" -> AutoModeration + "BANNER" -> Banner + "COMMUNITY" -> Community + "DISCOVERABLE" -> Discoverable + "FEATURABLE" -> Featurable + "INVITE_SPLASH" -> InviteSplash + "MEMBER_VERIFICATION_GATE_ENABLED" -> MemberVerificationGateEnabled + "MONETIZATION_ENABLED" -> MonetizationEnabled + "MORE_STICKERS" -> MoreStickers + "NEWS" -> News + "PARTNERED" -> Partnered + "PREVIEW_ENABLED" -> PreviewEnabled + "PRIVATE_THREADS" -> PrivateThreads + "ROLE_ICONS" -> RoleIcons + "SEVEN_DAY_THREAD_ARCHIVE" -> @Suppress("DEPRECATION") SevenDayThreadArchive + "THREE_DAY_THREAD_ARCHIVE" -> @Suppress("DEPRECATION") ThreeDayThreadArchive + "TICKETED_EVENTS_ENABLED" -> TicketedEventsEnabled + "VANITY_URL" -> VanityUrl + "VERIFIED" -> Verified + "VIP_REGIONS" -> VIPRegions + "WELCOME_SCREEN_ENABLED" -> WelcomeScreenEnabled + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + AnimatedBanner, + AnimatedIcon, + AutoModeration, + Banner, + Community, + Discoverable, + Featurable, + InviteSplash, + MemberVerificationGateEnabled, + MonetizationEnabled, + MoreStickers, + News, + Partnered, + PreviewEnabled, + PrivateThreads, + RoleIcons, + @Suppress("DEPRECATION") SevenDayThreadArchive, + @Suppress("DEPRECATION") ThreeDayThreadArchive, + TicketedEventsEnabled, + VanityUrl, + Verified, + VIPRegions, + WelcomeScreenEnabled, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordGuild.kt b/common/src/main/kotlin/entity/DiscordGuild.kt index dc7b3e90ec4f..82e9d885fb86 100644 --- a/common/src/main/kotlin/entity/DiscordGuild.kt +++ b/common/src/main/kotlin/entity/DiscordGuild.kt @@ -1,3 +1,70 @@ +@file:GenerateKordEnum( + name = "GuildFeature", valueType = STRING, + entries = [ + Entry( + "AnimatedBanner", stringValue = "ANIMATED_BANNER", + kDoc = "Guild has access to set an animated guild banner image.", + ), + Entry("AnimatedIcon", stringValue = "ANIMATED_ICON", kDoc = "Guild has access to set an animated guild icon."), + Entry("AutoModeration", stringValue = "AUTO_MODERATION", kDoc = "Guild has set up auto moderation rules."), + Entry("Banner", stringValue = "BANNER", kDoc = "Guild has access to set a guild banner image."), + Entry( + "Community", stringValue = "COMMUNITY", + kDoc = "Guild can enable welcome screen, Membership Screening, stage channels and discovery, and " + + "receives community updates.", + ), + Entry("Discoverable", stringValue = "DISCOVERABLE", kDoc = "Guild is able to be discovered in the directory."), + Entry( + "Featurable", stringValue = "FEATURABLE", + kDoc = "Guild is able to be featured in the directory.", + ), + Entry( + "InviteSplash", stringValue = "INVITE_SPLASH", + kDoc = "Guild has access to set an invite splash background.", + ), + Entry( + "MemberVerificationGateEnabled", stringValue = "MEMBER_VERIFICATION_GATE_ENABLED", + kDoc = "Guild has enabled Membership Screening.", + ), + Entry("MonetizationEnabled", stringValue = "MONETIZATION_ENABLED", kDoc = "Guild has enabled monetization."), + Entry("MoreStickers", stringValue = "MORE_STICKERS", kDoc = "Guild has increased custom sticker slots."), + Entry("News", stringValue = "NEWS", kDoc = "Guild has access to create announcement channels."), + Entry("Partnered", stringValue = "PARTNERED", kDoc = "Guild is partnered."), + Entry( + "PreviewEnabled", stringValue = "PREVIEW_ENABLED", + kDoc = "Guild can be previewed before joining via Membership Screening or the directory.", + ), + Entry("PrivateThreads", stringValue = "PRIVATE_THREADS", kDoc = "Guild has access to create private threads"), + Entry("RoleIcons", stringValue = "ROLE_ICONS", kDoc = "Guild is able to set role icons."), + Entry( + "TicketedEventsEnabled", stringValue = "TICKETED_EVENTS_ENABLED", + kDoc = "Guild has enabled ticketed events.", + ), + Entry("VanityUrl", stringValue = "VANITY_URL", kDoc = "Guild has access to set a vanity URL."), + Entry("Verified", stringValue = "VERIFIED", kDoc = "Guild is verified."), + Entry( + "VIPRegions", stringValue = "VIP_REGIONS", + kDoc = "Guild has access to set 384kbps bitrate in voice (previously VIP voice servers).", + ), + Entry( + "WelcomeScreenEnabled", stringValue = "WELCOME_SCREEN_ENABLED", + kDoc = "Guild has enabled the welcome screen.", + ), + ], + deprecatedEntries = [ + Entry( + "ThreeDayThreadArchive", stringValue = "THREE_DAY_THREAD_ARCHIVE", + kDoc = "Guild has access to the three-day archive time for threads\n\n@suppress.", + deprecationMessage = "Thread archive durations are no longer boost locked.", deprecationLevel = WARNING, + ), + Entry( + "SevenDayThreadArchive", stringValue = "SEVEN_DAY_THREAD_ARCHIVE", + kDoc = "Guild has access to the seven day archive time for threads.\n\n@suppress", + deprecationMessage = "Thread archive durations are no longer boost locked.", deprecationLevel = WARNING, + ), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional @@ -5,6 +72,9 @@ import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.DurationInSeconds +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.STRING import kotlinx.datetime.Instant import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName @@ -14,6 +84,7 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlin.DeprecationLevel.WARNING /** * A partial representation of a [DiscordGuild] that may be [unavailable]. @@ -177,135 +248,6 @@ public data class DiscordPartialGuild( ) -/** - * A representation of a [Discord Guild Feature](https://discord.com/developers/docs/resources/guild#guild-object-guild-features). - */ -@Serializable(with = GuildFeature.Serializer::class) -public sealed class GuildFeature(public val value: String) { - - final override fun equals(other: Any?): Boolean = - this === other || (other is GuildFeature && this.value == other.value) - - final override fun hashCode(): Int = value.hashCode() - final override fun toString(): String = "GuildFeature(value=$value)" - - - /** An unknown [GuildFeature]. */ - public class Unknown(value: String) : GuildFeature(value) - - /** Guild has access to set an animated guild banner image. */ - public object AnimatedBanner : GuildFeature("ANIMATED_BANNER") - - /** Guild has set up auto moderation rules. */ - public object AutoModeration : GuildFeature("AUTO_MODERATION") - - /** Guild has access to set an invite splash background */ - public object InviteSplash : GuildFeature("INVITE_SPLASH") - - /** Guild has access to set 384kbps bitrate in voice (previously VIP voice servers) */ - public object VIPRegions : GuildFeature("VIP_REGIONS") - - /** Guild has access to set a vanity URL */ - public object VanityUrl : GuildFeature("VANITY_URL") - - /** Guild is verified */ - public object Verified : GuildFeature("VERIFIED") - - /** Guild is partnered */ - public object Partnered : GuildFeature("PARTNERED") - - /** Guild can enable welcome screen and discovery, and receives community updates */ - public object Community : GuildFeature("COMMUNITY") - - /** Guild has access to use commerce features (i.e. create store channels) */ - public object Commerce : GuildFeature("COMMERCE") - - /** Guild has access to create news channels */ - public object News : GuildFeature("NEWS") - - /** Guild is lurkable and able to be discovered directly */ - public object Discoverable : GuildFeature("DISCOVERABLE") - - /** Guild is able to be featured in the directory */ - public object Featurable : GuildFeature("FEATURABLE") - - /** Guild has access to set an animated guild icon */ - public object AnimatedIcon : GuildFeature("ANIMATED_ICON") - - /** Guild has access to set a guild banner image */ - public object Banner : GuildFeature("BANNER") - - /** Guild has enabled the welcome screen */ - public object WelcomeScreenEnabled : GuildFeature("WELCOME_SCREEN_ENABLED") - - /** Guild has enabled ticketed events */ - public object TicketedEventsEnabled : GuildFeature("TICKETED_EVENTS_ENABLED") - - /** Guild has enabled monetization */ - public object MonetizationEnabled : GuildFeature("MONETIZATION_ENABLED") - - /** Guild has increased custom sticker slots */ - public object MoreStickers : GuildFeature("MORE_STICKERS") - - /** Guild has access to the three-day archive time for threads */ - @Deprecated("Thread archive durations are no longer boost locked") - public object ThreeDayThreadArchive : GuildFeature("THREE_DAY_THREAD_ARCHIVE") - - /** Guild has access to the seven day archive time for threads */ - @Deprecated("Thread archive durations are no longer boost locked") - public object SevenDayThreadArchive : GuildFeature("SEVEN_DAY_THREAD_ARCHIVE") - - /** Guild has access to create private threads */ - public object PrivateThreads : GuildFeature("PRIVATE_THREADS") - - /** Guild has enabled Membership Screening */ - public object MemberVerificationGateEnabled : GuildFeature("MEMBER_VERIFICATION_GATE_ENABLED") - - /** Guild can be previewed before joining via Membership Screening or the directory */ - public object PreviewEnabled : GuildFeature("PREVIEW_ENABLED") - - /** Guild is able to set role icons */ - public object RoleIcons : GuildFeature("ROLE_ICONS") - - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("feature", PrimitiveKind.STRING) - - override fun deserialize(decoder: Decoder): GuildFeature = when (val value = decoder.decodeString()) { - "ANIMATED_BANNER" -> AnimatedBanner - "AUTO_MODERATION" -> AutoModeration - "INVITE_SPLASH" -> InviteSplash - "VIP_REGIONS" -> VIPRegions - "VANITY_URL" -> VanityUrl - "VERIFIED" -> Verified - "PARTNERED" -> Partnered - "COMMUNITY" -> Community - "COMMERCE" -> Commerce - "NEWS" -> News - "DISCOVERABLE" -> Discoverable - "FEATURABLE" -> Featurable - "ANIMATED_ICON" -> AnimatedIcon - "BANNER" -> Banner - "WELCOME_SCREEN_ENABLED" -> WelcomeScreenEnabled - "TICKETED_EVENTS_ENABLED" -> TicketedEventsEnabled - "MONETIZATION_ENABLED" -> MonetizationEnabled - "MORE_STICKERS" -> MoreStickers - "THREE_DAY_THREAD_ARCHIVE" -> @Suppress("DEPRECATION") ThreeDayThreadArchive - "SEVEN_DAY_THREAD_ARCHIVE" -> @Suppress("DEPRECATION") SevenDayThreadArchive - "PRIVATE_THREADS" -> PrivateThreads - "MEMBER_VERIFICATION_GATE_ENABLED" -> MemberVerificationGateEnabled - "PREVIEW_ENABLED" -> PreviewEnabled - "ROLE_ICONS" -> RoleIcons - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: GuildFeature) { - encoder.encodeString(value.value) - } - } -} - @Serializable(with = SystemChannelFlags.Companion::class) public data class SystemChannelFlags(val code: Int) { diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 7bedef43d095..c04441da004c 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -132,6 +132,14 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addStatement("return $valueName.hashCode()") } + // TODO for all value types + // final override fun toString + if (valueType == STRING) addFunction("toString"){ + addModifiers(FINAL, OVERRIDE) + returns() + addStatement("return \"%T($valueName=\$$valueName)\"", enumName) + } + // public class Unknown(: ) : () addClass("Unknown") { From df417ed17570c98b2a9faac011e8001a44f3af60 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 17:15:25 +0200 Subject: [PATCH 20/47] Generate `DefaultMessageNotificationLevel`, `ExplicitContentFilter`, `ExplicitContentFilter`, `VerificationLevel`, `NsfwLevel` and `PremiumTier` --- common/api/common.api | 18 ++ .../entity/DefaultMessageNotificationLevel.kt | 74 ++++++ .../common/entity/ExplicitContentFilter.kt | 80 ++++++ .../kotlin/dev/kord/common/entity/MFALevel.kt | 72 +++++ .../dev/kord/common/entity/NsfwLevel.kt | 74 ++++++ .../dev/kord/common/entity/PremiumTier.kt | 86 ++++++ .../kord/common/entity/VerificationLevel.kt | 94 +++++++ common/src/main/kotlin/entity/DiscordGuild.kt | 250 +++++------------- 8 files changed, 563 insertions(+), 185 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt diff --git a/common/api/common.api b/common/api/common.api index 487fc7651245..01a879fe45e6 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -1682,7 +1682,9 @@ public final class dev/kord/common/entity/ComponentType$Unknown : dev/kord/commo public abstract class dev/kord/common/entity/DefaultMessageNotificationLevel { public static final field Companion Ldev/kord/common/entity/DefaultMessageNotificationLevel$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/DefaultMessageNotificationLevel$AllMessages : dev/kord/common/entity/DefaultMessageNotificationLevel { @@ -1690,6 +1692,7 @@ public final class dev/kord/common/entity/DefaultMessageNotificationLevel$AllMes } public final class dev/kord/common/entity/DefaultMessageNotificationLevel$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -5999,7 +6002,9 @@ public final class dev/kord/common/entity/EmbedType$Video : dev/kord/common/enti public abstract class dev/kord/common/entity/ExplicitContentFilter { public static final field Companion Ldev/kord/common/entity/ExplicitContentFilter$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/ExplicitContentFilter$AllMembers : dev/kord/common/entity/ExplicitContentFilter { @@ -6007,6 +6012,7 @@ public final class dev/kord/common/entity/ExplicitContentFilter$AllMembers : dev } public final class dev/kord/common/entity/ExplicitContentFilter$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -6482,10 +6488,13 @@ public final class dev/kord/common/entity/InviteTargetType$Unknown : dev/kord/co public abstract class dev/kord/common/entity/MFALevel { public static final field Companion Ldev/kord/common/entity/MFALevel$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/MFALevel$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -6907,7 +6916,9 @@ public final class dev/kord/common/entity/NotSerializable : kotlinx/serializatio public abstract class dev/kord/common/entity/NsfwLevel { public static final field Companion Ldev/kord/common/entity/NsfwLevel$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/NsfwLevel$AgeRestricted : dev/kord/common/entity/NsfwLevel { @@ -6915,6 +6926,7 @@ public final class dev/kord/common/entity/NsfwLevel$AgeRestricted : dev/kord/com } public final class dev/kord/common/entity/NsfwLevel$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -7242,10 +7254,13 @@ public final class dev/kord/common/entity/Permissions$PermissionsBuilder { public abstract class dev/kord/common/entity/PremiumTier { public static final field Companion Ldev/kord/common/entity/PremiumTier$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/PremiumTier$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -7699,10 +7714,13 @@ public final class dev/kord/common/entity/UserPremium$Unknown : dev/kord/common/ public abstract class dev/kord/common/entity/VerificationLevel { public static final field Companion Ldev/kord/common/entity/VerificationLevel$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/VerificationLevel$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt new file mode 100644 index 000000000000..899aa5a572b7 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt @@ -0,0 +1,74 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = DefaultMessageNotificationLevel.Serializer::class) +public sealed class DefaultMessageNotificationLevel( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is DefaultMessageNotificationLevel && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [DefaultMessageNotificationLevel]. + * + * This is used as a fallback for [DefaultMessageNotificationLevel]s that haven't been added to + * Kord yet. + */ + public class Unknown( + `value`: Int, + ) : DefaultMessageNotificationLevel(value) + + /** + * Members will receive notifications for all messages by default. + */ + public object AllMessages : DefaultMessageNotificationLevel(0) + + /** + * Members will receive notifications only for messages that @mention them by default. + */ + public object OnlyMentions : DefaultMessageNotificationLevel(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.DefaultMessageNotificationLevel", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: DefaultMessageNotificationLevel) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> AllMessages + 1 -> OnlyMentions + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + AllMessages, + OnlyMentions, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt new file mode 100644 index 000000000000..441411ad51a7 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt @@ -0,0 +1,80 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = ExplicitContentFilter.Serializer::class) +public sealed class ExplicitContentFilter( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is ExplicitContentFilter && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [ExplicitContentFilter]. + * + * This is used as a fallback for [ExplicitContentFilter]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : ExplicitContentFilter(value) + + /** + * Media content will not be scanned. + */ + public object Disabled : ExplicitContentFilter(0) + + /** + * Media content sent by members without roles will be scanned. + */ + public object MembersWithoutRoles : ExplicitContentFilter(1) + + /** + * Media content sent by all members will be scanned. + */ + public object AllMembers : ExplicitContentFilter(2) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ExplicitContentFilter", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ExplicitContentFilter) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> Disabled + 1 -> MembersWithoutRoles + 2 -> AllMembers + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Disabled, + MembersWithoutRoles, + AllMembers, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt new file mode 100644 index 000000000000..269ff3a4b60d --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt @@ -0,0 +1,72 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = MFALevel.Serializer::class) +public sealed class MFALevel( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is MFALevel && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [MFALevel]. + * + * This is used as a fallback for [MFALevel]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : MFALevel(value) + + /** + * Guild has no MFA/2FA requirement for moderation actions. + */ + public object None : MFALevel(0) + + /** + * Guild has a 2FA requirement for moderation actions. + */ + public object Elevated : MFALevel(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.MFALevel", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: MFALevel) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> None + 1 -> Elevated + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + None, + Elevated, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt new file mode 100644 index 000000000000..5508bcc77d40 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt @@ -0,0 +1,74 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = NsfwLevel.Serializer::class) +public sealed class NsfwLevel( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is NsfwLevel && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [NsfwLevel]. + * + * This is used as a fallback for [NsfwLevel]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : NsfwLevel(value) + + public object Default : NsfwLevel(0) + + public object Explicit : NsfwLevel(1) + + public object Safe : NsfwLevel(2) + + public object AgeRestricted : NsfwLevel(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.NsfwLevel", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: NsfwLevel) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> Default + 1 -> Explicit + 2 -> Safe + 3 -> AgeRestricted + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Default, + Explicit, + Safe, + AgeRestricted, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt new file mode 100644 index 000000000000..9d12860d70d0 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt @@ -0,0 +1,86 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = PremiumTier.Serializer::class) +public sealed class PremiumTier( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is PremiumTier && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [PremiumTier]. + * + * This is used as a fallback for [PremiumTier]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : PremiumTier(value) + + /** + * Guild has not unlocked any Server Boost perks. + */ + public object None : PremiumTier(0) + + /** + * Guild has unlocked Server Boost level 1 perks. + */ + public object One : PremiumTier(1) + + /** + * Guild has unlocked Server Boost level 2 perks. + */ + public object Two : PremiumTier(2) + + /** + * Guild has unlocked Server Boost level 3 perks. + */ + public object Three : PremiumTier(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.PremiumTier", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: PremiumTier) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> None + 1 -> One + 2 -> Two + 3 -> Three + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + None, + One, + Two, + Three, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt new file mode 100644 index 000000000000..aeb7fd6c199c --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt @@ -0,0 +1,94 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = VerificationLevel.Serializer::class) +public sealed class VerificationLevel( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is VerificationLevel && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [VerificationLevel]. + * + * This is used as a fallback for [VerificationLevel]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : VerificationLevel(value) + + /** + * Unrestricted. + */ + public object None : VerificationLevel(0) + + /** + * Must have verified email on account. + */ + public object Low : VerificationLevel(1) + + /** + * Must be registered on Discord for longer than 5 minutes. + */ + public object Medium : VerificationLevel(2) + + /** + * Must be a member of the server for longer than 10 minutes. + */ + public object High : VerificationLevel(3) + + /** + * Must have a verified phone number. + */ + public object VeryHigh : VerificationLevel(4) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.VerificationLevel", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: VerificationLevel) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> None + 1 -> Low + 2 -> Medium + 3 -> High + 4 -> VeryHigh + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + None, + Low, + Medium, + High, + VeryHigh, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordGuild.kt b/common/src/main/kotlin/entity/DiscordGuild.kt index 82e9d885fb86..e4377ed4fe5e 100644 --- a/common/src/main/kotlin/entity/DiscordGuild.kt +++ b/common/src/main/kotlin/entity/DiscordGuild.kt @@ -1,3 +1,65 @@ +@file:GenerateKordEnum( + name = "DefaultMessageNotificationLevel", valueType = INT, + entries = [ + Entry("AllMessages", intValue = 0, kDoc = "Members will receive notifications for all messages by default."), + Entry( + "OnlyMentions", intValue = 1, + kDoc = "Members will receive notifications only for messages that @mention them by default.", + ), + ], +) + +@file:GenerateKordEnum( + name = "ExplicitContentFilter", valueType = INT, + entries = [ + Entry("Disabled", intValue = 0, kDoc = "Media content will not be scanned."), + Entry( + "MembersWithoutRoles", intValue = 1, + kDoc = "Media content sent by members without roles will be scanned.", + ), + Entry("AllMembers", intValue = 2, kDoc = "Media content sent by all members will be scanned."), + ], +) + +@file:GenerateKordEnum( + name = "MFALevel", valueType = INT, + entries = [ + Entry("None", intValue = 0, kDoc = "Guild has no MFA/2FA requirement for moderation actions."), + Entry("Elevated", intValue = 1, kDoc = "Guild has a 2FA requirement for moderation actions."), + ], +) + +@file:GenerateKordEnum( + name = "VerificationLevel", valueType = INT, + entries = [ + Entry("None", intValue = 0, kDoc = "Unrestricted."), + Entry("Low", intValue = 1, kDoc = "Must have verified email on account."), + Entry("Medium", intValue = 2, kDoc = "Must be registered on Discord for longer than 5 minutes."), + Entry("High", intValue = 3, kDoc = "Must be a member of the server for longer than 10 minutes."), + Entry("VeryHigh", intValue = 4, kDoc = "Must have a verified phone number."), + ], +) + +@file:GenerateKordEnum( + name = "NsfwLevel", valueType = INT, + entries = [ + Entry("Default", intValue = 0), + Entry("Explicit", intValue = 1), + Entry("Safe", intValue = 2), + Entry("AgeRestricted", intValue = 3), + ], +) + +@file:GenerateKordEnum( + name = "PremiumTier", valueType = INT, + entries = [ + Entry("None", intValue = 0, kDoc = "Guild has not unlocked any Server Boost perks."), + Entry("One", intValue = 1, kDoc = "Guild has unlocked Server Boost level 1 perks."), + Entry("Two", intValue = 2, kDoc = "Guild has unlocked Server Boost level 2 perks."), + Entry("Three", intValue = 3, kDoc = "Guild has unlocked Server Boost level 3 perks."), + ], +) + @file:GenerateKordEnum( name = "GuildFeature", valueType = STRING, entries = [ @@ -74,6 +136,7 @@ import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.DurationInSeconds import dev.kord.ksp.GenerateKordEnum import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import dev.kord.ksp.GenerateKordEnum.ValueType.STRING import kotlinx.datetime.Instant import kotlinx.serialization.KSerializer @@ -244,9 +307,8 @@ public data class DiscordPartialGuild( @SerialName("guild_scheduled_events") val guildScheduledEvents: Optional> = Optional.Missing(), @SerialName("premium_progress_bar_enabled") - val premiumProgressBarEnabled: OptionalBoolean = OptionalBoolean.Missing - - ) + val premiumProgressBarEnabled: OptionalBoolean = OptionalBoolean.Missing, +) @Serializable(with = SystemChannelFlags.Companion::class) public data class SystemChannelFlags(val code: Int) { @@ -374,188 +436,6 @@ public data class DiscordVoiceRegion( val custom: Boolean, ) -/** - * A representation of a [Discord Premium tier](https://discord.com/developers/docs/resources/guild#guild-object-premium-tier). - */ -@Serializable(with = PremiumTier.Serializer::class) -public sealed class PremiumTier(public val value: Int) { - public class Unknown(value: Int) : PremiumTier(value) - public object None : PremiumTier(0) - public object One : PremiumTier(1) - public object Two : PremiumTier(2) - public object Three : PremiumTier(3) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.PremiumTier", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): PremiumTier = when (val value = decoder.decodeInt()) { - 0 -> None - 1 -> One - 2 -> Two - 3 -> Three - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: PremiumTier) { - encoder.encodeInt(value.value) - } - - } -} - -@Serializable(with = DefaultMessageNotificationLevel.Serializer::class) -public sealed class DefaultMessageNotificationLevel(public val value: Int) { - public class Unknown(value: Int) : DefaultMessageNotificationLevel(value) - public object AllMessages : DefaultMessageNotificationLevel(0) - public object OnlyMentions : DefaultMessageNotificationLevel(1) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("default_message_notifications", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): DefaultMessageNotificationLevel = - when (val value = decoder.decodeInt()) { - 0 -> AllMessages - 1 -> OnlyMentions - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: DefaultMessageNotificationLevel) { - encoder.encodeInt(value.value) - } - } - -} - -@Serializable(with = ExplicitContentFilter.Serializer::class) -public sealed class ExplicitContentFilter(public val value: Int) { - public class Unknown(value: Int) : ExplicitContentFilter(value) - public object Disabled : ExplicitContentFilter(0) - public object MembersWithoutRoles : ExplicitContentFilter(1) - public object AllMembers : ExplicitContentFilter(2) - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("explicit_content_filter", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): ExplicitContentFilter = when (val value = decoder.decodeInt()) { - 0 -> Disabled - 1 -> MembersWithoutRoles - 2 -> AllMembers - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: ExplicitContentFilter) { - encoder.encodeInt(value.value) - } - - } -} - -@Serializable(with = MFALevel.Serializer::class) -public sealed class MFALevel(public val value: Int) { - public class Unknown(value: Int) : MFALevel(value) - public object None : MFALevel(0) - public object Elevated : MFALevel(1) - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.MFALevel", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): MFALevel = when (val value = decoder.decodeInt()) { - 0 -> None - 1 -> Elevated - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: MFALevel) { - encoder.encodeInt(value.value) - } - } -} - -/** - * A representation of a [Discord Guild NSFW Level](https://discord.com/developers/docs/resources/guild#guild-object-guild-nsfw-level). - */ -@Serializable(with = NsfwLevel.Serializer::class) -public sealed class NsfwLevel(public val value: Int) { - public class Unknown(value: Int) : NsfwLevel(value) - - public object Default : NsfwLevel(0) - - public object Explicit : NsfwLevel(1) - - public object Safe : NsfwLevel(2) - - public object AgeRestricted : NsfwLevel(3) - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.GuildNsfwLevel", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): NsfwLevel = when (val value = decoder.decodeInt()) { - 0 -> Default - 1 -> Explicit - 2 -> Safe - 3 -> AgeRestricted - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: NsfwLevel) { - encoder.encodeInt(value.value) - } - - } -} - - -/** - * A representation of a [Discord Verification Level](https://discord.com/developers/docs/resources/guild#guild-object-verification-level). - */ -@Serializable(with = VerificationLevel.Serializer::class) -public sealed class VerificationLevel(public val value: Int) { - public class Unknown(value: Int) : VerificationLevel(value) - - /** Unrestricted. */ - public object None : VerificationLevel(0) - - /** Must have verified email and account. */ - public object Low : VerificationLevel(1) - - /** Must be registered on Discord for longer than 5 minutes. */ - public object Medium : VerificationLevel(2) - - /** Must be member of the server for longer than 10 minutes */ - public object High : VerificationLevel(3) - - /** Must have a verified phone number */ - public object VeryHigh : VerificationLevel(4) - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.VerificationLevel", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): VerificationLevel = when (val value = decoder.decodeInt()) { - 0 -> None - 1 -> Low - 2 -> Medium - 3 -> High - 4 -> VeryHigh - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: VerificationLevel) { - encoder.encodeInt(value.value) - } - - } -} - @Serializable public data class DiscordWelcomeScreenChannel( @SerialName("channel_id") val channelId: Snowflake, From ffe5efd35f1f9d868491cbacc5fecece45886542 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 17:24:02 +0200 Subject: [PATCH 21/47] Generate `GuildScheduledEventPrivacyLevel`, `ScheduledEntityType` and `GuildScheduledEventStatus` --- common/api/common.api | 39 +++---- .../entity/GuildScheduledEventPrivacyLevel.kt | 67 +++++++++++ .../entity/GuildScheduledEventStatus.kt | 76 ++++++++++++ .../kord/common/entity/ScheduledEntityType.kt | 71 +++++++++++ .../entity/DiscordGuildScheduledEvent.kt | 110 +++++------------- 5 files changed, 260 insertions(+), 103 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt diff --git a/common/api/common.api b/common/api/common.api index 01a879fe45e6..a8d30607545c 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -6177,10 +6177,13 @@ public final class dev/kord/common/entity/GuildScheduledEventEntityMetadata$Comp public abstract class dev/kord/common/entity/GuildScheduledEventPrivacyLevel { public static final field Companion Ldev/kord/common/entity/GuildScheduledEventPrivacyLevel$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/GuildScheduledEventPrivacyLevel$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -6193,9 +6196,11 @@ public final class dev/kord/common/entity/GuildScheduledEventPrivacyLevel$Unknow } public abstract class dev/kord/common/entity/GuildScheduledEventStatus { - public static final field Serializer Ldev/kord/common/entity/GuildScheduledEventStatus$Serializer; + public static final field Companion Ldev/kord/common/entity/GuildScheduledEventStatus$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/GuildScheduledEventStatus$Active : dev/kord/common/entity/GuildScheduledEventStatus { @@ -6206,6 +6211,11 @@ public final class dev/kord/common/entity/GuildScheduledEventStatus$Cancelled : public static final field INSTANCE Ldev/kord/common/entity/GuildScheduledEventStatus$Cancelled; } +public final class dev/kord/common/entity/GuildScheduledEventStatus$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/GuildScheduledEventStatus$Completed : dev/kord/common/entity/GuildScheduledEventStatus { public static final field INSTANCE Ldev/kord/common/entity/GuildScheduledEventStatus$Completed; } @@ -6214,15 +6224,6 @@ public final class dev/kord/common/entity/GuildScheduledEventStatus$Scheduled : public static final field INSTANCE Ldev/kord/common/entity/GuildScheduledEventStatus$Scheduled; } -public final class dev/kord/common/entity/GuildScheduledEventStatus$Serializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/GuildScheduledEventStatus; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/GuildScheduledEventStatus;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - public final class dev/kord/common/entity/GuildScheduledEventStatus$Unknown : dev/kord/common/entity/GuildScheduledEventStatus { public fun (I)V } @@ -7400,22 +7401,20 @@ public final class dev/kord/common/entity/ResolvedObjects$Companion { } public abstract class dev/kord/common/entity/ScheduledEntityType { - public static final field Serializer Ldev/kord/common/entity/ScheduledEntityType$Serializer; + public static final field Companion Ldev/kord/common/entity/ScheduledEntityType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } -public final class dev/kord/common/entity/ScheduledEntityType$External : dev/kord/common/entity/ScheduledEntityType { - public static final field INSTANCE Ldev/kord/common/entity/ScheduledEntityType$External; +public final class dev/kord/common/entity/ScheduledEntityType$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public final class dev/kord/common/entity/ScheduledEntityType$Serializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/ScheduledEntityType; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/ScheduledEntityType;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; +public final class dev/kord/common/entity/ScheduledEntityType$External : dev/kord/common/entity/ScheduledEntityType { + public static final field INSTANCE Ldev/kord/common/entity/ScheduledEntityType$External; } public final class dev/kord/common/entity/ScheduledEntityType$StageInstance : dev/kord/common/entity/ScheduledEntityType { diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt new file mode 100644 index 000000000000..038ca277f906 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt @@ -0,0 +1,67 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = GuildScheduledEventPrivacyLevel.Serializer::class) +public sealed class GuildScheduledEventPrivacyLevel( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is GuildScheduledEventPrivacyLevel && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [GuildScheduledEventPrivacyLevel]. + * + * This is used as a fallback for [GuildScheduledEventPrivacyLevel]s that haven't been added to + * Kord yet. + */ + public class Unknown( + `value`: Int, + ) : GuildScheduledEventPrivacyLevel(value) + + /** + * The scheduled event is only accessible to guild members. + */ + public object GuildOnly : GuildScheduledEventPrivacyLevel(2) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.GuildScheduledEventPrivacyLevel", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: GuildScheduledEventPrivacyLevel) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 2 -> GuildOnly + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + GuildOnly, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt new file mode 100644 index 000000000000..ab832b856a7e --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt @@ -0,0 +1,76 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = GuildScheduledEventStatus.Serializer::class) +public sealed class GuildScheduledEventStatus( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is GuildScheduledEventStatus && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [GuildScheduledEventStatus]. + * + * This is used as a fallback for [GuildScheduledEventStatus]s that haven't been added to Kord + * yet. + */ + public class Unknown( + `value`: Int, + ) : GuildScheduledEventStatus(value) + + public object Scheduled : GuildScheduledEventStatus(1) + + public object Active : GuildScheduledEventStatus(2) + + public object Completed : GuildScheduledEventStatus(3) + + public object Cancelled : GuildScheduledEventStatus(4) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.GuildScheduledEventStatus", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: GuildScheduledEventStatus) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Scheduled + 2 -> Active + 3 -> Completed + 4 -> Cancelled + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Scheduled, + Active, + Completed, + Cancelled, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt new file mode 100644 index 000000000000..1da62057bc74 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt @@ -0,0 +1,71 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = ScheduledEntityType.Serializer::class) +public sealed class ScheduledEntityType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is ScheduledEntityType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [ScheduledEntityType]. + * + * This is used as a fallback for [ScheduledEntityType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : ScheduledEntityType(value) + + public object StageInstance : ScheduledEntityType(1) + + public object Voice : ScheduledEntityType(2) + + public object External : ScheduledEntityType(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ScheduledEntityType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ScheduledEntityType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> StageInstance + 2 -> Voice + 3 -> External + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + StageInstance, + Voice, + External, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt b/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt index c21a7457820d..4f7ba38e3677 100644 --- a/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt +++ b/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt @@ -1,17 +1,38 @@ +@file:GenerateKordEnum( + name = "GuildScheduledEventPrivacyLevel", valueType = INT, + entries = [Entry("GuildOnly", intValue = 2, kDoc = "The scheduled event is only accessible to guild members.")], +) + +@file:GenerateKordEnum( + name = "ScheduledEntityType", valueType = INT, + entries = [ + Entry("StageInstance", intValue = 1), + Entry("Voice", intValue = 2), + Entry("External", intValue = 3), + ], +) + +@file:GenerateKordEnum( + name = "GuildScheduledEventStatus", valueType = INT, + entries = [ + Entry("Scheduled", intValue = 1), + Entry("Active", intValue = 2), + Entry("Completed", intValue = 3), + Entry("Cancelled", intValue = 4), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.OptionalSnowflake +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.datetime.Instant -import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName 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 /** * Representation of a @@ -66,83 +87,6 @@ public data class DiscordGuildScheduledEvent( val image: Optional = Optional.Missing(), ) -/** Privacy level of a [DiscordGuildScheduledEvent]. */ -@Serializable(with = GuildScheduledEventPrivacyLevel.Serializer::class) -public sealed class GuildScheduledEventPrivacyLevel(public val value: Int) { - - /** The scheduled event is only accessible to guild members. */ - public object GuildOnly : GuildScheduledEventPrivacyLevel(2) - - /** An unknown privacy level. */ - public class Unknown(value: Int) : GuildScheduledEventPrivacyLevel(value) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("GuildScheduledEventPrivacyLevel", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): GuildScheduledEventPrivacyLevel { - return when (val value = decoder.decodeInt()) { - 2 -> GuildOnly - else -> Unknown(value) - } - } - - override fun serialize(encoder: Encoder, value: GuildScheduledEventPrivacyLevel) { - encoder.encodeInt(value.value) - } - } -} - -@Serializable(with = ScheduledEntityType.Serializer::class) -public sealed class ScheduledEntityType(public val value: Int) { - public object StageInstance : ScheduledEntityType(1) - public object Voice : ScheduledEntityType(2) - public object External : ScheduledEntityType(3) - public class Unknown(value: Int) : ScheduledEntityType(value) - - public companion object Serializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("ScheduledEntityType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): ScheduledEntityType { - return when (val value = decoder.decodeInt()) { - 1 -> StageInstance - 2 -> Voice - 3 -> External - else -> Unknown(value) - } - } - - override fun serialize(encoder: Encoder, value: ScheduledEntityType): Unit = encoder.encodeInt(value.value) - - } -} - -@Serializable(with = GuildScheduledEventStatus.Serializer::class) -public sealed class GuildScheduledEventStatus(public val value: Int) { - public object Scheduled : GuildScheduledEventStatus(1) - public object Active : GuildScheduledEventStatus(2) - public object Completed : GuildScheduledEventStatus(3) - public object Cancelled : GuildScheduledEventStatus(4) - public class Unknown(value: Int) : GuildScheduledEventStatus(value) - - public companion object Serializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("GuildScheduledEventStatus", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): GuildScheduledEventStatus { - return when (val value = decoder.decodeInt()) { - 1 -> Scheduled - 2 -> Active - 3 -> Completed - 4 -> Cancelled - else -> Unknown(value) - } - } - - override fun serialize(encoder: Encoder, value: GuildScheduledEventStatus): Unit = encoder.encodeInt(value.value) - - } -} - /** * Entity metadata for [DiscordGuildScheduledEvent]. * From 914f06fa054d4056fc50e674840d1b9360d8912e Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 17:29:44 +0200 Subject: [PATCH 22/47] Generate `IntegrationExpireBehavior` --- common/api/common.api | 18 +++-- .../entity/IntegrationExpireBehavior.kt | 68 +++++++++++++++++++ .../main/kotlin/entity/DiscordIntegration.kt | 40 +++-------- 3 files changed, 87 insertions(+), 39 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt diff --git a/common/api/common.api b/common/api/common.api index a8d30607545c..a6ed0a5eb137 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -6302,9 +6302,16 @@ public final class dev/kord/common/entity/IntegrationApplication$Companion { } public abstract class dev/kord/common/entity/IntegrationExpireBehavior { - public static final field Serializer Ldev/kord/common/entity/IntegrationExpireBehavior$Serializer; + public static final field Companion Ldev/kord/common/entity/IntegrationExpireBehavior$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I +} + +public final class dev/kord/common/entity/IntegrationExpireBehavior$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } public final class dev/kord/common/entity/IntegrationExpireBehavior$Kick : dev/kord/common/entity/IntegrationExpireBehavior { @@ -6315,15 +6322,6 @@ public final class dev/kord/common/entity/IntegrationExpireBehavior$RemoveRole : public static final field INSTANCE Ldev/kord/common/entity/IntegrationExpireBehavior$RemoveRole; } -public final class dev/kord/common/entity/IntegrationExpireBehavior$Serializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/IntegrationExpireBehavior; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/IntegrationExpireBehavior;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - public final class dev/kord/common/entity/IntegrationExpireBehavior$Unknown : dev/kord/common/entity/IntegrationExpireBehavior { public fun (I)V } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt new file mode 100644 index 000000000000..f19a01c57bbc --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt @@ -0,0 +1,68 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = IntegrationExpireBehavior.Serializer::class) +public sealed class IntegrationExpireBehavior( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is IntegrationExpireBehavior && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [IntegrationExpireBehavior]. + * + * This is used as a fallback for [IntegrationExpireBehavior]s that haven't been added to Kord + * yet. + */ + public class Unknown( + `value`: Int, + ) : IntegrationExpireBehavior(value) + + public object RemoveRole : IntegrationExpireBehavior(0) + + public object Kick : IntegrationExpireBehavior(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.IntegrationExpireBehavior", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: IntegrationExpireBehavior) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> RemoveRole + 1 -> Kick + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + RemoveRole, + Kick, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordIntegration.kt b/common/src/main/kotlin/entity/DiscordIntegration.kt index 68db354d8d51..48c3468cf6ba 100644 --- a/common/src/main/kotlin/entity/DiscordIntegration.kt +++ b/common/src/main/kotlin/entity/DiscordIntegration.kt @@ -1,17 +1,22 @@ +@file:GenerateKordEnum( + name = "IntegrationExpireBehavior", valueType = INT, + entries = [ + Entry("RemoveRole", intValue = 0), + Entry("Kick", intValue = 1), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.serialization.DurationInDays +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.datetime.Instant -import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName 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 import kotlin.DeprecationLevel.ERROR @Serializable @@ -58,29 +63,6 @@ public data class IntegrationApplication( val bot: Optional = Optional.Missing(), ) -@Serializable(with = IntegrationExpireBehavior.Serializer::class) -public sealed class IntegrationExpireBehavior(public val value: Int) { - public class Unknown(value: Int) : IntegrationExpireBehavior(value) - public object RemoveRole : IntegrationExpireBehavior(0) - public object Kick : IntegrationExpireBehavior(1) - - public companion object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("expire_behavior", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): IntegrationExpireBehavior = when (val value = decoder.decodeInt()) { - 0 -> RemoveRole - 1 -> Kick - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: IntegrationExpireBehavior) { - encoder.encodeInt(value.value) - } - - } -} - @Serializable public data class DiscordIntegrationsAccount( val id: String, From 10ffc50651c739b0c95a0c5bd3824f8682204a61 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 17:34:11 +0200 Subject: [PATCH 23/47] Generate `InviteTargetType` --- common/api/common.api | 3 + .../kord/common/entity/InviteTargetType.kt | 67 +++++++++++++++++++ .../src/main/kotlin/entity/DiscordInvite.kt | 38 +++-------- 3 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt diff --git a/common/api/common.api b/common/api/common.api index a6ed0a5eb137..4f9cd7fdbf01 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -6465,10 +6465,13 @@ public final class dev/kord/common/entity/InteractionsKt { public abstract class dev/kord/common/entity/InviteTargetType { public static final field Companion Ldev/kord/common/entity/InviteTargetType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/InviteTargetType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt new file mode 100644 index 000000000000..1eb3bccf9944 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt @@ -0,0 +1,67 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = InviteTargetType.Serializer::class) +public sealed class InviteTargetType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is InviteTargetType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [InviteTargetType]. + * + * This is used as a fallback for [InviteTargetType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : InviteTargetType(value) + + public object Stream : InviteTargetType(1) + + public object EmbeddedApplication : InviteTargetType(2) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.InviteTargetType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: InviteTargetType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Stream + 2 -> EmbeddedApplication + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Stream, + EmbeddedApplication, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordInvite.kt b/common/src/main/kotlin/entity/DiscordInvite.kt index 63d4fce675d4..800494ba6f3d 100644 --- a/common/src/main/kotlin/entity/DiscordInvite.kt +++ b/common/src/main/kotlin/entity/DiscordInvite.kt @@ -1,17 +1,22 @@ +@file:GenerateKordEnum( + name = "InviteTargetType", valueType = INT, + entries = [ + Entry("Stream", intValue = 1), + Entry("EmbeddedApplication", intValue = 2), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.serialization.DurationInSeconds +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.datetime.Instant -import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName 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 import kotlin.DeprecationLevel.ERROR public sealed interface BaseDiscordInvite { @@ -97,24 +102,3 @@ public data class DiscordPartialInvite( val code: String?, val uses: Int ) - -@Serializable(with = InviteTargetType.Serializer::class) -public sealed class InviteTargetType(public val value: Int) { - public class Unknown(value: Int) : InviteTargetType(value) - public object Stream : InviteTargetType(1) - public object EmbeddedApplication : InviteTargetType(2) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("InviteTargetType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): InviteTargetType = when (val value = decoder.decodeInt()) { - 1 -> Stream - 2 -> EmbeddedApplication - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: InviteTargetType) { - encoder.encodeInt(value.value) - } - } -} From 77d9ae28727d056fa35396ebb7b92a8e7dc16aed Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 17:42:11 +0200 Subject: [PATCH 24/47] Add missing `GuildFeature.Commerce` --- .../ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt | 7 +++++++ common/src/main/kotlin/entity/DiscordGuild.kt | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt index 3819a2e8121e..e72b1dd6a449 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt @@ -60,6 +60,11 @@ public sealed class GuildFeature( */ public object Banner : GuildFeature("BANNER") + /** + * Guild has access to use commerce features (i.e. create store channels). + */ + public object Commerce : GuildFeature("COMMERCE") + /** * Guild can enable welcome screen, Membership Screening, stage channels and discovery, and * receives community updates. @@ -176,6 +181,7 @@ public sealed class GuildFeature( "ANIMATED_ICON" -> AnimatedIcon "AUTO_MODERATION" -> AutoModeration "BANNER" -> Banner + "COMMERCE" -> Commerce "COMMUNITY" -> Community "DISCOVERABLE" -> Discoverable "FEATURABLE" -> Featurable @@ -206,6 +212,7 @@ public sealed class GuildFeature( AnimatedIcon, AutoModeration, Banner, + Commerce, Community, Discoverable, Featurable, diff --git a/common/src/main/kotlin/entity/DiscordGuild.kt b/common/src/main/kotlin/entity/DiscordGuild.kt index e4377ed4fe5e..53fadf83ecd2 100644 --- a/common/src/main/kotlin/entity/DiscordGuild.kt +++ b/common/src/main/kotlin/entity/DiscordGuild.kt @@ -70,6 +70,10 @@ Entry("AnimatedIcon", stringValue = "ANIMATED_ICON", kDoc = "Guild has access to set an animated guild icon."), Entry("AutoModeration", stringValue = "AUTO_MODERATION", kDoc = "Guild has set up auto moderation rules."), Entry("Banner", stringValue = "BANNER", kDoc = "Guild has access to set a guild banner image."), + Entry( + "Commerce", stringValue = "COMMERCE", + kDoc = "Guild has access to use commerce features (i.e. create store channels).", + ), Entry( "Community", stringValue = "COMMUNITY", kDoc = "Guild can enable welcome screen, Membership Screening, stage channels and discovery, and " + From c961a984c1f97e1db666f11bed53d8f7fd8aaaa2 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 18:00:47 +0200 Subject: [PATCH 25/47] Generate `MessageType` --- common/api/common.api | 1 + .../dev/kord/common/entity/MessageType.kt | 214 ++++++++++++++++++ .../src/main/kotlin/entity/DiscordMessage.kt | 165 +++++--------- 3 files changed, 275 insertions(+), 105 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt diff --git a/common/api/common.api b/common/api/common.api index 4f9cd7fdbf01..a1d15e7d21c2 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -6810,6 +6810,7 @@ public final class dev/kord/common/entity/MessageType$ChatInputCommand : dev/kor } public final class dev/kord/common/entity/MessageType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun getValues ()Ljava/util/Set; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt new file mode 100644 index 000000000000..894f251d36e8 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt @@ -0,0 +1,214 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Deprecated +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.Set +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 + +@Serializable(with = MessageType.Serializer::class) +public sealed class MessageType( + public val code: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is MessageType && this.code == other.code) + + public final override fun hashCode(): Int = code.hashCode() + + /** + * An unknown [MessageType]. + * + * This is used as a fallback for [MessageType]s that haven't been added to Kord yet. + */ + public class Unknown( + code: Int, + ) : MessageType(code) + + public object Default : MessageType(0) + + public object RecipientAdd : MessageType(1) + + public object RecipientRemove : MessageType(2) + + public object Call : MessageType(3) + + public object ChannelNameChange : MessageType(4) + + public object ChannelIconChange : MessageType(5) + + public object ChannelPinnedMessage : MessageType(6) + + public object UserJoin : MessageType(7) + + public object GuildBoost : MessageType(8) + + public object GuildBoostTier1 : MessageType(9) + + public object GuildBoostTier2 : MessageType(10) + + public object GuildBoostTier3 : MessageType(11) + + public object ChannelFollowAdd : MessageType(12) + + public object GuildDiscoveryDisqualified : MessageType(14) + + public object GuildDiscoveryRequalified : MessageType(15) + + public object GuildDiscoveryGracePeriodInitialWarning : MessageType(16) + + public object GuildDiscoveryGracePeriodFinalWarning : MessageType(17) + + public object ThreadCreated : MessageType(18) + + public object Reply : MessageType(19) + + public object ChatInputCommand : MessageType(20) + + public object ThreadStarterMessage : MessageType(21) + + public object GuildInviteReminder : MessageType(22) + + public object ContextMenuCommand : MessageType(23) + + public object AutoModerationAction : MessageType(24) + + /** + * @suppress + */ + @Deprecated( + message = "Renamed to 'UserJoin'.", + replaceWith = ReplaceWith(expression = "UserJoin", imports = + arrayOf("dev.kord.common.entity.MessageType.UserJoin")), + ) + public object GuildMemberJoin : MessageType(7) + + /** + * @suppress + */ + @Deprecated( + message = "Renamed to 'GuildBoost'.", + replaceWith = ReplaceWith(expression = "GuildBoost", imports = + arrayOf("dev.kord.common.entity.MessageType.GuildBoost")), + ) + public object UserPremiumGuildSubscription : MessageType(8) + + /** + * @suppress + */ + @Deprecated( + message = "Renamed to 'GuildBoostTier1'.", + replaceWith = ReplaceWith(expression = "GuildBoostTier1", imports = + arrayOf("dev.kord.common.entity.MessageType.GuildBoostTier1")), + ) + public object UserPremiumGuildSubscriptionTierOne : MessageType(9) + + /** + * @suppress + */ + @Deprecated( + message = "Renamed to 'GuildBoostTier2'.", + replaceWith = ReplaceWith(expression = "GuildBoostTier2", imports = + arrayOf("dev.kord.common.entity.MessageType.GuildBoostTier2")), + ) + public object UserPremiumGuildSubscriptionTwo : MessageType(10) + + /** + * @suppress + */ + @Deprecated( + message = "Renamed to 'GuildBoostTier3'.", + replaceWith = ReplaceWith(expression = "GuildBoostTier3", imports = + arrayOf("dev.kord.common.entity.MessageType.GuildBoostTier3")), + ) + public object UserPremiumGuildSubscriptionThree : MessageType(11) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.MessageType", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: MessageType) = + encoder.encodeInt(value.code) + + public override fun deserialize(decoder: Decoder) = when (val code = decoder.decodeInt()) { + 0 -> Default + 1 -> RecipientAdd + 2 -> RecipientRemove + 3 -> Call + 4 -> ChannelNameChange + 5 -> ChannelIconChange + 6 -> ChannelPinnedMessage + 7 -> UserJoin + 8 -> GuildBoost + 9 -> GuildBoostTier1 + 10 -> GuildBoostTier2 + 11 -> GuildBoostTier3 + 12 -> ChannelFollowAdd + 14 -> GuildDiscoveryDisqualified + 15 -> GuildDiscoveryRequalified + 16 -> GuildDiscoveryGracePeriodInitialWarning + 17 -> GuildDiscoveryGracePeriodFinalWarning + 18 -> ThreadCreated + 19 -> Reply + 20 -> ChatInputCommand + 21 -> ThreadStarterMessage + 22 -> GuildInviteReminder + 23 -> ContextMenuCommand + 24 -> AutoModerationAction + else -> Unknown(code) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Default, + RecipientAdd, + RecipientRemove, + Call, + ChannelNameChange, + ChannelIconChange, + ChannelPinnedMessage, + UserJoin, + GuildBoost, + GuildBoostTier1, + GuildBoostTier2, + GuildBoostTier3, + ChannelFollowAdd, + GuildDiscoveryDisqualified, + GuildDiscoveryRequalified, + GuildDiscoveryGracePeriodInitialWarning, + GuildDiscoveryGracePeriodFinalWarning, + ThreadCreated, + Reply, + ChatInputCommand, + ThreadStarterMessage, + GuildInviteReminder, + ContextMenuCommand, + AutoModerationAction, + ) + } + + + @Deprecated( + message = "Renamed to 'entries'.", + replaceWith = ReplaceWith(expression = "this.entries", imports = arrayOf()), + ) + public val values: Set + get() = entries.toSet() + } +} diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index f6fc765f35a2..ddfb1a8e1bbe 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -1,3 +1,62 @@ +@file:GenerateKordEnum( + name = "MessageType", valueType = INT, valueName = "code", + // had `public val values: Set` in companion before -> replace with `entries` + valuesPropertyName = "values", valuesPropertyType = SET, + entries = [ + Entry("Default", intValue = 0), + Entry("RecipientAdd", intValue = 1), + Entry("RecipientRemove", intValue = 2), + Entry("Call", intValue = 3), + Entry("ChannelNameChange", intValue = 4), + Entry("ChannelIconChange", intValue = 5), + Entry("ChannelPinnedMessage", intValue = 6), + Entry("UserJoin", intValue = 7), + Entry("GuildBoost", intValue = 8), + Entry("GuildBoostTier1", intValue = 9), + Entry("GuildBoostTier2", intValue = 10), + Entry("GuildBoostTier3", intValue = 11), + Entry("ChannelFollowAdd", intValue = 12), + Entry("GuildDiscoveryDisqualified", intValue = 14), + Entry("GuildDiscoveryRequalified", intValue = 15), + Entry("GuildDiscoveryGracePeriodInitialWarning", intValue = 16), + Entry("GuildDiscoveryGracePeriodFinalWarning", intValue = 17), + Entry("ThreadCreated", intValue = 18), + Entry("Reply", intValue = 19), + Entry("ChatInputCommand", intValue = 20), + Entry("ThreadStarterMessage", intValue = 21), + Entry("GuildInviteReminder", intValue = 22), + Entry("ContextMenuCommand", intValue = 23), + Entry("AutoModerationAction", intValue = 24), + ], + deprecatedEntries = [ + Entry( + "GuildMemberJoin", intValue = 7, kDoc = "@suppress", + deprecationMessage = "Renamed to 'UserJoin'.", deprecationLevel = WARNING, + replaceWith = ReplaceWith("UserJoin", "dev.kord.common.entity.MessageType.UserJoin"), + ), + Entry( + "UserPremiumGuildSubscription", intValue = 8, kDoc = "@suppress", + deprecationMessage = "Renamed to 'GuildBoost'.", deprecationLevel = WARNING, + replaceWith = ReplaceWith("GuildBoost", "dev.kord.common.entity.MessageType.GuildBoost"), + ), + Entry( + "UserPremiumGuildSubscriptionTierOne", intValue = 9, kDoc = "@suppress", + deprecationMessage = "Renamed to 'GuildBoostTier1'.", deprecationLevel = WARNING, + replaceWith = ReplaceWith("GuildBoostTier1", "dev.kord.common.entity.MessageType.GuildBoostTier1"), + ), + Entry( + "UserPremiumGuildSubscriptionTwo", intValue = 10, kDoc = "@suppress", + deprecationMessage = "Renamed to 'GuildBoostTier2'.", deprecationLevel = WARNING, + replaceWith = ReplaceWith("GuildBoostTier2", "dev.kord.common.entity.MessageType.GuildBoostTier2"), + ), + Entry( + "UserPremiumGuildSubscriptionThree", intValue = 11, kDoc = "@suppress", + deprecationMessage = "Renamed to 'GuildBoostTier3'.", deprecationLevel = WARNING, + replaceWith = ReplaceWith("GuildBoostTier3", "dev.kord.common.entity.MessageType.GuildBoostTier3"), + ), + ], +) + @file:GenerateKordEnum( name = "MessageStickerType", valueType = INT, // had `public val values: Set` in companion before -> replace with `entries` @@ -29,6 +88,7 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlin.DeprecationLevel.WARNING import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -757,111 +817,6 @@ public data class AllRemovedMessageReactions( val guildId: OptionalSnowflake = OptionalSnowflake.Missing, ) -@Serializable(with = MessageType.MessageTypeSerializer::class) -public sealed class MessageType(public val code: Int) { - - final override fun equals(other: Any?): Boolean = - this === other || (other is MessageType && this.code == other.code) - - final override fun hashCode(): Int = code - - - /** The default code for unknown values. */ - public class Unknown(code: Int) : MessageType(code) - public object Default : MessageType(0) - public object RecipientAdd : MessageType(1) - public object RecipientRemove : MessageType(2) - public object Call : MessageType(3) - public object ChannelNameChange : MessageType(4) - public object ChannelIconChange : MessageType(5) - public object ChannelPinnedMessage : MessageType(6) - - /** @suppress */ - @Deprecated("Renamed to 'UserJoin'.", ReplaceWith("UserJoin")) - public object GuildMemberJoin : MessageType(7) - public object UserJoin : MessageType(7) - - /** @suppress */ - @Deprecated("Renamed to 'GuildBoost'.", ReplaceWith("GuildBoost")) - public object UserPremiumGuildSubscription : MessageType(8) - public object GuildBoost : MessageType(8) - - /** @suppress */ - @Deprecated("Renamed to 'GuildBoostTier1'.", ReplaceWith("GuildBoostTier1")) - public object UserPremiumGuildSubscriptionTierOne : MessageType(9) - public object GuildBoostTier1 : MessageType(9) - - /** @suppress */ - @Deprecated("Renamed to 'GuildBoostTier2'.", ReplaceWith("GuildBoostTier2")) - public object UserPremiumGuildSubscriptionTwo : MessageType(10) - public object GuildBoostTier2 : MessageType(10) - - /** @suppress */ - @Deprecated("Renamed to 'GuildBoostTier3'.", ReplaceWith("GuildBoostTier3")) - public object UserPremiumGuildSubscriptionThree : MessageType(11) - public object GuildBoostTier3 : MessageType(11) - public object ChannelFollowAdd : MessageType(12) - public object GuildDiscoveryDisqualified : MessageType(14) - - @Suppress("SpellCheckingInspection") - public object GuildDiscoveryRequalified : MessageType(15) - public object GuildDiscoveryGracePeriodInitialWarning : MessageType(16) - public object GuildDiscoveryGracePeriodFinalWarning : MessageType(17) - public object ThreadCreated : MessageType(18) - public object Reply : MessageType(19) - public object ChatInputCommand : MessageType(20) - public object ThreadStarterMessage : MessageType(21) - public object GuildInviteReminder : MessageType(22) - public object ContextMenuCommand : MessageType(23) - public object AutoModerationAction : MessageType(24) - - - internal object MessageTypeSerializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("type", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): MessageType { - val code = decoder.decodeInt() - return values.firstOrNull { it.code == code } ?: Unknown(code) - } - - override fun serialize(encoder: Encoder, value: MessageType) { - encoder.encodeInt(value.code) - } - } - - public companion object { - public val values: Set - get() = setOf( - Default, - RecipientAdd, - RecipientRemove, - Call, - ChannelNameChange, - ChannelIconChange, - ChannelPinnedMessage, - UserJoin, - GuildBoost, - GuildBoostTier1, - GuildBoostTier2, - GuildBoostTier3, - ChannelFollowAdd, - GuildDiscoveryDisqualified, - GuildDiscoveryRequalified, - Reply, - GuildDiscoveryGracePeriodInitialWarning, - GuildDiscoveryGracePeriodFinalWarning, - ThreadCreated, - ChatInputCommand, - ThreadStarterMessage, - GuildInviteReminder, - ContextMenuCommand, - AutoModerationAction, - ) - } -} - @Serializable(with = AllowedMentionType.Serializer::class) public sealed class AllowedMentionType(public val value: String) { public class Unknown(value: String) : AllowedMentionType(value) From 2a01023ca6ae064cdef5c385c6176e74843faf11 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 18:12:53 +0200 Subject: [PATCH 26/47] Generate `MessageActivityType` and `AllowedMentionType` --- common/api/common.api | 7 ++ .../kord/common/entity/AllowedMentionType.kt | 84 +++++++++++++++++++ .../kord/common/entity/MessageActivityType.kt | 75 +++++++++++++++++ .../src/main/kotlin/entity/DiscordMessage.kt | 70 +++++----------- 4 files changed, 186 insertions(+), 50 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt diff --git a/common/api/common.api b/common/api/common.api index a1d15e7d21c2..889b782c81c4 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -263,10 +263,14 @@ public final class dev/kord/common/entity/AllRemovedMessageReactions$Companion { public abstract class dev/kord/common/entity/AllowedMentionType { public static final field Companion Ldev/kord/common/entity/AllowedMentionType$Companion; public synthetic fun (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()Ljava/lang/String; + public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/AllowedMentionType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -6548,10 +6552,13 @@ public final class dev/kord/common/entity/MessageActivity$Companion { public abstract class dev/kord/common/entity/MessageActivityType { public static final field Companion Ldev/kord/common/entity/MessageActivityType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/MessageActivityType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt new file mode 100644 index 000000000000..c7b28dcbd2c6 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt @@ -0,0 +1,84 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = AllowedMentionType.Serializer::class) +public sealed class AllowedMentionType( + public val `value`: String, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is AllowedMentionType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + public final override fun toString(): String = "AllowedMentionType(value=$value)" + + /** + * An unknown [AllowedMentionType]. + * + * This is used as a fallback for [AllowedMentionType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: String, + ) : AllowedMentionType(value) + + /** + * Controls role mentions. + */ + public object RoleMentions : AllowedMentionType("roles") + + /** + * Controls user mentions + */ + public object UserMentions : AllowedMentionType("users") + + /** + * Controls @everyone and @here mentions. + */ + public object EveryoneMentions : AllowedMentionType("everyone") + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.AllowedMentionType", + PrimitiveKind.STRING) + + public override fun serialize(encoder: Encoder, `value`: AllowedMentionType) = + encoder.encodeString(value.value) + + public override fun deserialize(decoder: Decoder) = + when (val value = decoder.decodeString()) { + "everyone" -> EveryoneMentions + "roles" -> RoleMentions + "users" -> UserMentions + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + EveryoneMentions, + RoleMentions, + UserMentions, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt new file mode 100644 index 000000000000..5afac456480d --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt @@ -0,0 +1,75 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = MessageActivityType.Serializer::class) +public sealed class MessageActivityType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is MessageActivityType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [MessageActivityType]. + * + * This is used as a fallback for [MessageActivityType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : MessageActivityType(value) + + public object Join : MessageActivityType(1) + + public object Spectate : MessageActivityType(2) + + public object Listen : MessageActivityType(3) + + public object JoinRequest : MessageActivityType(5) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.MessageActivityType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: MessageActivityType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Join + 2 -> Spectate + 3 -> Listen + 5 -> JoinRequest + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Join, + Spectate, + Listen, + JoinRequest, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index ddfb1a8e1bbe..82d5ac0a289e 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -57,6 +57,25 @@ ], ) +@file:GenerateKordEnum( + name = "MessageActivityType", valueType = INT, + entries = [ + Entry("Join", intValue = 1), + Entry("Spectate", intValue = 2), + Entry("Listen", intValue = 3), + Entry("JoinRequest", intValue = 5), + ], +) + +@file:GenerateKordEnum( + name = "AllowedMentionType", valueType = STRING, + entries = [ + Entry("RoleMentions", stringValue = "roles", kDoc = "Controls role mentions."), + Entry("UserMentions", stringValue = "users", kDoc = "Controls user mentions"), + Entry("EveryoneMentions", stringValue = "everyone", kDoc = "Controls @everyone and @here mentions."), + ], +) + @file:GenerateKordEnum( name = "MessageStickerType", valueType = INT, // had `public val values: Set` in companion before -> replace with `entries` @@ -78,6 +97,7 @@ import dev.kord.common.serialization.IntOrStringSerializer import dev.kord.ksp.GenerateKordEnum import dev.kord.ksp.GenerateKordEnum.Entry import dev.kord.ksp.GenerateKordEnum.ValueType.INT +import dev.kord.ksp.GenerateKordEnum.ValueType.STRING import dev.kord.ksp.GenerateKordEnum.ValuesPropertyType.SET import kotlinx.datetime.Instant import kotlinx.serialization.KSerializer @@ -726,32 +746,6 @@ public data class MessageActivity( val partyId: Optional = Optional.Missing(), ) -@Serializable(with = MessageActivityType.Serializer::class) -public sealed class MessageActivityType(public val value: Int) { - public class Unknown(value: Int) : MessageActivityType(value) - public object Join : MessageActivityType(1) - public object Spectate : MessageActivityType(2) - public object Listen : MessageActivityType(3) - public object JoinRequest : MessageActivityType(5) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.MessageActivivtyType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): MessageActivityType = when (val value = decoder.decodeInt()) { - 1 -> Join - 2 -> Spectate - 3 -> Listen - 5 -> JoinRequest - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: MessageActivityType) { - encoder.encodeInt(value.value) - } - } -} - @Serializable public data class MessageApplication( val id: Snowflake, @@ -817,30 +811,6 @@ public data class AllRemovedMessageReactions( val guildId: OptionalSnowflake = OptionalSnowflake.Missing, ) -@Serializable(with = AllowedMentionType.Serializer::class) -public sealed class AllowedMentionType(public val value: String) { - public class Unknown(value: String) : AllowedMentionType(value) - public object RoleMentions : AllowedMentionType("roles") - public object UserMentions : AllowedMentionType("users") - public object EveryoneMentions : AllowedMentionType("everyone") - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.DiscordAllowedMentionType", PrimitiveKind.STRING) - - override fun deserialize(decoder: Decoder): AllowedMentionType = when (val value = decoder.decodeString()) { - "roles" -> RoleMentions - "users" -> UserMentions - "everyone" -> EveryoneMentions - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: AllowedMentionType) { - encoder.encodeString(value.value) - } - } -} - @Serializable public data class AllowedMentions( val parse: List, From a5db3bde3a99c2ae1d194a48fda844130a11759a Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 18:21:23 +0200 Subject: [PATCH 27/47] Generate `StageInstancePrivacyLevel` --- common/api/common.api | 18 ++--- .../entity/StageInstancePrivacyLevel.kt | 76 +++++++++++++++++++ .../kotlin/entity/DiscordStageInstance.kt | 62 +++++---------- 3 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt diff --git a/common/api/common.api b/common/api/common.api index 889b782c81c4..92702056c32a 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -7477,9 +7477,16 @@ public final class dev/kord/common/entity/SnowflakeKt { } public abstract class dev/kord/common/entity/StageInstancePrivacyLevel { - public static final field Serializer Ldev/kord/common/entity/StageInstancePrivacyLevel$Serializer; + public static final field Companion Ldev/kord/common/entity/StageInstancePrivacyLevel$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I +} + +public final class dev/kord/common/entity/StageInstancePrivacyLevel$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } public final class dev/kord/common/entity/StageInstancePrivacyLevel$GuildOnly : dev/kord/common/entity/StageInstancePrivacyLevel { @@ -7490,15 +7497,6 @@ public final class dev/kord/common/entity/StageInstancePrivacyLevel$Public : dev public static final field INSTANCE Ldev/kord/common/entity/StageInstancePrivacyLevel$Public; } -public final class dev/kord/common/entity/StageInstancePrivacyLevel$Serializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/StageInstancePrivacyLevel; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/StageInstancePrivacyLevel;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - public final class dev/kord/common/entity/StageInstancePrivacyLevel$Unknown : dev/kord/common/entity/StageInstancePrivacyLevel { public fun (I)V } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt new file mode 100644 index 000000000000..00dea49f40b9 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt @@ -0,0 +1,76 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Deprecated +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = StageInstancePrivacyLevel.Serializer::class) +public sealed class StageInstancePrivacyLevel( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is StageInstancePrivacyLevel && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [StageInstancePrivacyLevel]. + * + * This is used as a fallback for [StageInstancePrivacyLevel]s that haven't been added to Kord + * yet. + */ + public class Unknown( + `value`: Int, + ) : StageInstancePrivacyLevel(value) + + /** + * The Stage instance is visible to only guild members. + */ + public object GuildOnly : StageInstancePrivacyLevel(2) + + /** + * The Stage instance is visible publicly. + */ + @Deprecated(message = "Stages are no longer discoverable") + public object Public : StageInstancePrivacyLevel(1) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.StageInstancePrivacyLevel", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: StageInstancePrivacyLevel) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> @Suppress("DEPRECATION") Public + 2 -> GuildOnly + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + @Suppress("DEPRECATION") Public, + GuildOnly, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordStageInstance.kt b/common/src/main/kotlin/entity/DiscordStageInstance.kt index 3c79d804770d..8f7caf7e6923 100644 --- a/common/src/main/kotlin/entity/DiscordStageInstance.kt +++ b/common/src/main/kotlin/entity/DiscordStageInstance.kt @@ -1,13 +1,24 @@ +@file:GenerateKordEnum( + name = "StageInstancePrivacyLevel", valueType = INT, + entries = [ + Entry("GuildOnly", intValue = 2, kDoc = "The Stage instance is visible to only guild members."), + ], + deprecatedEntries = [ + Entry( + "Public", intValue = 1, kDoc = "The Stage instance is visible publicly.", + deprecationMessage = "Stages are no longer discoverable", deprecationLevel = WARNING, + ), + ], +) + package dev.kord.common.entity -import kotlinx.serialization.KSerializer +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.SerialName 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 +import kotlin.DeprecationLevel.WARNING /** @@ -38,42 +49,3 @@ public data class DiscordStageInstance( @SerialName("guild_scheduled_event_id") val guildScheduledEventId: Snowflake?, ) - -/** - * Privacy level of a [DiscordStageInstance]. - */ -@Serializable(with = StageInstancePrivacyLevel.Serializer::class) -public sealed class StageInstancePrivacyLevel(public val value: Int) { - - /** - * The Stage instance is visible publicly, such as on Stage Discovery. - */ - @Deprecated("Stages are no longer discoverable") - public object Public : StageInstancePrivacyLevel(1) - - /** - * The Stage instance is visible to only guild members. - */ - public object GuildOnly : StageInstancePrivacyLevel(2) - - /** - * An unknown privacy level. - */ - public class Unknown(value: Int) : StageInstancePrivacyLevel(value) - - public companion object Serializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("StageInstancePrivacyLevel", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): StageInstancePrivacyLevel { - @Suppress("DEPRECATION") - return when (val value = decoder.decodeInt()) { - 1 -> Public - 2 -> GuildOnly - else -> Unknown(value) - } - } - - override fun serialize(encoder: Encoder, value: StageInstancePrivacyLevel): Unit = encoder.encodeInt(value.value) - - } -} From aa49f9ab3286110d2c15740bc691d7a66ee1a0aa Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 18:27:46 +0200 Subject: [PATCH 28/47] Generate `UserPremium` --- common/api/common.api | 3 + .../dev/kord/common/entity/UserPremium.kt | 73 +++++++++++++++++++ common/src/main/kotlin/entity/DiscordUser.kt | 42 ++++------- 3 files changed, 89 insertions(+), 29 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt diff --git a/common/api/common.api b/common/api/common.api index 92702056c32a..ef3056cf8e78 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -7694,10 +7694,13 @@ public final class dev/kord/common/entity/UserFlags$UserFlagsSerializer : kotlin public abstract class dev/kord/common/entity/UserPremium { public static final field Companion Ldev/kord/common/entity/UserPremium$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/UserPremium$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt new file mode 100644 index 000000000000..5ff43e1c44ea --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt @@ -0,0 +1,73 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +/** + * Premium types denote the level of premium a user has. + */ +@Serializable(with = UserPremium.Serializer::class) +public sealed class UserPremium( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is UserPremium && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [UserPremium]. + * + * This is used as a fallback for [UserPremium]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : UserPremium(value) + + public object None : UserPremium(0) + + public object NitroClassic : UserPremium(1) + + public object Nitro : UserPremium(2) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.UserPremium", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: UserPremium) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 0 -> None + 1 -> NitroClassic + 2 -> Nitro + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + None, + NitroClassic, + Nitro, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordUser.kt b/common/src/main/kotlin/entity/DiscordUser.kt index 70d0f747d32a..32bba6985f2a 100644 --- a/common/src/main/kotlin/entity/DiscordUser.kt +++ b/common/src/main/kotlin/entity/DiscordUser.kt @@ -1,7 +1,20 @@ +@file:GenerateKordEnum( + name = "UserPremium", valueType = INT, + kDoc = "Premium types denote the level of premium a user has.", + entries = [ + Entry("None", intValue = 0), + Entry("NitroClassic", intValue = 1), + Entry("Nitro", intValue = 2), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName @@ -178,32 +191,3 @@ public inline fun UserFlags(builder: UserFlags.UserFlagsBuilder.() -> Unit): Use contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } return UserFlags.UserFlagsBuilder().apply(builder).flags() } - -/** - * An instance of [Discord Premium Types](https://discord.com/developers/docs/resources/user#user-object-premium-types). - * - * Premium types denote the level of premium a user has. - */ -@Serializable(with = UserPremium.Serializer::class) -public sealed class UserPremium(public val value: Int) { - public class Unknown(value: Int) : UserPremium(value) - public object None : UserPremium(0) - public object NitroClassic : UserPremium(1) - public object Nitro : UserPremium(2) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("premium_type", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): UserPremium = when (val value = decoder.decodeInt()) { - 0 -> None - 1 -> NitroClassic - 2 -> Nitro - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: UserPremium) { - encoder.encodeInt(value.value) - } - } -} From 4a6e5d4e4b3d8155df410c37243072abd8707366 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 18:32:58 +0200 Subject: [PATCH 29/47] Generate `WebhookType` --- common/api/common.api | 7 ++ .../dev/kord/common/entity/WebhookType.kt | 80 +++++++++++++++++++ .../src/main/kotlin/entity/DiscordWebhook.kt | 55 +++++-------- 3 files changed, 106 insertions(+), 36 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt diff --git a/common/api/common.api b/common/api/common.api index ef3056cf8e78..07fa58728601 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -7785,7 +7785,13 @@ public final class dev/kord/common/entity/VideoQualityMode$Unknown : dev/kord/co public abstract class dev/kord/common/entity/WebhookType { public static final field Companion Ldev/kord/common/entity/WebhookType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I +} + +public final class dev/kord/common/entity/WebhookType$Application : dev/kord/common/entity/WebhookType { + public static final field INSTANCE Ldev/kord/common/entity/WebhookType$Application; } public final class dev/kord/common/entity/WebhookType$ChannelFollower : dev/kord/common/entity/WebhookType { @@ -7793,6 +7799,7 @@ public final class dev/kord/common/entity/WebhookType$ChannelFollower : dev/kord } public final class dev/kord/common/entity/WebhookType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt new file mode 100644 index 000000000000..0cf11b7200ab --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt @@ -0,0 +1,80 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = WebhookType.Serializer::class) +public sealed class WebhookType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is WebhookType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [WebhookType]. + * + * This is used as a fallback for [WebhookType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : WebhookType(value) + + /** + * Incoming Webhooks can post messages to channels with a generated token. + */ + public object Incoming : WebhookType(1) + + /** + * Channel Follower Webhooks are internal webhooks used with Channel Following to post new + * messages into channels. + */ + public object ChannelFollower : WebhookType(2) + + /** + * Application webhooks are webhooks used with Interactions. + */ + public object Application : WebhookType(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.WebhookType", PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: WebhookType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Incoming + 2 -> ChannelFollower + 3 -> Application + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Incoming, + ChannelFollower, + Application, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordWebhook.kt b/common/src/main/kotlin/entity/DiscordWebhook.kt index 30f60dd0f630..0291501ab00d 100644 --- a/common/src/main/kotlin/entity/DiscordWebhook.kt +++ b/common/src/main/kotlin/entity/DiscordWebhook.kt @@ -1,13 +1,27 @@ +@file:GenerateKordEnum( + name = "WebhookType", valueType = INT, + entries = [ + Entry( + "Incoming", intValue = 1, + kDoc = "Incoming Webhooks can post messages to channels with a generated token.", + ), + Entry( + "ChannelFollower", intValue = 2, + kDoc = "Channel Follower Webhooks are internal webhooks used with Channel Following to post new messages " + + "into channels.", + ), + Entry("Application", intValue = 3, kDoc = "Application webhooks are webhooks used with Interactions."), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalSnowflake +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.* -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 /** * A representation of the [Discord Webhook structure](https://discord.com/developers/docs/resources/webhook#webhook-object). @@ -37,34 +51,3 @@ public data class DiscordWebhook( @SerialName("application_id") val applicationId: Snowflake?, ) - -@Serializable(with = WebhookType.Serializer::class) -public sealed class WebhookType(public val value: Int) { - public class Unknown(value: Int) : WebhookType(value) - - /** - * Incoming Webhooks can post messages to channels with a generated token. - */ - public object Incoming : WebhookType(1) - - /** - * Channel Follower Webhooks are internal webhooks used with Channel Following to post new messages into channels. - */ - public object ChannelFollower : WebhookType(2) - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("type", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): WebhookType = when (val value = decoder.decodeInt()) { - 1 -> Incoming - 2 -> ChannelFollower - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: WebhookType) { - encoder.encodeInt(value.value) - } - } -} From 5c99c0cfbc35fc68aaecb6cf28950a716d08cd93 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 21:08:15 +0200 Subject: [PATCH 30/47] Generate `ApplicationCommandType`, `ApplicationCommandOptionType`, `InteractionType`, `InteractionResponseType` and `ApplicationCommandPermissionType` --- common/api/common.api | 89 +++--- .../entity/ApplicationCommandOptionType.kt | 115 ++++++++ .../ApplicationCommandPermissionType.kt | 72 +++++ .../common/entity/ApplicationCommandType.kt | 80 ++++++ .../common/entity/InteractionResponseType.kt | 110 ++++++++ .../dev/kord/common/entity/InteractionType.kt | 79 ++++++ common/src/main/kotlin/entity/Interactions.kt | 256 ++++++------------ core/api/core.api | 12 +- .../GuildApplicationCommandPermissionData.kt | 3 +- .../ApplicationGuildCommandPermissions.kt | 4 +- 10 files changed, 590 insertions(+), 230 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt diff --git a/common/api/common.api b/common/api/common.api index 07fa58728601..73e463f46a60 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -389,7 +389,9 @@ public final class dev/kord/common/entity/ApplicationCommandOption$Companion { public abstract class dev/kord/common/entity/ApplicationCommandOptionType { public static final field Companion Ldev/kord/common/entity/ApplicationCommandOptionType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getType ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/ApplicationCommandOptionType$Attachment : dev/kord/common/entity/ApplicationCommandOptionType { @@ -405,6 +407,7 @@ public final class dev/kord/common/entity/ApplicationCommandOptionType$Channel : } public final class dev/kord/common/entity/ApplicationCommandOptionType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -444,10 +447,41 @@ public final class dev/kord/common/entity/ApplicationCommandOptionType$User : de public static final field INSTANCE Ldev/kord/common/entity/ApplicationCommandOptionType$User; } +public abstract class dev/kord/common/entity/ApplicationCommandPermissionType { + public static final field Companion Ldev/kord/common/entity/ApplicationCommandPermissionType$Companion; + public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z + public final fun getValue ()I + public final fun hashCode ()I +} + +public final class dev/kord/common/entity/ApplicationCommandPermissionType$Channel : dev/kord/common/entity/ApplicationCommandPermissionType { + public static final field INSTANCE Ldev/kord/common/entity/ApplicationCommandPermissionType$Channel; +} + +public final class dev/kord/common/entity/ApplicationCommandPermissionType$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/ApplicationCommandPermissionType$Role : dev/kord/common/entity/ApplicationCommandPermissionType { + public static final field INSTANCE Ldev/kord/common/entity/ApplicationCommandPermissionType$Role; +} + +public final class dev/kord/common/entity/ApplicationCommandPermissionType$Unknown : dev/kord/common/entity/ApplicationCommandPermissionType { + public fun (I)V +} + +public final class dev/kord/common/entity/ApplicationCommandPermissionType$User : dev/kord/common/entity/ApplicationCommandPermissionType { + public static final field INSTANCE Ldev/kord/common/entity/ApplicationCommandPermissionType$User; +} + public abstract class dev/kord/common/entity/ApplicationCommandType { public static final field Companion Ldev/kord/common/entity/ApplicationCommandType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/ApplicationCommandType$ChatInput : dev/kord/common/entity/ApplicationCommandType { @@ -455,6 +489,7 @@ public final class dev/kord/common/entity/ApplicationCommandType$ChatInput : dev } public final class dev/kord/common/entity/ApplicationCommandType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -3373,17 +3408,17 @@ public final class dev/kord/common/entity/DiscordGuild$Companion { public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission { public static final field Companion Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Companion; - public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;ZLkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)V + public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;ZLkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)V public final fun component1 ()Ldev/kord/common/entity/Snowflake; - public final fun component2 ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; + public final fun component2 ()Ldev/kord/common/entity/ApplicationCommandPermissionType; public final fun component3 ()Z - public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; - public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;ZILjava/lang/Object;)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; + public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; + public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;ZILjava/lang/Object;)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; public fun equals (Ljava/lang/Object;)Z public final fun getId ()Ldev/kord/common/entity/Snowflake; public final fun getPermission ()Z - public final fun getType ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; + public final fun getType ()Ldev/kord/common/entity/ApplicationCommandPermissionType; public fun hashCode ()I public fun toString ()Ljava/lang/String; public static final fun write$Self (Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V @@ -3405,41 +3440,6 @@ public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermissi public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public abstract class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { - public static final field Companion Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Companion; - public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun getValue ()I -} - -public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Channel : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { - public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Channel; -} - -public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Companion { - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - -public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Role : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { - public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Role; -} - -public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Serializer : kotlinx/serialization/KSerializer { - public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Serializer; - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V -} - -public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Unknown : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { - public fun (I)V -} - -public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$User : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { - public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$User; -} - public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermissions { public static final field Companion Ldev/kord/common/entity/DiscordGuildApplicationCommandPermissions$Companion; public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V @@ -6385,7 +6385,9 @@ public final class dev/kord/common/entity/InteractionCallbackData$Companion { public abstract class dev/kord/common/entity/InteractionResponseType { public static final field Companion Ldev/kord/common/entity/InteractionResponseType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getType ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/InteractionResponseType$ApplicationCommandAutoCompleteResult : dev/kord/common/entity/InteractionResponseType { @@ -6397,6 +6399,7 @@ public final class dev/kord/common/entity/InteractionResponseType$ChannelMessage } public final class dev/kord/common/entity/InteractionResponseType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } @@ -6427,8 +6430,9 @@ public final class dev/kord/common/entity/InteractionResponseType$UpdateMessage public abstract class dev/kord/common/entity/InteractionType { public static final field Companion Ldev/kord/common/entity/InteractionType$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getType ()I - public fun toString ()Ljava/lang/String; + public final fun hashCode ()I } public final class dev/kord/common/entity/InteractionType$ApplicationCommand : dev/kord/common/entity/InteractionType { @@ -6440,6 +6444,7 @@ public final class dev/kord/common/entity/InteractionType$AutoComplete : dev/kor } public final class dev/kord/common/entity/InteractionType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt new file mode 100644 index 000000000000..8397e3491655 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt @@ -0,0 +1,115 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = ApplicationCommandOptionType.Serializer::class) +public sealed class ApplicationCommandOptionType( + public val type: Int, +) { + public final override fun equals(other: Any?): kotlin.Boolean = this === other || + (other is ApplicationCommandOptionType && this.type == other.type) + + public final override fun hashCode(): Int = type.hashCode() + + /** + * An unknown [ApplicationCommandOptionType]. + * + * This is used as a fallback for [ApplicationCommandOptionType]s that haven't been added to + * Kord yet. + */ + public class Unknown( + type: Int, + ) : ApplicationCommandOptionType(type) + + public object SubCommand : ApplicationCommandOptionType(1) + + public object SubCommandGroup : ApplicationCommandOptionType(2) + + public object String : ApplicationCommandOptionType(3) + + /** + * Any integer between `-2^53` and `2^53`. + */ + public object Integer : ApplicationCommandOptionType(4) + + public object Boolean : ApplicationCommandOptionType(5) + + public object User : ApplicationCommandOptionType(6) + + /** + * Includes all channel types + categories. + */ + public object Channel : ApplicationCommandOptionType(7) + + public object Role : ApplicationCommandOptionType(8) + + /** + * Includes users and roles. + */ + public object Mentionable : ApplicationCommandOptionType(9) + + /** + * Any double between `-2^53` and `2^53`. + */ + public object Number : ApplicationCommandOptionType(10) + + public object Attachment : ApplicationCommandOptionType(11) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ApplicationCommandOptionType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ApplicationCommandOptionType) = + encoder.encodeInt(value.type) + + public override fun deserialize(decoder: Decoder) = when (val type = decoder.decodeInt()) { + 1 -> SubCommand + 2 -> SubCommandGroup + 3 -> String + 4 -> Integer + 5 -> Boolean + 6 -> User + 7 -> Channel + 8 -> Role + 9 -> Mentionable + 10 -> Number + 11 -> Attachment + else -> Unknown(type) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + SubCommand, + SubCommandGroup, + String, + Integer, + Boolean, + User, + Channel, + Role, + Mentionable, + Number, + Attachment, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt new file mode 100644 index 000000000000..8d48a72e1e25 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt @@ -0,0 +1,72 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = ApplicationCommandPermissionType.Serializer::class) +public sealed class ApplicationCommandPermissionType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is ApplicationCommandPermissionType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [ApplicationCommandPermissionType]. + * + * This is used as a fallback for [ApplicationCommandPermissionType]s that haven't been added to + * Kord yet. + */ + public class Unknown( + `value`: Int, + ) : ApplicationCommandPermissionType(value) + + public object Role : ApplicationCommandPermissionType(1) + + public object User : ApplicationCommandPermissionType(2) + + public object Channel : ApplicationCommandPermissionType(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ApplicationCommandPermissionType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ApplicationCommandPermissionType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Role + 2 -> User + 3 -> Channel + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Role, + User, + Channel, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt new file mode 100644 index 000000000000..b2a3c2d14c24 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt @@ -0,0 +1,80 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = ApplicationCommandType.Serializer::class) +public sealed class ApplicationCommandType( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is ApplicationCommandType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [ApplicationCommandType]. + * + * This is used as a fallback for [ApplicationCommandType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : ApplicationCommandType(value) + + /** + * A text-based command that shows up when a user types `/`. + */ + public object ChatInput : ApplicationCommandType(1) + + /** + * A UI-based command that shows up when you right-click or tap on a user. + */ + public object User : ApplicationCommandType(2) + + /** + * A UI-based command that shows up when you right-click or tap on a message. + */ + public object Message : ApplicationCommandType(3) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.ApplicationCommandType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: ApplicationCommandType) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> ChatInput + 2 -> User + 3 -> Message + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + ChatInput, + User, + Message, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt new file mode 100644 index 000000000000..2b7316045054 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt @@ -0,0 +1,110 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = InteractionResponseType.Serializer::class) +public sealed class InteractionResponseType( + public val type: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is InteractionResponseType && this.type == other.type) + + public final override fun hashCode(): Int = type.hashCode() + + /** + * An unknown [InteractionResponseType]. + * + * This is used as a fallback for [InteractionResponseType]s that haven't been added to Kord + * yet. + */ + public class Unknown( + type: Int, + ) : InteractionResponseType(type) + + /** + * ACK a [Ping][dev.kord.common.entity.InteractionType.Ping] + */ + public object Pong : InteractionResponseType(1) + + /** + * Respond to an interaction with a message. + */ + public object ChannelMessageWithSource : InteractionResponseType(4) + + /** + * ACK an interaction and edit a response later, the user sees a loading state. + */ + public object DeferredChannelMessageWithSource : InteractionResponseType(5) + + /** + * For components, ACK an interaction and edit the original message later; the user does not see + * a loading state. + */ + public object DeferredUpdateMessage : InteractionResponseType(6) + + /** + * For components, edit the message the component was attached to. + */ + public object UpdateMessage : InteractionResponseType(7) + + /** + * Respond to an autocomplete interaction with suggested choices. + */ + public object ApplicationCommandAutoCompleteResult : InteractionResponseType(8) + + /** + * Respond to an interaction with a popup modal. + */ + public object Modal : InteractionResponseType(9) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.InteractionResponseType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: InteractionResponseType) = + encoder.encodeInt(value.type) + + public override fun deserialize(decoder: Decoder) = when (val type = decoder.decodeInt()) { + 1 -> Pong + 4 -> ChannelMessageWithSource + 5 -> DeferredChannelMessageWithSource + 6 -> DeferredUpdateMessage + 7 -> UpdateMessage + 8 -> ApplicationCommandAutoCompleteResult + 9 -> Modal + else -> Unknown(type) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Pong, + ChannelMessageWithSource, + DeferredChannelMessageWithSource, + DeferredUpdateMessage, + UpdateMessage, + ApplicationCommandAutoCompleteResult, + Modal, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt new file mode 100644 index 000000000000..a31c333c3622 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt @@ -0,0 +1,79 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = InteractionType.Serializer::class) +public sealed class InteractionType( + public val type: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is InteractionType && this.type == other.type) + + public final override fun hashCode(): Int = type.hashCode() + + /** + * An unknown [InteractionType]. + * + * This is used as a fallback for [InteractionType]s that haven't been added to Kord yet. + */ + public class Unknown( + type: Int, + ) : InteractionType(type) + + public object Ping : InteractionType(1) + + public object ApplicationCommand : InteractionType(2) + + public object Component : InteractionType(3) + + public object AutoComplete : InteractionType(4) + + public object ModalSubmit : InteractionType(5) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.InteractionType", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: InteractionType) = + encoder.encodeInt(value.type) + + public override fun deserialize(decoder: Decoder) = when (val type = decoder.decodeInt()) { + 1 -> Ping + 2 -> ApplicationCommand + 3 -> Component + 4 -> AutoComplete + 5 -> ModalSubmit + else -> Unknown(type) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Ping, + ApplicationCommand, + Component, + AutoComplete, + ModalSubmit, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/Interactions.kt b/common/src/main/kotlin/entity/Interactions.kt index 9da64f65094b..a09f6825a58d 100644 --- a/common/src/main/kotlin/entity/Interactions.kt +++ b/common/src/main/kotlin/entity/Interactions.kt @@ -1,8 +1,83 @@ +@file:GenerateKordEnum( + name = "ApplicationCommandType", valueType = INT, + entries = [ + Entry("ChatInput", intValue = 1, kDoc = "A text-based command that shows up when a user types `/`."), + Entry("User", intValue = 2, kDoc = "A UI-based command that shows up when you right-click or tap on a user."), + Entry( + "Message", intValue = 3, + kDoc = "A UI-based command that shows up when you right-click or tap on a message.", + ), + ], +) + +@file:GenerateKordEnum( + name = "ApplicationCommandOptionType", valueType = INT, valueName = "type", + entries = [ + Entry("SubCommand", intValue = 1), + Entry("SubCommandGroup", intValue = 2), + Entry("String", intValue = 3), + Entry("Integer", intValue = 4, kDoc = "Any integer between `-2^53` and `2^53`."), + Entry("Boolean", intValue = 5), + Entry("User", intValue = 6), + Entry("Channel", intValue = 7, kDoc = "Includes all channel types + categories."), + Entry("Role", intValue = 8), + Entry("Mentionable", intValue = 9, kDoc = "Includes users and roles."), + Entry("Number", intValue = 10, kDoc = "Any double between `-2^53` and `2^53`."), + Entry("Attachment", intValue = 11), + ], +) + +@file:GenerateKordEnum( + name = "InteractionType", valueType = INT, valueName = "type", + entries = [ + Entry("Ping", intValue = 1), + Entry("ApplicationCommand", intValue = 2), + Entry("Component", intValue = 3), + Entry("AutoComplete", intValue = 4), + Entry("ModalSubmit", intValue = 5), + ], +) + +@file:GenerateKordEnum( + name = "InteractionResponseType", valueType = INT, valueName = "type", + entries = [ + Entry("Pong", intValue = 1, kDoc = "ACK a [Ping][dev.kord.common.entity.InteractionType.Ping]"), + Entry("ChannelMessageWithSource", intValue = 4, kDoc = "Respond to an interaction with a message."), + Entry( + "DeferredChannelMessageWithSource", intValue = 5, + kDoc = "ACK an interaction and edit a response later, the user sees a loading state.", + ), + Entry( + "DeferredUpdateMessage", intValue = 6, + kDoc = "For components, ACK an interaction and edit the original message later; the user does not see a " + + "loading state.", + ), + Entry("UpdateMessage", intValue = 7, kDoc = "For components, edit the message the component was attached to."), + Entry( + "ApplicationCommandAutoCompleteResult", intValue = 8, + kDoc = "Respond to an autocomplete interaction with suggested choices.", + ), + Entry("Modal", intValue = 9, kDoc = "Respond to an interaction with a popup modal."), + ], +) + +@file:GenerateKordEnum( + name = "ApplicationCommandPermissionType", valueType = INT, + entries = [ + Entry("Role", intValue = 1), + Entry("User", intValue = 2), + Entry("Channel", intValue = 3), + ], +) + package dev.kord.common.entity import dev.kord.common.Locale import dev.kord.common.annotation.KordExperimental import dev.kord.common.entity.optional.* +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.MapSerializer @@ -40,30 +115,6 @@ public data class DiscordApplicationCommand( val version: Snowflake ) -@Serializable(with = ApplicationCommandType.Serializer::class) -public sealed class ApplicationCommandType(public val value: Int) { - /** The default code for unknown values. */ - public class Unknown(value: Int) : ApplicationCommandType(value) - public object ChatInput : ApplicationCommandType(1) - public object User : ApplicationCommandType(2) - public object Message : ApplicationCommandType(3) - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("type", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): ApplicationCommandType = when (val code = decoder.decodeInt()) { - 1 -> ChatInput - 2 -> User - 3 -> Message - else -> Unknown(code) - } - - override fun serialize(encoder: Encoder, value: ApplicationCommandType) = encoder.encodeInt(value.value) - } - -} - @Serializable public data class ApplicationCommandOption( val type: ApplicationCommandOptionType, @@ -105,52 +156,6 @@ public object NotSerializable : KSerializer { } -@Serializable(ApplicationCommandOptionType.Serializer::class) -public sealed class ApplicationCommandOptionType(public val type: Int) { - - public object SubCommand : ApplicationCommandOptionType(1) - public object SubCommandGroup : ApplicationCommandOptionType(2) - public object String : ApplicationCommandOptionType(3) - public object Integer : ApplicationCommandOptionType(4) - public object Boolean : ApplicationCommandOptionType(5) - public object User : ApplicationCommandOptionType(6) - public object Channel : ApplicationCommandOptionType(7) - public object Role : ApplicationCommandOptionType(8) - public object Mentionable : ApplicationCommandOptionType(9) - public object Number : ApplicationCommandOptionType(10) - public object Attachment : ApplicationCommandOptionType(11) - public class Unknown(type: Int) : ApplicationCommandOptionType(type) - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("ApplicationCommandOptionType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): ApplicationCommandOptionType { - return when (val type = decoder.decodeInt()) { - 1 -> SubCommand - 2 -> SubCommandGroup - 3 -> String - 4 -> Integer - 5 -> Boolean - 6 -> User - 7 -> Channel - 8 -> Role - 9 -> Mentionable - 10 -> Number - 11 -> Attachment - else -> Unknown(type) - } - } - - override fun serialize(encoder: Encoder, value: ApplicationCommandOptionType) { - encoder.encodeInt(value.type) - } - } - - -} - private val LocalizationSerializer = Optional.serializer(MapSerializer(Locale.serializer(), String.serializer()).nullable) @@ -292,54 +297,6 @@ public data class DiscordInteraction( } -@Serializable(InteractionType.Serializer::class) -public sealed class InteractionType(public val type: Int) { - public object Ping : InteractionType(1) - public object ApplicationCommand : InteractionType(2) - - /* - * don't trust the docs: - * - * this type exists and is needed for components even though it's not documented - */ - public object Component : InteractionType(3) - - public object AutoComplete : InteractionType(4) - public object ModalSubmit : InteractionType(5) - public class Unknown(type: Int) : InteractionType(type) - - override fun toString(): String = when (this) { - Ping -> "InteractionType.Ping($type)" - ApplicationCommand -> "InteractionType.ApplicationCommand($type)" - Component -> "InteractionType.ComponentInvoke($type)" - AutoComplete -> "InteractionType.AutoComplete($type)" - ModalSubmit -> "InteractionType.ModalSubmit($type)" - is Unknown -> "InteractionType.Unknown($type)" - } - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("InteractionType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): InteractionType { - return when (val type = decoder.decodeInt()) { - 1 -> Ping - 2 -> ApplicationCommand - 3 -> Component - 4 -> AutoComplete - 5 -> ModalSubmit - else -> Unknown(type) - } - } - - override fun serialize(encoder: Encoder, value: InteractionType) { - encoder.encodeInt(value.type) - } - - } -} - @Serializable public data class InteractionCallbackData( val id: OptionalSnowflake = OptionalSnowflake.Missing, @@ -738,42 +695,6 @@ public fun CommandArgument<*>.snowflake(): Snowflake { return Snowflake(id) } -@Serializable(InteractionResponseType.Serializer::class) - -public sealed class InteractionResponseType(public val type: Int) { - public object Pong : InteractionResponseType(1) - public object ChannelMessageWithSource : InteractionResponseType(4) - public object DeferredChannelMessageWithSource : InteractionResponseType(5) - public object DeferredUpdateMessage : InteractionResponseType(6) - public object UpdateMessage : InteractionResponseType(7) - public object ApplicationCommandAutoCompleteResult : InteractionResponseType(8) - public object Modal : InteractionResponseType(9) - public class Unknown(type: Int) : InteractionResponseType(type) - - internal object Serializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("InteractionResponseType", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): InteractionResponseType { - return when (val type = decoder.decodeInt()) { - 1 -> Pong - 4 -> ChannelMessageWithSource - 5 -> DeferredChannelMessageWithSource - 6 -> DeferredUpdateMessage - 7 -> UpdateMessage - 8 -> ApplicationCommandAutoCompleteResult - 9 -> Modal - else -> Unknown(type) - } - } - - override fun serialize(encoder: Encoder, value: InteractionResponseType) { - encoder.encodeInt(value.type) - } - } -} - @Serializable public data class DiscordGuildApplicationCommandPermissions( @@ -788,32 +709,9 @@ public data class DiscordGuildApplicationCommandPermissions( @Serializable public data class DiscordGuildApplicationCommandPermission( val id: Snowflake, - val type: Type, + val type: ApplicationCommandPermissionType, val permission: Boolean -) { - @Serializable(with = Type.Serializer::class) - public sealed class Type(public val value: Int) { - public object Role : Type(1) - public object User : Type(2) - public object Channel : Type(3) - public class Unknown(value: Int) : Type(value) - - public object Serializer : KSerializer { - override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("type", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): Type = - when (val value = decoder.decodeInt()) { - 1 -> Role - 2 -> User - 3 -> Channel - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: Type): Unit = encoder.encodeInt(value.value) - } - } -} +) @Serializable public data class DiscordAutoComplete( diff --git a/core/api/core.api b/core/api/core.api index eecc4838f367..e37e8965bbd7 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -3543,16 +3543,16 @@ public final class dev/kord/core/cache/data/EmojiDataKt { public final class dev/kord/core/cache/data/GuildApplicationCommandPermissionData { public static final field Companion Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData$Companion; - public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)V + public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)V public final fun component1 ()Ldev/kord/common/entity/Snowflake; - public final fun component2 ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; + public final fun component2 ()Ldev/kord/common/entity/ApplicationCommandPermissionType; public final fun component3 ()Z - public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; - public static synthetic fun copy$default (Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;ZILjava/lang/Object;)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; + public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; + public static synthetic fun copy$default (Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;ZILjava/lang/Object;)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; public fun equals (Ljava/lang/Object;)Z public final fun getId ()Ldev/kord/common/entity/Snowflake; public final fun getPermission ()Z - public final fun getType ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; + public final fun getType ()Ldev/kord/common/entity/ApplicationCommandPermissionType; public fun hashCode ()I public fun toString ()Ljava/lang/String; } @@ -7432,7 +7432,7 @@ public final class dev/kord/core/entity/application/GuildApplicationCommandPermi public final fun getData ()Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; public final fun getId ()Ldev/kord/common/entity/Snowflake; public final fun getPermission ()Z - public final fun getType ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; + public final fun getType ()Ldev/kord/common/entity/ApplicationCommandPermissionType; } public final class dev/kord/core/entity/application/GuildChatInputCommand : dev/kord/core/behavior/GuildChatInputCommandBehavior, dev/kord/core/entity/application/ChatInputCommandCommand, dev/kord/core/entity/application/GuildApplicationCommand { diff --git a/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt b/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt index dc2d7924eac6..47a0d9ed4688 100644 --- a/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt +++ b/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt @@ -1,12 +1,13 @@ package dev.kord.core.cache.data +import dev.kord.common.entity.ApplicationCommandPermissionType import dev.kord.common.entity.DiscordGuildApplicationCommandPermission import dev.kord.common.entity.Snowflake public data class GuildApplicationCommandPermissionData( val id: Snowflake, - val type: DiscordGuildApplicationCommandPermission.Type, + val type: ApplicationCommandPermissionType, val permission: Boolean ) { public companion object { diff --git a/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt b/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt index b43f2c54fbac..a7580794ffe9 100644 --- a/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt +++ b/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt @@ -1,6 +1,6 @@ package dev.kord.core.entity.application -import dev.kord.common.entity.DiscordGuildApplicationCommandPermission +import dev.kord.common.entity.ApplicationCommandPermissionType import dev.kord.common.entity.Snowflake import dev.kord.core.cache.data.GuildApplicationCommandPermissionData import dev.kord.core.cache.data.GuildApplicationCommandPermissionsData @@ -11,7 +11,7 @@ public class GuildApplicationCommandPermission(public val data: GuildApplication public val id: Snowflake get() = data.id - public val type: DiscordGuildApplicationCommandPermission.Type get() = data.type + public val type: ApplicationCommandPermissionType get() = data.type public val permission: Boolean get() = data.permission } From 525dc119469289e7ddf77ea31dfa52added9df4e Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 21:11:26 +0200 Subject: [PATCH 31/47] Fix test --- common/src/test/kotlin/json/InteractionTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/test/kotlin/json/InteractionTest.kt b/common/src/test/kotlin/json/InteractionTest.kt index 1072e0f157d8..f6894c4a0b4c 100644 --- a/common/src/test/kotlin/json/InteractionTest.kt +++ b/common/src/test/kotlin/json/InteractionTest.kt @@ -108,7 +108,7 @@ class InteractionTest { with(permissions.first()) { id shouldBe "827126703301066792" - type shouldBe DiscordGuildApplicationCommandPermission.Type.Role + type shouldBe ApplicationCommandPermissionType.Role permission shouldBe true } } From a21d5c5ba58f8d69482089f4763eb809b8722123 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Fri, 2 Sep 2022 21:47:55 +0200 Subject: [PATCH 32/47] Generate `PresenceStatus` and `TeamMembershipState` --- common/api/common.api | 37 ++++--- .../dev/kord/common/entity/PresenceStatus.kt | 98 +++++++++++++++++++ .../kord/common/entity/TeamMembershipState.kt | 67 +++++++++++++ common/src/main/kotlin/entity/Presence.kt | 42 +++----- common/src/main/kotlin/entity/Team.kt | 54 +++------- 5 files changed, 207 insertions(+), 91 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt diff --git a/common/api/common.api b/common/api/common.api index 73e463f46a60..5c6416ad3792 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -7300,9 +7300,17 @@ public final class dev/kord/common/entity/PremiumTier$Unknown : dev/kord/common/ } public abstract class dev/kord/common/entity/PresenceStatus { - public static final field StatusSerializer Ldev/kord/common/entity/PresenceStatus$StatusSerializer; + public static final field Companion Ldev/kord/common/entity/PresenceStatus$Companion; public synthetic fun (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()Ljava/lang/String; + public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; +} + +public final class dev/kord/common/entity/PresenceStatus$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } public final class dev/kord/common/entity/PresenceStatus$DoNotDisturb : dev/kord/common/entity/PresenceStatus { @@ -7325,15 +7333,6 @@ public final class dev/kord/common/entity/PresenceStatus$Online : dev/kord/commo public static final field INSTANCE Ldev/kord/common/entity/PresenceStatus$Online; } -public final class dev/kord/common/entity/PresenceStatus$StatusSerializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/PresenceStatus; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/PresenceStatus;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; -} - public final class dev/kord/common/entity/PresenceStatus$Unknown : dev/kord/common/entity/PresenceStatus { public fun (Ljava/lang/String;)V } @@ -7589,26 +7588,24 @@ public final class dev/kord/common/entity/TargetUserType$Unknown : dev/kord/comm } public abstract class dev/kord/common/entity/TeamMembershipState { - public static final field TeamMembershipStateSerializer Ldev/kord/common/entity/TeamMembershipState$TeamMembershipStateSerializer; + public static final field Companion Ldev/kord/common/entity/TeamMembershipState$Companion; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I + public final fun hashCode ()I } public final class dev/kord/common/entity/TeamMembershipState$Accepted : dev/kord/common/entity/TeamMembershipState { public static final field INSTANCE Ldev/kord/common/entity/TeamMembershipState$Accepted; } -public final class dev/kord/common/entity/TeamMembershipState$Invited : dev/kord/common/entity/TeamMembershipState { - public static final field INSTANCE Ldev/kord/common/entity/TeamMembershipState$Invited; +public final class dev/kord/common/entity/TeamMembershipState$Companion { + public final fun getEntries ()Ljava/util/List; + public final fun serializer ()Lkotlinx/serialization/KSerializer; } -public final class dev/kord/common/entity/TeamMembershipState$TeamMembershipStateSerializer : kotlinx/serialization/KSerializer { - public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/TeamMembershipState; - public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; - public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; - public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/TeamMembershipState;)V - public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V - public final fun serializer ()Lkotlinx/serialization/KSerializer; +public final class dev/kord/common/entity/TeamMembershipState$Invited : dev/kord/common/entity/TeamMembershipState { + public static final field INSTANCE Ldev/kord/common/entity/TeamMembershipState$Invited; } public final class dev/kord/common/entity/TeamMembershipState$Unknown : dev/kord/common/entity/TeamMembershipState { diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt new file mode 100644 index 000000000000..8a4bc3c83b10 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt @@ -0,0 +1,98 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = PresenceStatus.Serializer::class) +public sealed class PresenceStatus( + public val `value`: String, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is PresenceStatus && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + public final override fun toString(): String = "PresenceStatus(value=$value)" + + /** + * An unknown [PresenceStatus]. + * + * This is used as a fallback for [PresenceStatus]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: String, + ) : PresenceStatus(value) + + /** + * Online. + */ + public object Online : PresenceStatus("online") + + /** + * Do Not Disturb. + */ + public object DoNotDisturb : PresenceStatus("dnd") + + /** + * AFK. + */ + public object Idle : PresenceStatus("idle") + + /** + * Invisible and shown as offline. + */ + public object Invisible : PresenceStatus("invisible") + + /** + * Offline. + */ + public object Offline : PresenceStatus("offline") + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.PresenceStatus", + PrimitiveKind.STRING) + + public override fun serialize(encoder: Encoder, `value`: PresenceStatus) = + encoder.encodeString(value.value) + + public override fun deserialize(decoder: Decoder) = + when (val value = decoder.decodeString()) { + "dnd" -> DoNotDisturb + "idle" -> Idle + "invisible" -> Invisible + "offline" -> Offline + "online" -> Online + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + DoNotDisturb, + Idle, + Invisible, + Offline, + Online, + ) + } + + } +} diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt new file mode 100644 index 000000000000..26fc9c578014 --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt @@ -0,0 +1,67 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = TeamMembershipState.Serializer::class) +public sealed class TeamMembershipState( + public val `value`: Int, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is TeamMembershipState && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + /** + * An unknown [TeamMembershipState]. + * + * This is used as a fallback for [TeamMembershipState]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: Int, + ) : TeamMembershipState(value) + + public object Invited : TeamMembershipState(1) + + public object Accepted : TeamMembershipState(2) + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.TeamMembershipState", + PrimitiveKind.INT) + + public override fun serialize(encoder: Encoder, `value`: TeamMembershipState) = + encoder.encodeInt(value.value) + + public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { + 1 -> Invited + 2 -> Accepted + else -> Unknown(value) + } + } + + public companion object { + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Invited, + Accepted, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/Presence.kt b/common/src/main/kotlin/entity/Presence.kt index 3f7e51b246c5..8fc090a07a8c 100644 --- a/common/src/main/kotlin/entity/Presence.kt +++ b/common/src/main/kotlin/entity/Presence.kt @@ -1,7 +1,21 @@ +@file:GenerateKordEnum( + name = "PresenceStatus", valueType = STRING, + entries = [ + Entry("Online", stringValue = "online", kDoc = "Online."), + Entry("DoNotDisturb", stringValue = "dnd", kDoc = "Do Not Disturb."), + Entry("Idle", stringValue = "idle", kDoc = "AFK."), + Entry("Invisible", stringValue = "invisible", kDoc = "Invisible and shown as offline."), + Entry("Offline", stringValue = "offline", kDoc = "Offline."), + ], +) + package dev.kord.common.entity import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalSnowflake +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.STRING import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -66,31 +80,3 @@ public data class DiscordClientStatus( val mobile: Optional = Optional.Missing(), val web: Optional = Optional.Missing(), ) - -@Serializable(with = PresenceStatus.StatusSerializer::class) -public sealed class PresenceStatus(public val value: String) { - - public class Unknown(value: String) : PresenceStatus(value) - public object Online : PresenceStatus("online") - public object Idle : PresenceStatus("idle") - public object DoNotDisturb : PresenceStatus("dnd") - public object Offline : PresenceStatus("offline") - public object Invisible : PresenceStatus("invisible") - - public companion object StatusSerializer : KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Kord.ClientStatus", PrimitiveKind.STRING) - - override fun deserialize(decoder: Decoder): PresenceStatus = when (val value = decoder.decodeString()) { - "online" -> Online - "idle" -> Idle - "dnd" -> DoNotDisturb - "offline" -> Offline - "invisible" -> Invisible - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: PresenceStatus) { - encoder.encodeString(value.value) - } - } -} diff --git a/common/src/main/kotlin/entity/Team.kt b/common/src/main/kotlin/entity/Team.kt index 7656e2d838cb..7562417f5ae6 100644 --- a/common/src/main/kotlin/entity/Team.kt +++ b/common/src/main/kotlin/entity/Team.kt @@ -1,11 +1,17 @@ +@file:GenerateKordEnum( + name = "TeamMembershipState", valueType = INT, + entries = [ + Entry("Invited", intValue = 1), + Entry("Accepted", intValue = 2), + ], +) + package dev.kord.common.entity +import dev.kord.ksp.GenerateKordEnum +import dev.kord.ksp.GenerateKordEnum.Entry +import dev.kord.ksp.GenerateKordEnum.ValueType.INT import kotlinx.serialization.* -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 /** * The raw developer team data gotten from the API. @@ -19,44 +25,6 @@ public data class DiscordTeam( val ownerUserId: Snowflake, ) -/** - * The state of membership on a Discord developer team. - */ -@Serializable(with = TeamMembershipState.TeamMembershipStateSerializer::class) -public sealed class TeamMembershipState(public val value: Int) { - /** - * Unknown membership state. - */ - public class Unknown(value: Int) : TeamMembershipState(value) - - /** - * The user has been invited. - */ - public object Invited : TeamMembershipState(1) - - /** - * The user has accepted the invitation. - */ - public object Accepted : TeamMembershipState(2) - - - public companion object TeamMembershipStateSerializer : KSerializer { - - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("membership_state", PrimitiveKind.INT) - - override fun deserialize(decoder: Decoder): TeamMembershipState = when (val value = decoder.decodeInt()) { - 1 -> Invited - 2 -> Accepted - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: TeamMembershipState) { - encoder.encodeInt(value.value) - } - } -} - /** * The raw developer team member data gotten from the API. */ From a89afc2098bfadd83fa9bc42ccae7fb58392f3a5 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 4 Sep 2022 00:01:26 +0200 Subject: [PATCH 33/47] Update dokka config for ksp --- .../src/main/kotlin/kord-module.gradle.kts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 8d5c1bc7a373..ca9a5ff18bd0 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -60,30 +60,45 @@ tasks { useJUnitPlatform() } + val compileKotlin by existing + // configure both dokkaHtml and dokkaHtmlPartial tasks // (dokkaHtmlMultiModule depends on dokkaHtmlPartial, dokkaJar depends on dokkaHtml) withType { // see https://kotlin.github.io/dokka//user_guide/gradle/usage/#configuration-options + // make sure ksp generates files before building docs + dependsOn(compileKotlin) + failOnWarning.set(true) dokkaSourceSets.configureEach { jdkVersion.set(Jvm.targetInt) + val baseRemoteUrl = "https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.8.x")}/${project.name}" + sourceLink { localDirectory.set(file("src/main/kotlin")) - remoteUrl.set(URL("https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.8.x")}/${project.name}/src/main/kotlin/")) + remoteUrl.set(URL("$baseRemoteUrl/src/main/kotlin/")) remoteLineSuffix.set("#L") } + // config for files generated by ksp + val kspSrc = file("build/generated/ksp/main/kotlin") + if (kspSrc.exists()) { + suppressGeneratedFiles.set(false) + sourceLink { + localDirectory.set(kspSrc) + 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("https://api.ktor.io/") - // include docs for files generated by ksp - suppressGeneratedFiles.set(false) - // don't list `TweetNaclFast` in docs perPackageOption { matchingRegex.set("""com\.iwebpp\.crypto""") @@ -97,7 +112,7 @@ tasks { from(sourceSets.main.get().allSource) } - val dokkaHtml by getting + val dokkaHtml by existing val dokkaJar by registering(Jar::class) { group = JavaBasePlugin.DOCUMENTATION_GROUP From 68612ccab62ddc548b911cf2c3b55eaa6ee48d96 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 15:48:10 +0200 Subject: [PATCH 34/47] Gradle config formatting --- buildSrc/src/main/kotlin/kord-module.gradle.kts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index ca9a5ff18bd0..489309347f03 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -25,14 +25,12 @@ dependencies { kotlin { explicitApi() - sourceSets.main { + sourceSets { // mark ksp src dir - kotlin.srcDir("build/generated/ksp/main/kotlin") - } + main { kotlin.srcDir("build/generated/ksp/main/kotlin") } - sourceSets.test { - // allow ExperimentalCoroutinesApi for `runTest {}` - languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") + // allow `ExperimentalCoroutinesApi` for `runTest {}` + test { languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") } } } From e360522d186a43131f9d610b2b0f289e3c4e634f Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 17:13:39 +0200 Subject: [PATCH 35/47] Binary compatibility for `DiscordGuildApplicationCommandPermission.Type` --- common/api/common.api | 40 ++++++ common/src/main/kotlin/entity/Interactions.kt | 133 +++++++++++++++++- core/api/core.api | 6 + .../GuildApplicationCommandPermissionData.kt | 53 +++++++ .../ApplicationGuildCommandPermissions.kt | 13 ++ 5 files changed, 244 insertions(+), 1 deletion(-) diff --git a/common/api/common.api b/common/api/common.api index 5c6416ad3792..ef7912ec54f3 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -3410,15 +3410,20 @@ public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermissi public static final field Companion Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Companion; public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;ZLkotlinx/serialization/internal/SerializationConstructorMarker;)V public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)V + public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)V public final fun component1 ()Ldev/kord/common/entity/Snowflake; public final fun component2 ()Ldev/kord/common/entity/ApplicationCommandPermissionType; + public final synthetic fun component2 ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; public final fun component3 ()Z public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; + public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;ZILjava/lang/Object;)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; + public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;ZILjava/lang/Object;)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission; public fun equals (Ljava/lang/Object;)Z public final fun getId ()Ldev/kord/common/entity/Snowflake; public final fun getPermission ()Z public final fun getType ()Ldev/kord/common/entity/ApplicationCommandPermissionType; + public final synthetic fun getType ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; public fun hashCode ()I public fun toString ()Ljava/lang/String; public static final fun write$Self (Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V @@ -3440,6 +3445,41 @@ public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermissi public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public abstract class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { + public static final field Companion Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Companion; + public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getValue ()I +} + +public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Channel : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { + public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Channel; +} + +public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Role : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { + public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Role; +} + +public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Serializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Serializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V +} + +public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$Unknown : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { + public fun (I)V +} + +public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$User : dev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type { + public static final field INSTANCE Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type$User; +} + public final class dev/kord/common/entity/DiscordGuildApplicationCommandPermissions { public static final field Companion Ldev/kord/common/entity/DiscordGuildApplicationCommandPermissions$Companion; public synthetic fun (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V diff --git a/common/src/main/kotlin/entity/Interactions.kt b/common/src/main/kotlin/entity/Interactions.kt index a09f6825a58d..ee45e8cc5c59 100644 --- a/common/src/main/kotlin/entity/Interactions.kt +++ b/common/src/main/kotlin/entity/Interactions.kt @@ -86,6 +86,8 @@ import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.* import kotlinx.serialization.json.* +import kotlin.DeprecationLevel.ERROR +import kotlin.DeprecationLevel.HIDDEN @Serializable public data class DiscordApplicationCommand( @@ -711,7 +713,136 @@ public data class DiscordGuildApplicationCommandPermission( val id: Snowflake, val type: ApplicationCommandPermissionType, val permission: Boolean -) +) { + + @Suppress("DEPRECATION_ERROR") + @Deprecated( + "'DiscordGuildApplicationCommandPermission.Type' is replaced by 'ApplicationCommandPermissionType'", + level = ERROR, + ) + public constructor(id: Snowflake, type: Type, permission: Boolean) : this(id, type.toNewType(), permission) + + @Suppress("DEPRECATION_ERROR") + @Deprecated("Binary compatibility", level = HIDDEN) + @get:JvmName("getType") + public val type0: Type get() = type.toDeprecatedType() + + @Suppress("DEPRECATION_ERROR", "FunctionName") + @Deprecated("Binary compatibility", level = HIDDEN) + @JvmName("component2") + public fun _component2(): Type = type.toDeprecatedType() + + @Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") + @Deprecated( + "'DiscordGuildApplicationCommandPermission.Type' is replaced by 'ApplicationCommandPermissionType'", + level = ERROR, + ) + public fun copy( + id: Snowflake = this.id, + type: Type = this.type.toDeprecatedType(), + permission: Boolean = this.permission, + ): DiscordGuildApplicationCommandPermission = DiscordGuildApplicationCommandPermission(id, type, permission) + + @Suppress("DEPRECATION_ERROR") + @Deprecated( + "Replaced by 'ApplicationCommandPermissionType'", + ReplaceWith("ApplicationCommandPermissionType", "dev.kord.common.entity.ApplicationCommandPermissionType"), + level = ERROR, + ) + @Serializable(with = Type.Serializer::class) + public sealed class Type(public val value: Int) { + @Deprecated( + "Replaced by 'ApplicationCommandPermissionType.Role'", + ReplaceWith( + "ApplicationCommandPermissionType.Role", + "dev.kord.common.entity.ApplicationCommandPermissionType", + ), + level = ERROR, + ) + public object Role : Type(1) + + @Deprecated( + "Replaced by 'ApplicationCommandPermissionType.User'", + ReplaceWith( + "ApplicationCommandPermissionType.User", + "dev.kord.common.entity.ApplicationCommandPermissionType", + ), + level = ERROR, + ) + public object User : Type(2) + + @Deprecated( + "Replaced by 'ApplicationCommandPermissionType.Channel'", + ReplaceWith( + "ApplicationCommandPermissionType.Channel", + "dev.kord.common.entity.ApplicationCommandPermissionType", + ), + level = ERROR, + ) + public object Channel : Type(3) + + @Deprecated( + "Replaced by 'ApplicationCommandPermissionType.Unknown'", + ReplaceWith( + "ApplicationCommandPermissionType.Unknown", + "dev.kord.common.entity.ApplicationCommandPermissionType", + ), + level = ERROR, + ) + public class Unknown + @Deprecated( + "Replaced by 'ApplicationCommandPermissionType.Unknown'", + ReplaceWith( + "ApplicationCommandPermissionType.Unknown(value)", + "dev.kord.common.entity.ApplicationCommandPermissionType", + ), + level = ERROR, + ) public constructor(value: Int) : Type(value) + + @Deprecated( + "Replaced by 'ApplicationCommandPermissionType.serializer()'", + ReplaceWith( + "ApplicationCommandPermissionType.serializer()", + "dev.kord.common.entity.ApplicationCommandPermissionType", + ), + level = ERROR, + ) + public object Serializer : KSerializer { + override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("type", PrimitiveKind.INT) + + override fun deserialize(decoder: Decoder): Type = + when (val value = decoder.decodeInt()) { + 1 -> Role + 2 -> User + 3 -> Channel + else -> Unknown(value) + } + + override fun serialize(encoder: Encoder, value: Type): Unit = encoder.encodeInt(value.value) + } + } + + // functions for migration purposes, remove when bumping deprecations + // (public companion object can be removed, it's generated by kxser) + public companion object { + @Suppress("DEPRECATION_ERROR") + private fun ApplicationCommandPermissionType.toDeprecatedType() = when (this) { + ApplicationCommandPermissionType.Role -> Type.Role + ApplicationCommandPermissionType.User -> Type.User + ApplicationCommandPermissionType.Channel -> Type.Channel + is ApplicationCommandPermissionType.Unknown -> Type.Unknown(value) + } + + @Suppress("DEPRECATION_ERROR") + private fun Type.toNewType() = when (this) { + Type.Role -> ApplicationCommandPermissionType.Role + Type.User -> ApplicationCommandPermissionType.User + Type.Channel -> ApplicationCommandPermissionType.Channel + is Type.Unknown -> ApplicationCommandPermissionType.Unknown(value) + } + } +} @Serializable public data class DiscordAutoComplete( diff --git a/core/api/core.api b/core/api/core.api index e37e8965bbd7..ff6ce8f17d32 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -3544,15 +3544,20 @@ public final class dev/kord/core/cache/data/EmojiDataKt { public final class dev/kord/core/cache/data/GuildApplicationCommandPermissionData { public static final field Companion Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData$Companion; public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)V + public fun (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)V public final fun component1 ()Ldev/kord/common/entity/Snowflake; public final fun component2 ()Ldev/kord/common/entity/ApplicationCommandPermissionType; + public final synthetic fun component2 ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; public final fun component3 ()Z public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;Z)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; + public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;Z)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; public static synthetic fun copy$default (Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/ApplicationCommandPermissionType;ZILjava/lang/Object;)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; + public static synthetic fun copy$default (Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type;ZILjava/lang/Object;)Ldev/kord/core/cache/data/GuildApplicationCommandPermissionData; public fun equals (Ljava/lang/Object;)Z public final fun getId ()Ldev/kord/common/entity/Snowflake; public final fun getPermission ()Z public final fun getType ()Ldev/kord/common/entity/ApplicationCommandPermissionType; + public final synthetic fun getType ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; public fun hashCode ()I public fun toString ()Ljava/lang/String; } @@ -7433,6 +7438,7 @@ public final class dev/kord/core/entity/application/GuildApplicationCommandPermi public final fun getId ()Ldev/kord/common/entity/Snowflake; public final fun getPermission ()Z public final fun getType ()Ldev/kord/common/entity/ApplicationCommandPermissionType; + public final synthetic fun getType ()Ldev/kord/common/entity/DiscordGuildApplicationCommandPermission$Type; } public final class dev/kord/core/entity/application/GuildChatInputCommand : dev/kord/core/behavior/GuildChatInputCommandBehavior, dev/kord/core/entity/application/ChatInputCommandCommand, dev/kord/core/entity/application/GuildApplicationCommand { diff --git a/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt b/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt index 47a0d9ed4688..c2e93fbc7e46 100644 --- a/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt +++ b/core/src/main/kotlin/cache/data/GuildApplicationCommandPermissionData.kt @@ -3,6 +3,8 @@ package dev.kord.core.cache.data import dev.kord.common.entity.ApplicationCommandPermissionType import dev.kord.common.entity.DiscordGuildApplicationCommandPermission import dev.kord.common.entity.Snowflake +import kotlin.DeprecationLevel.ERROR +import kotlin.DeprecationLevel.HIDDEN public data class GuildApplicationCommandPermissionData( @@ -10,10 +12,61 @@ public data class GuildApplicationCommandPermissionData( val type: ApplicationCommandPermissionType, val permission: Boolean ) { + @Suppress("DEPRECATION_ERROR") + @Deprecated( + "'DiscordGuildApplicationCommandPermission.Type' is replaced by 'ApplicationCommandPermissionType'", + level = ERROR, + ) + public constructor(id: Snowflake, type: DiscordGuildApplicationCommandPermission.Type, permission: Boolean) : this( + id, + type.toNewType(), + permission, + ) + + @Suppress("DEPRECATION_ERROR") + @Deprecated("Binary compatibility", level = HIDDEN) + @get:JvmName("getType") + public val type0: DiscordGuildApplicationCommandPermission.Type get() = type.toDeprecatedType() + + @Suppress("DEPRECATION_ERROR", "FunctionName") + @Deprecated("Binary compatibility", level = HIDDEN) + @JvmName("component2") + public fun _component2(): DiscordGuildApplicationCommandPermission.Type = type.toDeprecatedType() + + @Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") + @Deprecated( + "'DiscordGuildApplicationCommandPermission.Type' is replaced by 'ApplicationCommandPermissionType'", + level = ERROR, + ) + public fun copy( + id: Snowflake = this.id, + type: DiscordGuildApplicationCommandPermission.Type = this.type.toDeprecatedType(), + permission: Boolean = this.permission, + ): GuildApplicationCommandPermissionData = GuildApplicationCommandPermissionData(id, type, permission) + + public companion object { public fun from(permission: DiscordGuildApplicationCommandPermission): GuildApplicationCommandPermissionData = with(permission) { GuildApplicationCommandPermissionData(id, type, this.permission) } + + + // functions for migration purposes, remove when bumping deprecations + @Suppress("DEPRECATION_ERROR") + private fun ApplicationCommandPermissionType.toDeprecatedType() = when (this) { + ApplicationCommandPermissionType.Role -> DiscordGuildApplicationCommandPermission.Type.Role + ApplicationCommandPermissionType.User -> DiscordGuildApplicationCommandPermission.Type.User + ApplicationCommandPermissionType.Channel -> DiscordGuildApplicationCommandPermission.Type.Channel + is ApplicationCommandPermissionType.Unknown -> DiscordGuildApplicationCommandPermission.Type.Unknown(value) + } + + @Suppress("DEPRECATION_ERROR") + private fun DiscordGuildApplicationCommandPermission.Type.toNewType() = when (this) { + DiscordGuildApplicationCommandPermission.Type.Role -> ApplicationCommandPermissionType.Role + DiscordGuildApplicationCommandPermission.Type.User -> ApplicationCommandPermissionType.User + DiscordGuildApplicationCommandPermission.Type.Channel -> ApplicationCommandPermissionType.Channel + is DiscordGuildApplicationCommandPermission.Type.Unknown -> ApplicationCommandPermissionType.Unknown(value) + } } } diff --git a/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt b/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt index a7580794ffe9..c25e67e0ed50 100644 --- a/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt +++ b/core/src/main/kotlin/entity/application/ApplicationGuildCommandPermissions.kt @@ -1,11 +1,13 @@ package dev.kord.core.entity.application import dev.kord.common.entity.ApplicationCommandPermissionType +import dev.kord.common.entity.DiscordGuildApplicationCommandPermission import dev.kord.common.entity.Snowflake import dev.kord.core.cache.data.GuildApplicationCommandPermissionData import dev.kord.core.cache.data.GuildApplicationCommandPermissionsData import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlin.DeprecationLevel.HIDDEN public class GuildApplicationCommandPermission(public val data: GuildApplicationCommandPermissionData) { @@ -13,6 +15,17 @@ public class GuildApplicationCommandPermission(public val data: GuildApplication public val type: ApplicationCommandPermissionType get() = data.type + @Suppress("DEPRECATION_ERROR") + @Deprecated("Binary compatibility", level = HIDDEN) + @get:JvmName("getType") + public val type0: DiscordGuildApplicationCommandPermission.Type + get() = when (val t = type) { + ApplicationCommandPermissionType.Role -> DiscordGuildApplicationCommandPermission.Type.Role + ApplicationCommandPermissionType.User -> DiscordGuildApplicationCommandPermission.Type.User + ApplicationCommandPermissionType.Channel -> DiscordGuildApplicationCommandPermission.Type.Channel + is ApplicationCommandPermissionType.Unknown -> DiscordGuildApplicationCommandPermission.Type.Unknown(t.value) + } + public val permission: Boolean get() = data.permission } From b06be402513a1416025d5911878cb564d3f0bc02 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 20:26:44 +0200 Subject: [PATCH 36/47] Add `@DslMarker` for scope control in KotlinPoet DSL --- .../{KotlinPoetUtils.kt => KotlinPoetDsl.kt} | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) rename ksp-processors/src/main/kotlin/{KotlinPoetUtils.kt => KotlinPoetDsl.kt} (70%) diff --git a/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt similarity index 70% rename from ksp-processors/src/main/kotlin/KotlinPoetUtils.kt rename to ksp-processors/src/main/kotlin/KotlinPoetDsl.kt index 7b0c755a8bff..4cb2922b0739 100644 --- a/ksp-processors/src/main/kotlin/KotlinPoetUtils.kt +++ b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt @@ -2,16 +2,29 @@ package dev.kord.ksp import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.MemberName.Companion.member +import kotlin.annotation.AnnotationTarget.TYPE + +// for scope control, see https://kotlinlang.org/docs/type-safe-builders.html#scope-control-dslmarker +@DslMarker +@Target(TYPE) +internal annotation class KotlinPoetDsl + +internal typealias FileSpecBuilder = (@KotlinPoetDsl FileSpec.Builder).() -> Unit +internal typealias TypeSpecBuilder = (@KotlinPoetDsl TypeSpec.Builder).() -> Unit +internal typealias AnnotationSpecBuilder = (@KotlinPoetDsl AnnotationSpec.Builder).() -> Unit +internal typealias FunSpecBuilder = (@KotlinPoetDsl FunSpec.Builder).() -> Unit +internal typealias PropertySpecBuilder = (@KotlinPoetDsl PropertySpec.Builder).() -> Unit +internal typealias CodeBlockBuilder = (@KotlinPoetDsl CodeBlock.Builder).() -> Unit // standalone -internal inline fun FileSpec(packageName: String, fileName: String, builder: FileSpec.Builder.() -> Unit) = +internal inline fun FileSpec(packageName: String, fileName: String, builder: FileSpecBuilder) = FileSpec.builder(packageName, fileName).apply(builder).build() // FileSpec.Builder -internal inline fun FileSpec.Builder.addClass(className: ClassName, builder: TypeSpec.Builder.() -> Unit) = +internal inline fun FileSpec.Builder.addClass(className: ClassName, builder: TypeSpecBuilder) = addType(TypeSpec.classBuilder(className).apply(builder).build()) @DelicateKotlinPoetApi("See 'AnnotationSpec.get'") @@ -21,40 +34,39 @@ internal fun FileSpec.Builder.addAnnotation(annotation: Annotation, includeDefau // TypeSpec.Builder -internal inline fun TypeSpec.Builder.addAnnotation( - builder: AnnotationSpec.Builder.() -> Unit, -) = addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) +internal inline fun TypeSpec.Builder.addAnnotation(builder: AnnotationSpecBuilder) = + addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) @DelicateKotlinPoetApi("See 'AnnotationSpec.get'") internal fun TypeSpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) -internal inline fun TypeSpec.Builder.primaryConstructor(builder: FunSpec.Builder.() -> Unit) = +internal inline fun TypeSpec.Builder.primaryConstructor(builder: FunSpecBuilder) = primaryConstructor(FunSpec.constructorBuilder().apply(builder).build()) internal inline fun TypeSpec.Builder.addProperty( name: String, vararg modifiers: KModifier, - builder: PropertySpec.Builder.() -> Unit, + builder: PropertySpecBuilder, ) = addProperty(PropertySpec.builder(name, typeNameOf(), *modifiers).apply(builder).build()) internal inline fun TypeSpec.Builder.addProperty( name: String, type: TypeName, vararg modifiers: KModifier, - builder: PropertySpec.Builder.() -> Unit, + builder: PropertySpecBuilder, ) = addProperty(PropertySpec.builder(name, type, *modifiers).apply(builder).build()) -internal inline fun TypeSpec.Builder.addFunction(name: String, builder: FunSpec.Builder.() -> Unit) = +internal inline fun TypeSpec.Builder.addFunction(name: String, builder: FunSpecBuilder) = addFunction(FunSpec.builder(name).apply(builder).build()) -internal inline fun TypeSpec.Builder.addClass(name: String, builder: TypeSpec.Builder.() -> Unit) = +internal inline fun TypeSpec.Builder.addClass(name: String, builder: TypeSpecBuilder) = addType(TypeSpec.classBuilder(name).apply(builder).build()) -internal inline fun TypeSpec.Builder.addObject(name: String, builder: TypeSpec.Builder.() -> Unit) = +internal inline fun TypeSpec.Builder.addObject(name: String, builder: TypeSpecBuilder) = addType(TypeSpec.objectBuilder(name).apply(builder).build()) -internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, builder: TypeSpec.Builder.() -> Unit) = +internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, builder: TypeSpecBuilder) = addType(TypeSpec.companionObjectBuilder(name).apply(builder).build()) @@ -65,23 +77,20 @@ internal inline fun FunSpec.Builder.returns() = returns(typeNameOf FunSpec.Builder.addParameter(name: String, vararg modifiers: KModifier) = addParameter(name, typeNameOf(), *modifiers) -internal inline fun FunSpec.Builder.withControlFlow( - controlFlow: String, - vararg args: Any, - builder: FunSpec.Builder.() -> Unit, -) = beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() +internal inline fun FunSpec.Builder.withControlFlow(controlFlow: String, vararg args: Any, builder: FunSpecBuilder) = + beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() // PropertySpec.Builder -internal inline fun PropertySpec.Builder.delegate(builder: CodeBlock.Builder.() -> Unit) = +internal inline fun PropertySpec.Builder.delegate(builder: CodeBlockBuilder) = delegate(CodeBlock.builder().apply(builder).build()) @DelicateKotlinPoetApi("See 'AnnotationSpec.get'") internal fun PropertySpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) -internal inline fun PropertySpec.Builder.getter(builder: FunSpec.Builder.() -> Unit) = +internal inline fun PropertySpec.Builder.getter(builder: FunSpecBuilder) = getter(FunSpec.getterBuilder().apply(builder).build()) @@ -90,7 +99,7 @@ internal inline fun PropertySpec.Builder.getter(builder: FunSpec.Builder.() -> U internal inline fun CodeBlock.Builder.withControlFlow( controlFlow: String, vararg args: Any?, - builder: CodeBlock.Builder.() -> Unit, + builder: CodeBlockBuilder, ) = beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() From c15e5268661d4c25f3d5e54c648208050ca54d56 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 20:29:09 +0200 Subject: [PATCH 37/47] Remove comments --- .../kotlin/kordenum/KordEnumGeneration.kt | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index c04441da004c..bb1f971c143f 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -27,6 +27,7 @@ import com.squareup.kotlinpoet.STRING as STRING_CLASS_NAME private val PRIMITIVE_SERIAL_DESCRIPTOR = MemberName("kotlinx.serialization.descriptors", "PrimitiveSerialDescriptor") private val KORD_EXPERIMENTAL = ClassName("dev.kord.common.annotation", "KordExperimental") +private val K_SERIALIZER = KSerializer::class.asClassName() private val Entry.warningSuppressedName get() = when { @@ -97,9 +98,6 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { @OptIn(DelicateKotlinPoetApi::class) // `AnnotationSpec.get` is ok for `Suppress` addAnnotation(Suppress("RedundantVisibilityModifier", "IncorrectFormatting", "ReplaceArrayOfWithLiteral")) - // /** */ - // @Serializable(with = .Serializer::class) - // public sealed class (public val : () @@ -125,7 +122,6 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addStatement("return this·===·other || (other·is·%T·&&·this.$valueName·==·other.$valueName)", enumName) } - // final override fun hashCode addFunction("hashCode") { addModifiers(FINAL, OVERRIDE) returns() @@ -133,15 +129,13 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } // TODO for all value types - // final override fun toString - if (valueType == STRING) addFunction("toString"){ + if (valueType == STRING) addFunction("toString") { addModifiers(FINAL, OVERRIDE) returns() addStatement("return \"%T($valueName=\$$valueName)\"", enumName) } - // public class Unknown(: ) : () addClass("Unknown") { addKdoc( "An unknown [%1T].\n\nThis is used as a fallback for [%1T]s that haven't been added to Kord yet.", @@ -164,17 +158,12 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addSuperclassConstructorParameter(valueFormat, entry.value) } - // /** */ - // public object : () for (entry in entries) { addObject(entry.name) { entry(entry) } } - // /** */ - // @Deprecated(, , ) - // public object : () for (entry in deprecatedEntries) { addObject(entry.name) { entry(entry) @@ -187,9 +176,8 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { // internal object Serializer : KSerializer<> addObject("Serializer") { addModifiers(INTERNAL) - addSuperinterface(KSerializer::class.asClassName().parameterizedBy(enumName)) + addSuperinterface(K_SERIALIZER.parameterizedBy(enumName)) - // override val descriptor addProperty("descriptor", OVERRIDE) { initializer( "%M(%S, %T)", @@ -199,7 +187,6 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { ) } - // override fun serialize addFunction("serialize") { addModifiers(OVERRIDE) addParameter("encoder") @@ -207,7 +194,6 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addStatement("return encoder.encode$encodingPostfix(value.$valueName)") } - // override fun deserialize addFunction("deserialize") { addModifiers(OVERRIDE) addParameter("decoder") @@ -225,7 +211,6 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addCompanionObject { addModifiers(PUBLIC) - // public val entries addProperty("entries", LIST.parameterizedBy(enumName), PUBLIC) { delegate { withControlFlow("lazy(mode·=·%M)", PUBLICATION.asMemberName()) { @@ -241,8 +226,6 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } // TODO bump deprecation level and remove eventually - // @Deprecated("Renamed to 'entries'.", ReplaceWith("this.entries"), level = WARNING) - // public val if (valuesPropertyName != null) { addProperty( valuesPropertyName, From 4dd56352fb7960ab3293c49de1040528ef79d994 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 20:52:33 +0200 Subject: [PATCH 38/47] Binary compatibility for old public serializers --- common/api/common.api | 88 +++++++++++++++++++ .../dev/kord/common/entity/ButtonStyle.kt | 30 ++++++- .../dev/kord/common/entity/ComponentType.kt | 30 ++++++- .../entity/GuildScheduledEventStatus.kt | 30 ++++++- .../entity/IntegrationExpireBehavior.kt | 30 ++++++- .../dev/kord/common/entity/PresenceStatus.kt | 26 ++++++ .../kord/common/entity/ScheduledEntityType.kt | 30 ++++++- .../entity/StageInstancePrivacyLevel.kt | 29 +++++- .../kord/common/entity/TeamMembershipState.kt | 27 ++++++ .../main/kotlin/entity/DiscordComponent.kt | 2 + .../entity/DiscordGuildScheduledEvent.kt | 2 + .../main/kotlin/entity/DiscordIntegration.kt | 1 + .../kotlin/entity/DiscordStageInstance.kt | 1 + common/src/main/kotlin/entity/Presence.kt | 1 + common/src/main/kotlin/entity/Team.kt | 1 + .../src/main/kotlin/GenerateKordEnum.kt | 2 + .../src/main/kotlin/KotlinPoetDsl.kt | 4 + .../src/main/kotlin/kordenum/KordEnum.kt | 4 +- .../kotlin/kordenum/KordEnumGeneration.kt | 48 +++++++++- 19 files changed, 369 insertions(+), 17 deletions(-) diff --git a/common/api/common.api b/common/api/common.api index ef7912ec54f3..5a5deb7b1d0b 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -1321,6 +1321,7 @@ public final class dev/kord/common/entity/BulkDeleteData$Companion { public abstract class dev/kord/common/entity/ButtonStyle { public static final field Companion Ldev/kord/common/entity/ButtonStyle$Companion; + public static final field Serializer Ldev/kord/common/entity/ButtonStyle$Serializer; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I @@ -1348,6 +1349,16 @@ public final class dev/kord/common/entity/ButtonStyle$Secondary : dev/kord/commo public static final field INSTANCE Ldev/kord/common/entity/ButtonStyle$Secondary; } +public final class dev/kord/common/entity/ButtonStyle$Serializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/ButtonStyle$Serializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/ButtonStyle; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/ButtonStyle;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/ButtonStyle$Success : dev/kord/common/entity/ButtonStyle { public static final field INSTANCE Ldev/kord/common/entity/ButtonStyle$Success; } @@ -1687,6 +1698,7 @@ public final class dev/kord/common/entity/CommandGroup : dev/kord/common/entity/ public abstract class dev/kord/common/entity/ComponentType { public static final field Companion Ldev/kord/common/entity/ComponentType$Companion; + public static final field Serializer Ldev/kord/common/entity/ComponentType$Serializer; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I @@ -1710,6 +1722,16 @@ public final class dev/kord/common/entity/ComponentType$SelectMenu : dev/kord/co public static final field INSTANCE Ldev/kord/common/entity/ComponentType$SelectMenu; } +public final class dev/kord/common/entity/ComponentType$Serializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/ComponentType$Serializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/ComponentType; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/ComponentType;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/ComponentType$TextInput : dev/kord/common/entity/ComponentType { public static final field INSTANCE Ldev/kord/common/entity/ComponentType$TextInput; } @@ -6241,6 +6263,7 @@ public final class dev/kord/common/entity/GuildScheduledEventPrivacyLevel$Unknow public abstract class dev/kord/common/entity/GuildScheduledEventStatus { public static final field Companion Ldev/kord/common/entity/GuildScheduledEventStatus$Companion; + public static final field Serializer Ldev/kord/common/entity/GuildScheduledEventStatus$Serializer; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I @@ -6268,6 +6291,16 @@ public final class dev/kord/common/entity/GuildScheduledEventStatus$Scheduled : public static final field INSTANCE Ldev/kord/common/entity/GuildScheduledEventStatus$Scheduled; } +public final class dev/kord/common/entity/GuildScheduledEventStatus$Serializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/GuildScheduledEventStatus$Serializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/GuildScheduledEventStatus; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/GuildScheduledEventStatus;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/GuildScheduledEventStatus$Unknown : dev/kord/common/entity/GuildScheduledEventStatus { public fun (I)V } @@ -6347,6 +6380,7 @@ public final class dev/kord/common/entity/IntegrationApplication$Companion { public abstract class dev/kord/common/entity/IntegrationExpireBehavior { public static final field Companion Ldev/kord/common/entity/IntegrationExpireBehavior$Companion; + public static final field Serializer Ldev/kord/common/entity/IntegrationExpireBehavior$Serializer; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I @@ -6366,6 +6400,16 @@ public final class dev/kord/common/entity/IntegrationExpireBehavior$RemoveRole : public static final field INSTANCE Ldev/kord/common/entity/IntegrationExpireBehavior$RemoveRole; } +public final class dev/kord/common/entity/IntegrationExpireBehavior$Serializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/IntegrationExpireBehavior$Serializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/IntegrationExpireBehavior; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/IntegrationExpireBehavior;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/IntegrationExpireBehavior$Unknown : dev/kord/common/entity/IntegrationExpireBehavior { public fun (I)V } @@ -7341,6 +7385,7 @@ public final class dev/kord/common/entity/PremiumTier$Unknown : dev/kord/common/ public abstract class dev/kord/common/entity/PresenceStatus { public static final field Companion Ldev/kord/common/entity/PresenceStatus$Companion; + public static final field StatusSerializer Ldev/kord/common/entity/PresenceStatus$StatusSerializer; public synthetic fun (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()Ljava/lang/String; @@ -7373,6 +7418,16 @@ public final class dev/kord/common/entity/PresenceStatus$Online : dev/kord/commo public static final field INSTANCE Ldev/kord/common/entity/PresenceStatus$Online; } +public final class dev/kord/common/entity/PresenceStatus$StatusSerializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/PresenceStatus$StatusSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/PresenceStatus; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/PresenceStatus;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/PresenceStatus$Unknown : dev/kord/common/entity/PresenceStatus { public fun (Ljava/lang/String;)V } @@ -7455,6 +7510,7 @@ public final class dev/kord/common/entity/ResolvedObjects$Companion { public abstract class dev/kord/common/entity/ScheduledEntityType { public static final field Companion Ldev/kord/common/entity/ScheduledEntityType$Companion; + public static final field Serializer Ldev/kord/common/entity/ScheduledEntityType$Serializer; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I @@ -7470,6 +7526,16 @@ public final class dev/kord/common/entity/ScheduledEntityType$External : dev/kor public static final field INSTANCE Ldev/kord/common/entity/ScheduledEntityType$External; } +public final class dev/kord/common/entity/ScheduledEntityType$Serializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/ScheduledEntityType$Serializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/ScheduledEntityType; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/ScheduledEntityType;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/ScheduledEntityType$StageInstance : dev/kord/common/entity/ScheduledEntityType { public static final field INSTANCE Ldev/kord/common/entity/ScheduledEntityType$StageInstance; } @@ -7522,6 +7588,7 @@ public final class dev/kord/common/entity/SnowflakeKt { public abstract class dev/kord/common/entity/StageInstancePrivacyLevel { public static final field Companion Ldev/kord/common/entity/StageInstancePrivacyLevel$Companion; + public static final field Serializer Ldev/kord/common/entity/StageInstancePrivacyLevel$Serializer; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I @@ -7541,6 +7608,16 @@ public final class dev/kord/common/entity/StageInstancePrivacyLevel$Public : dev public static final field INSTANCE Ldev/kord/common/entity/StageInstancePrivacyLevel$Public; } +public final class dev/kord/common/entity/StageInstancePrivacyLevel$Serializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/StageInstancePrivacyLevel$Serializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/StageInstancePrivacyLevel; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/StageInstancePrivacyLevel;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/StageInstancePrivacyLevel$Unknown : dev/kord/common/entity/StageInstancePrivacyLevel { public fun (I)V } @@ -7629,6 +7706,7 @@ public final class dev/kord/common/entity/TargetUserType$Unknown : dev/kord/comm public abstract class dev/kord/common/entity/TeamMembershipState { public static final field Companion Ldev/kord/common/entity/TeamMembershipState$Companion; + public static final field TeamMembershipStateSerializer Ldev/kord/common/entity/TeamMembershipState$TeamMembershipStateSerializer; public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I @@ -7648,6 +7726,16 @@ public final class dev/kord/common/entity/TeamMembershipState$Invited : dev/kord public static final field INSTANCE Ldev/kord/common/entity/TeamMembershipState$Invited; } +public final class dev/kord/common/entity/TeamMembershipState$TeamMembershipStateSerializer : kotlinx/serialization/KSerializer { + public static final field INSTANCE Ldev/kord/common/entity/TeamMembershipState$TeamMembershipStateSerializer; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/kord/common/entity/TeamMembershipState; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/kord/common/entity/TeamMembershipState;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public final class dev/kord/common/entity/TeamMembershipState$Unknown : dev/kord/common/entity/TeamMembershipState { public fun (I)V } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt index 75f6121495b5..a3775e817b00 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt @@ -6,10 +6,14 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -24,7 +28,7 @@ import kotlinx.serialization.encoding.Encoder * A preview of the different styles can be found * [here](https://discord.com/developers/docs/interactions/message-components#button-object-button-styles). */ -@Serializable(with = ButtonStyle.Serializer::class) +@Serializable(with = ButtonStyle.NewSerializer::class) public sealed class ButtonStyle( public val `value`: Int, ) { @@ -67,7 +71,7 @@ public sealed class ButtonStyle( */ public object Link : ButtonStyle(5) - internal object Serializer : KSerializer { + internal object NewSerializer : KSerializer { public override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.ButtonStyle", PrimitiveKind.INT) @@ -84,6 +88,20 @@ public sealed class ButtonStyle( } } + @Deprecated( + message = "Use 'ButtonStyle.serializer()' instead.", + replaceWith = ReplaceWith(expression = "ButtonStyle.serializer()", imports = + arrayOf("dev.kord.common.entity.ButtonStyle")), + ) + public object Serializer : KSerializer by NewSerializer { + @Deprecated( + message = "Use 'ButtonStyle.serializer()' instead.", + replaceWith = ReplaceWith(expression = "ButtonStyle.serializer()", imports = + arrayOf("dev.kord.common.entity.ButtonStyle")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -95,5 +113,13 @@ public sealed class ButtonStyle( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val Serializer: Serializer = Serializer } } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt index 496c3eb31a87..cadb57ea3aa7 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt @@ -6,10 +6,14 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -18,7 +22,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -@Serializable(with = ComponentType.Serializer::class) +@Serializable(with = ComponentType.NewSerializer::class) public sealed class ComponentType( public val `value`: Int, ) { @@ -56,7 +60,7 @@ public sealed class ComponentType( */ public object TextInput : ComponentType(4) - internal object Serializer : KSerializer { + internal object NewSerializer : KSerializer { public override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.ComponentType", PrimitiveKind.INT) @@ -72,6 +76,20 @@ public sealed class ComponentType( } } + @Deprecated( + message = "Use 'ComponentType.serializer()' instead.", + replaceWith = ReplaceWith(expression = "ComponentType.serializer()", imports = + arrayOf("dev.kord.common.entity.ComponentType")), + ) + public object Serializer : KSerializer by NewSerializer { + @Deprecated( + message = "Use 'ComponentType.serializer()' instead.", + replaceWith = ReplaceWith(expression = "ComponentType.serializer()", imports = + arrayOf("dev.kord.common.entity.ComponentType")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -82,5 +100,13 @@ public sealed class ComponentType( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val Serializer: Serializer = Serializer } } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt index ab832b856a7e..9b10c198dc31 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt @@ -6,10 +6,14 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -18,7 +22,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -@Serializable(with = GuildScheduledEventStatus.Serializer::class) +@Serializable(with = GuildScheduledEventStatus.NewSerializer::class) public sealed class GuildScheduledEventStatus( public val `value`: Int, ) { @@ -45,7 +49,7 @@ public sealed class GuildScheduledEventStatus( public object Cancelled : GuildScheduledEventStatus(4) - internal object Serializer : KSerializer { + internal object NewSerializer : KSerializer { public override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.GuildScheduledEventStatus", PrimitiveKind.INT) @@ -62,6 +66,20 @@ public sealed class GuildScheduledEventStatus( } } + @Deprecated( + message = "Use 'GuildScheduledEventStatus.serializer()' instead.", + replaceWith = ReplaceWith(expression = "GuildScheduledEventStatus.serializer()", imports = + arrayOf("dev.kord.common.entity.GuildScheduledEventStatus")), + ) + public object Serializer : KSerializer by NewSerializer { + @Deprecated( + message = "Use 'GuildScheduledEventStatus.serializer()' instead.", + replaceWith = ReplaceWith(expression = "GuildScheduledEventStatus.serializer()", imports + = arrayOf("dev.kord.common.entity.GuildScheduledEventStatus")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -72,5 +90,13 @@ public sealed class GuildScheduledEventStatus( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val Serializer: Serializer = Serializer } } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt index f19a01c57bbc..9f53af562dfa 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt @@ -6,10 +6,14 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -18,7 +22,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -@Serializable(with = IntegrationExpireBehavior.Serializer::class) +@Serializable(with = IntegrationExpireBehavior.NewSerializer::class) public sealed class IntegrationExpireBehavior( public val `value`: Int, ) { @@ -41,7 +45,7 @@ public sealed class IntegrationExpireBehavior( public object Kick : IntegrationExpireBehavior(1) - internal object Serializer : KSerializer { + internal object NewSerializer : KSerializer { public override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.IntegrationExpireBehavior", PrimitiveKind.INT) @@ -56,6 +60,20 @@ public sealed class IntegrationExpireBehavior( } } + @Deprecated( + message = "Use 'IntegrationExpireBehavior.serializer()' instead.", + replaceWith = ReplaceWith(expression = "IntegrationExpireBehavior.serializer()", imports = + arrayOf("dev.kord.common.entity.IntegrationExpireBehavior")), + ) + public object Serializer : KSerializer by NewSerializer { + @Deprecated( + message = "Use 'IntegrationExpireBehavior.serializer()' instead.", + replaceWith = ReplaceWith(expression = "IntegrationExpireBehavior.serializer()", imports + = arrayOf("dev.kord.common.entity.IntegrationExpireBehavior")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -64,5 +82,13 @@ public sealed class IntegrationExpireBehavior( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val Serializer: Serializer = Serializer } } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt index 8a4bc3c83b10..02194a92d980 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt @@ -6,11 +6,15 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.String import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -83,6 +87,20 @@ public sealed class PresenceStatus( } } + @Deprecated( + message = "Use 'PresenceStatus.serializer()' instead.", + replaceWith = ReplaceWith(expression = "PresenceStatus.serializer()", imports = + arrayOf("dev.kord.common.entity.PresenceStatus")), + ) + public object StatusSerializer : KSerializer by Serializer { + @Deprecated( + message = "Use 'PresenceStatus.serializer()' instead.", + replaceWith = ReplaceWith(expression = "PresenceStatus.serializer()", imports = + arrayOf("dev.kord.common.entity.PresenceStatus")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -94,5 +112,13 @@ public sealed class PresenceStatus( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val StatusSerializer: StatusSerializer = StatusSerializer } } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt index 1da62057bc74..d0f9a3587ec7 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt @@ -6,10 +6,14 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -18,7 +22,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -@Serializable(with = ScheduledEntityType.Serializer::class) +@Serializable(with = ScheduledEntityType.NewSerializer::class) public sealed class ScheduledEntityType( public val `value`: Int, ) { @@ -42,7 +46,7 @@ public sealed class ScheduledEntityType( public object External : ScheduledEntityType(3) - internal object Serializer : KSerializer { + internal object NewSerializer : KSerializer { public override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.ScheduledEntityType", PrimitiveKind.INT) @@ -58,6 +62,20 @@ public sealed class ScheduledEntityType( } } + @Deprecated( + message = "Use 'ScheduledEntityType.serializer()' instead.", + replaceWith = ReplaceWith(expression = "ScheduledEntityType.serializer()", imports = + arrayOf("dev.kord.common.entity.ScheduledEntityType")), + ) + public object Serializer : KSerializer by NewSerializer { + @Deprecated( + message = "Use 'ScheduledEntityType.serializer()' instead.", + replaceWith = ReplaceWith(expression = "ScheduledEntityType.serializer()", imports = + arrayOf("dev.kord.common.entity.ScheduledEntityType")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -67,5 +85,13 @@ public sealed class ScheduledEntityType( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val Serializer: Serializer = Serializer } } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt index 00dea49f40b9..67b37c63a50c 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt @@ -7,10 +7,13 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -19,7 +22,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -@Serializable(with = StageInstancePrivacyLevel.Serializer::class) +@Serializable(with = StageInstancePrivacyLevel.NewSerializer::class) public sealed class StageInstancePrivacyLevel( public val `value`: Int, ) { @@ -49,7 +52,7 @@ public sealed class StageInstancePrivacyLevel( @Deprecated(message = "Stages are no longer discoverable") public object Public : StageInstancePrivacyLevel(1) - internal object Serializer : KSerializer { + internal object NewSerializer : KSerializer { public override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dev.kord.common.entity.StageInstancePrivacyLevel", PrimitiveKind.INT) @@ -64,6 +67,20 @@ public sealed class StageInstancePrivacyLevel( } } + @Deprecated( + message = "Use 'StageInstancePrivacyLevel.serializer()' instead.", + replaceWith = ReplaceWith(expression = "StageInstancePrivacyLevel.serializer()", imports = + arrayOf("dev.kord.common.entity.StageInstancePrivacyLevel")), + ) + public object Serializer : KSerializer by NewSerializer { + @Deprecated( + message = "Use 'StageInstancePrivacyLevel.serializer()' instead.", + replaceWith = ReplaceWith(expression = "StageInstancePrivacyLevel.serializer()", imports + = arrayOf("dev.kord.common.entity.StageInstancePrivacyLevel")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -72,5 +89,13 @@ public sealed class StageInstancePrivacyLevel( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val Serializer: Serializer = Serializer } } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt index 26fc9c578014..946ebcf2fbe0 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt @@ -6,10 +6,14 @@ package dev.kord.common.entity import kotlin.Any import kotlin.Boolean +import kotlin.Deprecated +import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.ReplaceWith import kotlin.Suppress import kotlin.collections.List +import kotlin.jvm.JvmField import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.PrimitiveKind @@ -55,6 +59,20 @@ public sealed class TeamMembershipState( } } + @Deprecated( + message = "Use 'TeamMembershipState.serializer()' instead.", + replaceWith = ReplaceWith(expression = "TeamMembershipState.serializer()", imports = + arrayOf("dev.kord.common.entity.TeamMembershipState")), + ) + public object TeamMembershipStateSerializer : KSerializer by Serializer { + @Deprecated( + message = "Use 'TeamMembershipState.serializer()' instead.", + replaceWith = ReplaceWith(expression = "TeamMembershipState.serializer()", imports = + arrayOf("dev.kord.common.entity.TeamMembershipState")), + ) + public fun serializer(): KSerializer = this + } + public companion object { public val entries: List by lazy(mode = PUBLICATION) { listOf( @@ -63,5 +81,14 @@ public sealed class TeamMembershipState( ) } + + @Suppress(names = arrayOf("DEPRECATION")) + @Deprecated( + level = DeprecationLevel.HIDDEN, + message = "Binary compatibility", + ) + @JvmField + public val TeamMembershipStateSerializer: TeamMembershipStateSerializer = + TeamMembershipStateSerializer } } diff --git a/common/src/main/kotlin/entity/DiscordComponent.kt b/common/src/main/kotlin/entity/DiscordComponent.kt index 942c22c26559..f81690468939 100644 --- a/common/src/main/kotlin/entity/DiscordComponent.kt +++ b/common/src/main/kotlin/entity/DiscordComponent.kt @@ -1,5 +1,6 @@ @file:GenerateKordEnum( name = "ComponentType", valueType = INT, + deprecatedSerializerName = "Serializer", entries = [ Entry("ActionRow", intValue = 1, kDoc = "A container for other components."), Entry("Button", intValue = 2, kDoc = "A button object."), @@ -10,6 +11,7 @@ @file:GenerateKordEnum( name = "ButtonStyle", valueType = INT, + deprecatedSerializerName = "Serializer", kDoc = "Style of a [button][dev.kord.common.entity.ComponentType.Button].\n\nA preview of the different styles " + "can be found " + "[here](https://discord.com/developers/docs/interactions/message-components#button-object-button-styles).", diff --git a/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt b/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt index 4f7ba38e3677..7d4e22c89e2f 100644 --- a/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt +++ b/common/src/main/kotlin/entity/DiscordGuildScheduledEvent.kt @@ -5,6 +5,7 @@ @file:GenerateKordEnum( name = "ScheduledEntityType", valueType = INT, + deprecatedSerializerName = "Serializer", entries = [ Entry("StageInstance", intValue = 1), Entry("Voice", intValue = 2), @@ -14,6 +15,7 @@ @file:GenerateKordEnum( name = "GuildScheduledEventStatus", valueType = INT, + deprecatedSerializerName = "Serializer", entries = [ Entry("Scheduled", intValue = 1), Entry("Active", intValue = 2), diff --git a/common/src/main/kotlin/entity/DiscordIntegration.kt b/common/src/main/kotlin/entity/DiscordIntegration.kt index 48c3468cf6ba..ac2f31734ffe 100644 --- a/common/src/main/kotlin/entity/DiscordIntegration.kt +++ b/common/src/main/kotlin/entity/DiscordIntegration.kt @@ -1,5 +1,6 @@ @file:GenerateKordEnum( name = "IntegrationExpireBehavior", valueType = INT, + deprecatedSerializerName = "Serializer", entries = [ Entry("RemoveRole", intValue = 0), Entry("Kick", intValue = 1), diff --git a/common/src/main/kotlin/entity/DiscordStageInstance.kt b/common/src/main/kotlin/entity/DiscordStageInstance.kt index 8f7caf7e6923..08b1430cc943 100644 --- a/common/src/main/kotlin/entity/DiscordStageInstance.kt +++ b/common/src/main/kotlin/entity/DiscordStageInstance.kt @@ -1,5 +1,6 @@ @file:GenerateKordEnum( name = "StageInstancePrivacyLevel", valueType = INT, + deprecatedSerializerName = "Serializer", entries = [ Entry("GuildOnly", intValue = 2, kDoc = "The Stage instance is visible to only guild members."), ], diff --git a/common/src/main/kotlin/entity/Presence.kt b/common/src/main/kotlin/entity/Presence.kt index 8fc090a07a8c..a584b2218965 100644 --- a/common/src/main/kotlin/entity/Presence.kt +++ b/common/src/main/kotlin/entity/Presence.kt @@ -1,5 +1,6 @@ @file:GenerateKordEnum( name = "PresenceStatus", valueType = STRING, + deprecatedSerializerName = "StatusSerializer", entries = [ Entry("Online", stringValue = "online", kDoc = "Online."), Entry("DoNotDisturb", stringValue = "dnd", kDoc = "Do Not Disturb."), diff --git a/common/src/main/kotlin/entity/Team.kt b/common/src/main/kotlin/entity/Team.kt index 7562417f5ae6..50d7294e604f 100644 --- a/common/src/main/kotlin/entity/Team.kt +++ b/common/src/main/kotlin/entity/Team.kt @@ -1,5 +1,6 @@ @file:GenerateKordEnum( name = "TeamMembershipState", valueType = INT, + deprecatedSerializerName = "TeamMembershipStateSerializer", entries = [ Entry("Invited", intValue = 1), Entry("Accepted", intValue = 2), diff --git a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt index 344897b0f205..df3d15e7c441 100644 --- a/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt +++ b/ksp-annotations/src/main/kotlin/GenerateKordEnum.kt @@ -32,6 +32,8 @@ annotation class GenerateKordEnum( val valuesPropertyName: String = "", /** For migration purposes. */ val valuesPropertyType: ValuesPropertyType = NONE, + /** For migration purposes. */ + val deprecatedSerializerName: String = "", ) { enum class ValueType { INT, STRING } enum class ValuesPropertyType { NONE, SET } diff --git a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt index 4cb2922b0739..45437f660da7 100644 --- a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt +++ b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt @@ -72,6 +72,10 @@ internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, bu // FunSpec.Builder +@DelicateKotlinPoetApi("See 'AnnotationSpec.get'") +internal fun FunSpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = + addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) + internal inline fun FunSpec.Builder.returns() = returns(typeNameOf()) internal inline fun FunSpec.Builder.addParameter(name: String, vararg modifiers: KModifier) = diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt index 5e77b8fada19..b5ba4e7f24db 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnum.kt @@ -26,6 +26,7 @@ internal class KordEnum( // for migration purposes, TODO remove eventually val valuesPropertyName: String?, val valuesPropertyType: ValuesPropertyType, + val deprecatedSerializerName: String?, ) { internal class Entry( val name: String, @@ -67,13 +68,14 @@ internal fun KSAnnotation.toKordEnumOrNull(logger: KSPLogger): KordEnum? { return null } } + val deprecatedSerializerName = (args[GenerateKordEnum::deprecatedSerializerName] as String).ifEmpty { null } return KordEnum( name, kDoc, valueType, valueName, entries.map { it.toEntryOrNull(valueType, isDeprecated = false, logger) ?: return null }, deprecatedEntries.map { it.toEntryOrNull(valueType, isDeprecated = true, logger) ?: return null }, - valuesPropertyName, valuesPropertyType, + valuesPropertyName, valuesPropertyType, deprecatedSerializerName, ) } diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index bb1f971c143f..1cbfba1a2231 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -91,6 +91,9 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } } + // TODO remove eventually (always use "Serializer" then) + val internalSerializerName = if (deprecatedSerializerName == "Serializer") "NewSerializer" else "Serializer" + return FileSpec(packageName, fileName = name) { indent(" ") addFileComment("THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT!") @@ -105,7 +108,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { kDoc?.let { addKdoc(it) } addAnnotation { - addMember("with·=·%T.Serializer::class", enumName) + addMember("with·=·%T.$internalSerializerName::class", enumName) } addModifiers(PUBLIC, SEALED) primaryConstructor { @@ -173,8 +176,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } - // internal object Serializer : KSerializer<> - addObject("Serializer") { + addObject(internalSerializerName) { addModifiers(INTERNAL) addSuperinterface(K_SERIALIZER.parameterizedBy(enumName)) @@ -207,7 +209,32 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } - // public companion object + // TODO bump deprecation level and remove eventually + @OptIn(DelicateKotlinPoetApi::class) + if (deprecatedSerializerName != null) { + val name = this@generateFileSpec.name + val deprecatedAnnotation = Deprecated( + "Use '$name.serializer()' instead.", + ReplaceWith("$name.serializer()", "$packageName.$name"), + level = WARNING, + ) + val kSerializer = K_SERIALIZER.parameterizedBy(enumName) + + addObject(deprecatedSerializerName) { + addAnnotation(deprecatedAnnotation) + addModifiers(PUBLIC) + addSuperinterface(kSerializer, delegate = CodeBlock.of(internalSerializerName)) + + addFunction("serializer") { + addAnnotation(deprecatedAnnotation) + addModifiers(PUBLIC) + returns(kSerializer) + addStatement("return this") + } + } + } + + addCompanionObject { addModifiers(PUBLIC) @@ -245,6 +272,19 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { } } } + + // TODO remove eventually + if (deprecatedSerializerName != null) { + val deprecatedSerializer = enumName.nestedClass(deprecatedSerializerName) + + @OptIn(DelicateKotlinPoetApi::class) + addProperty(deprecatedSerializerName, deprecatedSerializer, PUBLIC) { + addAnnotation(Suppress("DEPRECATION")) + addAnnotation(Deprecated("Binary compatibility", level = HIDDEN)) + addAnnotation(JvmField()) + initializer("%T", deprecatedSerializer) + } + } } } } From 4ea2a61b0850c1beb56044461dfdf92c36ad3c79 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 21:03:31 +0200 Subject: [PATCH 39/47] New order for KotlinPoet DSL --- .../src/main/kotlin/KotlinPoetDsl.kt | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt index 45437f660da7..5047799f9826 100644 --- a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt +++ b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt @@ -16,23 +16,26 @@ internal typealias FunSpecBuilder = (@KotlinPoetDsl FunSpec.Builder).() -> Unit internal typealias PropertySpecBuilder = (@KotlinPoetDsl PropertySpec.Builder).() -> Unit internal typealias CodeBlockBuilder = (@KotlinPoetDsl CodeBlock.Builder).() -> Unit -// standalone + +// miscellaneous + +internal inline fun > E.asMemberName() = E::class.member(name) internal inline fun FileSpec(packageName: String, fileName: String, builder: FileSpecBuilder) = FileSpec.builder(packageName, fileName).apply(builder).build() -// FileSpec.Builder - -internal inline fun FileSpec.Builder.addClass(className: ClassName, builder: TypeSpecBuilder) = - addType(TypeSpec.classBuilder(className).apply(builder).build()) +// extensions for `FileSpec.Builder` @DelicateKotlinPoetApi("See 'AnnotationSpec.get'") internal fun FileSpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) +internal inline fun FileSpec.Builder.addClass(className: ClassName, builder: TypeSpecBuilder) = + addType(TypeSpec.classBuilder(className).apply(builder).build()) + -// TypeSpec.Builder +// extensions for `TypeSpec.Builder` internal inline fun TypeSpec.Builder.addAnnotation(builder: AnnotationSpecBuilder) = addAnnotation(AnnotationSpec.builder(A::class).apply(builder).build()) @@ -41,8 +44,17 @@ internal inline fun TypeSpec.Builder.addAnnotation(buil internal fun TypeSpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) -internal inline fun TypeSpec.Builder.primaryConstructor(builder: FunSpecBuilder) = - primaryConstructor(FunSpec.constructorBuilder().apply(builder).build()) +internal inline fun TypeSpec.Builder.addClass(name: String, builder: TypeSpecBuilder) = + addType(TypeSpec.classBuilder(name).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, builder: TypeSpecBuilder) = + addType(TypeSpec.companionObjectBuilder(name).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addFunction(name: String, builder: FunSpecBuilder) = + addFunction(FunSpec.builder(name).apply(builder).build()) + +internal inline fun TypeSpec.Builder.addObject(name: String, builder: TypeSpecBuilder) = + addType(TypeSpec.objectBuilder(name).apply(builder).build()) internal inline fun TypeSpec.Builder.addProperty( name: String, @@ -57,56 +69,42 @@ internal inline fun TypeSpec.Builder.addProperty( builder: PropertySpecBuilder, ) = addProperty(PropertySpec.builder(name, type, *modifiers).apply(builder).build()) -internal inline fun TypeSpec.Builder.addFunction(name: String, builder: FunSpecBuilder) = - addFunction(FunSpec.builder(name).apply(builder).build()) - -internal inline fun TypeSpec.Builder.addClass(name: String, builder: TypeSpecBuilder) = - addType(TypeSpec.classBuilder(name).apply(builder).build()) - -internal inline fun TypeSpec.Builder.addObject(name: String, builder: TypeSpecBuilder) = - addType(TypeSpec.objectBuilder(name).apply(builder).build()) - -internal inline fun TypeSpec.Builder.addCompanionObject(name: String? = null, builder: TypeSpecBuilder) = - addType(TypeSpec.companionObjectBuilder(name).apply(builder).build()) +internal inline fun TypeSpec.Builder.primaryConstructor(builder: FunSpecBuilder) = + primaryConstructor(FunSpec.constructorBuilder().apply(builder).build()) -// FunSpec.Builder +// extensions for `FunSpec.Builder` @DelicateKotlinPoetApi("See 'AnnotationSpec.get'") internal fun FunSpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) -internal inline fun FunSpec.Builder.returns() = returns(typeNameOf()) - internal inline fun FunSpec.Builder.addParameter(name: String, vararg modifiers: KModifier) = addParameter(name, typeNameOf(), *modifiers) +internal inline fun FunSpec.Builder.returns() = returns(typeNameOf()) + internal inline fun FunSpec.Builder.withControlFlow(controlFlow: String, vararg args: Any, builder: FunSpecBuilder) = beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() -// PropertySpec.Builder - -internal inline fun PropertySpec.Builder.delegate(builder: CodeBlockBuilder) = - delegate(CodeBlock.builder().apply(builder).build()) +// extensions for `PropertySpec.Builder` @DelicateKotlinPoetApi("See 'AnnotationSpec.get'") internal fun PropertySpec.Builder.addAnnotation(annotation: Annotation, includeDefaultValues: Boolean = false) = addAnnotation(AnnotationSpec.get(annotation, includeDefaultValues)) +internal inline fun PropertySpec.Builder.delegate(builder: CodeBlockBuilder) = + delegate(CodeBlock.builder().apply(builder).build()) + internal inline fun PropertySpec.Builder.getter(builder: FunSpecBuilder) = getter(FunSpec.getterBuilder().apply(builder).build()) -// CodeBlock.Builder +// extensions for `CodeBlock.Builder` internal inline fun CodeBlock.Builder.withControlFlow( controlFlow: String, vararg args: Any?, builder: CodeBlockBuilder, ) = beginControlFlow(controlFlow, *args).apply(builder).endControlFlow() - - -// other - -internal inline fun > E.asMemberName() = E::class.member(name) From a60166dcc1574034228ccb4d16a67149c680c840 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 21:23:35 +0200 Subject: [PATCH 40/47] Add `toString` to all kord enums --- common/api/common.api | 35 +++++++++++++++++++ .../kord/common/entity/AllowedMentionType.kt | 3 +- .../entity/ApplicationCommandOptionType.kt | 3 ++ .../ApplicationCommandPermissionType.kt | 4 +++ .../common/entity/ApplicationCommandType.kt | 4 +++ .../dev/kord/common/entity/AuditLogEvent.kt | 4 +++ .../common/entity/AutoModerationActionType.kt | 4 +++ .../entity/AutoModerationRuleEventType.kt | 4 +++ .../AutoModerationRuleKeywordPresetType.kt | 4 +++ .../entity/AutoModerationRuleTriggerType.kt | 4 +++ .../dev/kord/common/entity/ButtonStyle.kt | 4 +++ .../dev/kord/common/entity/ChannelType.kt | 4 +++ .../dev/kord/common/entity/ComponentType.kt | 4 +++ .../entity/DefaultMessageNotificationLevel.kt | 4 +++ .../entity/DiscordConnectionVisibility.kt | 4 +++ .../common/entity/ExplicitContentFilter.kt | 4 +++ .../dev/kord/common/entity/GuildFeature.kt | 3 +- .../entity/GuildScheduledEventPrivacyLevel.kt | 4 +++ .../entity/GuildScheduledEventStatus.kt | 4 +++ .../entity/IntegrationExpireBehavior.kt | 4 +++ .../common/entity/InteractionResponseType.kt | 4 +++ .../dev/kord/common/entity/InteractionType.kt | 4 +++ .../kord/common/entity/InviteTargetType.kt | 4 +++ .../kotlin/dev/kord/common/entity/MFALevel.kt | 4 +++ .../kord/common/entity/MessageActivityType.kt | 4 +++ .../kord/common/entity/MessageStickerType.kt | 4 +++ .../dev/kord/common/entity/MessageType.kt | 4 +++ .../dev/kord/common/entity/NsfwLevel.kt | 4 +++ .../dev/kord/common/entity/OverwriteType.kt | 4 +++ .../dev/kord/common/entity/PremiumTier.kt | 4 +++ .../dev/kord/common/entity/PresenceStatus.kt | 3 +- .../kord/common/entity/ScheduledEntityType.kt | 4 +++ .../entity/StageInstancePrivacyLevel.kt | 4 +++ .../kord/common/entity/TeamMembershipState.kt | 4 +++ .../dev/kord/common/entity/TextInputStyle.kt | 4 +++ .../dev/kord/common/entity/UserPremium.kt | 4 +++ .../kord/common/entity/VerificationLevel.kt | 4 +++ .../kord/common/entity/VideoQualityMode.kt | 4 +++ .../dev/kord/common/entity/WebhookType.kt | 4 +++ .../kotlin/kordenum/KordEnumGeneration.kt | 5 ++- 40 files changed, 182 insertions(+), 6 deletions(-) diff --git a/common/api/common.api b/common/api/common.api index 5a5deb7b1d0b..0c746e165db2 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -392,6 +392,7 @@ public abstract class dev/kord/common/entity/ApplicationCommandOptionType { public final fun equals (Ljava/lang/Object;)Z public final fun getType ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ApplicationCommandOptionType$Attachment : dev/kord/common/entity/ApplicationCommandOptionType { @@ -453,6 +454,7 @@ public abstract class dev/kord/common/entity/ApplicationCommandPermissionType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ApplicationCommandPermissionType$Channel : dev/kord/common/entity/ApplicationCommandPermissionType { @@ -482,6 +484,7 @@ public abstract class dev/kord/common/entity/ApplicationCommandType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ApplicationCommandType$ChatInput : dev/kord/common/entity/ApplicationCommandType { @@ -919,6 +922,7 @@ public abstract class dev/kord/common/entity/AuditLogEvent { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/AuditLogEvent$ApplicationCommandPermissionUpdate : dev/kord/common/entity/AuditLogEvent { @@ -1144,6 +1148,7 @@ public abstract class dev/kord/common/entity/AutoModerationActionType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/AutoModerationActionType$BlockMessage : dev/kord/common/entity/AutoModerationActionType { @@ -1173,6 +1178,7 @@ public abstract class dev/kord/common/entity/AutoModerationRuleEventType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/AutoModerationRuleEventType$Companion { @@ -1194,6 +1200,7 @@ public abstract class dev/kord/common/entity/AutoModerationRuleKeywordPresetType public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/AutoModerationRuleKeywordPresetType$Companion { @@ -1223,6 +1230,7 @@ public abstract class dev/kord/common/entity/AutoModerationRuleTriggerType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/AutoModerationRuleTriggerType$Companion { @@ -1326,6 +1334,7 @@ public abstract class dev/kord/common/entity/ButtonStyle { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ButtonStyle$Companion { @@ -1373,6 +1382,7 @@ public abstract class dev/kord/common/entity/ChannelType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ChannelType$Companion { @@ -1703,6 +1713,7 @@ public abstract class dev/kord/common/entity/ComponentType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ComponentType$ActionRow : dev/kord/common/entity/ComponentType { @@ -1746,6 +1757,7 @@ public abstract class dev/kord/common/entity/DefaultMessageNotificationLevel { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/DefaultMessageNotificationLevel$AllMessages : dev/kord/common/entity/DefaultMessageNotificationLevel { @@ -2889,6 +2901,7 @@ public abstract class dev/kord/common/entity/DiscordConnectionVisibility { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/DiscordConnectionVisibility$Companion { @@ -6071,6 +6084,7 @@ public abstract class dev/kord/common/entity/ExplicitContentFilter { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ExplicitContentFilter$AllMembers : dev/kord/common/entity/ExplicitContentFilter { @@ -6246,6 +6260,7 @@ public abstract class dev/kord/common/entity/GuildScheduledEventPrivacyLevel { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/GuildScheduledEventPrivacyLevel$Companion { @@ -6268,6 +6283,7 @@ public abstract class dev/kord/common/entity/GuildScheduledEventStatus { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/GuildScheduledEventStatus$Active : dev/kord/common/entity/GuildScheduledEventStatus { @@ -6385,6 +6401,7 @@ public abstract class dev/kord/common/entity/IntegrationExpireBehavior { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/IntegrationExpireBehavior$Companion { @@ -6472,6 +6489,7 @@ public abstract class dev/kord/common/entity/InteractionResponseType { public final fun equals (Ljava/lang/Object;)Z public final fun getType ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/InteractionResponseType$ApplicationCommandAutoCompleteResult : dev/kord/common/entity/InteractionResponseType { @@ -6517,6 +6535,7 @@ public abstract class dev/kord/common/entity/InteractionType { public final fun equals (Ljava/lang/Object;)Z public final fun getType ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/InteractionType$ApplicationCommand : dev/kord/common/entity/InteractionType { @@ -6561,6 +6580,7 @@ public abstract class dev/kord/common/entity/InviteTargetType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/InviteTargetType$Companion { @@ -6586,6 +6606,7 @@ public abstract class dev/kord/common/entity/MFALevel { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/MFALevel$Companion { @@ -6644,6 +6665,7 @@ public abstract class dev/kord/common/entity/MessageActivityType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/MessageActivityType$Companion { @@ -6845,6 +6867,7 @@ public abstract class dev/kord/common/entity/MessageStickerType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/MessageStickerType$APNG : dev/kord/common/entity/MessageStickerType { @@ -6875,6 +6898,7 @@ public abstract class dev/kord/common/entity/MessageType { public final fun equals (Ljava/lang/Object;)Z public final fun getCode ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/MessageType$AutoModerationAction : dev/kord/common/entity/MessageType { @@ -7018,6 +7042,7 @@ public abstract class dev/kord/common/entity/NsfwLevel { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/NsfwLevel$AgeRestricted : dev/kord/common/entity/NsfwLevel { @@ -7097,6 +7122,7 @@ public abstract class dev/kord/common/entity/OverwriteType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/OverwriteType$Companion { @@ -7356,6 +7382,7 @@ public abstract class dev/kord/common/entity/PremiumTier { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/PremiumTier$Companion { @@ -7515,6 +7542,7 @@ public abstract class dev/kord/common/entity/ScheduledEntityType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/ScheduledEntityType$Companion { @@ -7593,6 +7621,7 @@ public abstract class dev/kord/common/entity/StageInstancePrivacyLevel { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/StageInstancePrivacyLevel$Companion { @@ -7711,6 +7740,7 @@ public abstract class dev/kord/common/entity/TeamMembershipState { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/TeamMembershipState$Accepted : dev/kord/common/entity/TeamMembershipState { @@ -7746,6 +7776,7 @@ public abstract class dev/kord/common/entity/TextInputStyle { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/TextInputStyle$Companion { @@ -7827,6 +7858,7 @@ public abstract class dev/kord/common/entity/UserPremium { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/UserPremium$Companion { @@ -7856,6 +7888,7 @@ public abstract class dev/kord/common/entity/VerificationLevel { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/VerificationLevel$Companion { @@ -7893,6 +7926,7 @@ public abstract class dev/kord/common/entity/VideoQualityMode { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/VideoQualityMode$Auto : dev/kord/common/entity/VideoQualityMode { @@ -7918,6 +7952,7 @@ public abstract class dev/kord/common/entity/WebhookType { public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()I public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/WebhookType$Application : dev/kord/common/entity/WebhookType { diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt index c7b28dcbd2c6..96eef8aa35e7 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt @@ -28,7 +28,8 @@ public sealed class AllowedMentionType( public final override fun hashCode(): Int = value.hashCode() - public final override fun toString(): String = "AllowedMentionType(value=$value)" + public final override fun toString(): String = + "AllowedMentionType.${this::class.simpleName}(value=$value)" /** * An unknown [AllowedMentionType]. diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt index 8397e3491655..f014e6068098 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt @@ -26,6 +26,9 @@ public sealed class ApplicationCommandOptionType( public final override fun hashCode(): Int = type.hashCode() + public final override fun toString(): kotlin.String = + "ApplicationCommandOptionType.${this::class.simpleName}(type=$type)" + /** * An unknown [ApplicationCommandOptionType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt index 8d48a72e1e25..9d2dbfe69583 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class ApplicationCommandPermissionType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "ApplicationCommandPermissionType.${this::class.simpleName}(value=$value)" + /** * An unknown [ApplicationCommandPermissionType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt index b2a3c2d14c24..685f60723c17 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class ApplicationCommandType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "ApplicationCommandType.${this::class.simpleName}(value=$value)" + /** * An unknown [ApplicationCommandType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt index 42f34963ce7e..162324a9c685 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class AuditLogEvent( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "AuditLogEvent.${this::class.simpleName}(value=$value)" + /** * An unknown [AuditLogEvent]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt index bded2a1ab683..b42ac56ec7e6 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -30,6 +31,9 @@ public sealed class AutoModerationActionType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "AutoModerationActionType.${this::class.simpleName}(value=$value)" + /** * An unknown [AutoModerationActionType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt index 53277d626377..7e460f92313f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -30,6 +31,9 @@ public sealed class AutoModerationRuleEventType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "AutoModerationRuleEventType.${this::class.simpleName}(value=$value)" + /** * An unknown [AutoModerationRuleEventType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt index 05af1af6be66..5d4463007ecd 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -30,6 +31,9 @@ public sealed class AutoModerationRuleKeywordPresetType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "AutoModerationRuleKeywordPresetType.${this::class.simpleName}(value=$value)" + /** * An unknown [AutoModerationRuleKeywordPresetType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt index 424ea409f39c..a4b1216b0910 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt @@ -9,6 +9,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -31,6 +32,9 @@ public sealed class AutoModerationRuleTriggerType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "AutoModerationRuleTriggerType.${this::class.simpleName}(value=$value)" + /** * An unknown [AutoModerationRuleTriggerType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt index a3775e817b00..7f094e3503af 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt @@ -11,6 +11,7 @@ import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.jvm.JvmField @@ -37,6 +38,9 @@ public sealed class ButtonStyle( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "ButtonStyle.${this::class.simpleName}(value=$value)" + /** * An unknown [ButtonStyle]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index 2180850dda45..11c7ffa4d3af 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -10,6 +10,7 @@ import kotlin.Deprecated import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -29,6 +30,9 @@ public sealed class ChannelType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "ChannelType.${this::class.simpleName}(value=$value)" + /** * An unknown [ChannelType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt index cadb57ea3aa7..d0f04f6a115c 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt @@ -11,6 +11,7 @@ import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.jvm.JvmField @@ -31,6 +32,9 @@ public sealed class ComponentType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "ComponentType.${this::class.simpleName}(value=$value)" + /** * An unknown [ComponentType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt index 899aa5a572b7..483b74ac8d53 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class DefaultMessageNotificationLevel( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "DefaultMessageNotificationLevel.${this::class.simpleName}(value=$value)" + /** * An unknown [DefaultMessageNotificationLevel]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt index 026064e5f922..61bdba217498 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class DiscordConnectionVisibility( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "DiscordConnectionVisibility.${this::class.simpleName}(value=$value)" + /** * An unknown [DiscordConnectionVisibility]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt index 441411ad51a7..fef52679aea8 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class ExplicitContentFilter( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "ExplicitContentFilter.${this::class.simpleName}(value=$value)" + /** * An unknown [ExplicitContentFilter]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt index e72b1dd6a449..fd08f6b69946 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt @@ -29,7 +29,8 @@ public sealed class GuildFeature( public final override fun hashCode(): Int = value.hashCode() - public final override fun toString(): String = "GuildFeature(value=$value)" + public final override fun toString(): String = + "GuildFeature.${this::class.simpleName}(value=$value)" /** * An unknown [GuildFeature]. diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt index 038ca277f906..feaeef468fda 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class GuildScheduledEventPrivacyLevel( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "GuildScheduledEventPrivacyLevel.${this::class.simpleName}(value=$value)" + /** * An unknown [GuildScheduledEventPrivacyLevel]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt index 9b10c198dc31..0958614c9533 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt @@ -11,6 +11,7 @@ import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.jvm.JvmField @@ -31,6 +32,9 @@ public sealed class GuildScheduledEventStatus( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "GuildScheduledEventStatus.${this::class.simpleName}(value=$value)" + /** * An unknown [GuildScheduledEventStatus]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt index 9f53af562dfa..e56ea3f085cc 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt @@ -11,6 +11,7 @@ import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.jvm.JvmField @@ -31,6 +32,9 @@ public sealed class IntegrationExpireBehavior( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "IntegrationExpireBehavior.${this::class.simpleName}(value=$value)" + /** * An unknown [IntegrationExpireBehavior]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt index 2b7316045054..7076e2a4f9c6 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class InteractionResponseType( public final override fun hashCode(): Int = type.hashCode() + public final override fun toString(): String = + "InteractionResponseType.${this::class.simpleName}(type=$type)" + /** * An unknown [InteractionResponseType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt index a31c333c3622..46e08fd375bf 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class InteractionType( public final override fun hashCode(): Int = type.hashCode() + public final override fun toString(): String = + "InteractionType.${this::class.simpleName}(type=$type)" + /** * An unknown [InteractionType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt index 1eb3bccf9944..520d1f513f8a 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class InviteTargetType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "InviteTargetType.${this::class.simpleName}(value=$value)" + /** * An unknown [InviteTargetType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt index 269ff3a4b60d..13450afcc487 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class MFALevel( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "MFALevel.${this::class.simpleName}(value=$value)" + /** * An unknown [MFALevel]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt index 5afac456480d..c8903a799fc8 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class MessageActivityType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "MessageActivityType.${this::class.simpleName}(value=$value)" + /** * An unknown [MessageActivityType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt index 868a099c6f7b..baa8a0cd7b35 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt @@ -10,6 +10,7 @@ import kotlin.Deprecated import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.collections.Set @@ -30,6 +31,9 @@ public sealed class MessageStickerType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "MessageStickerType.${this::class.simpleName}(value=$value)" + /** * An unknown [MessageStickerType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt index 894f251d36e8..d8a1c5459c8f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt @@ -10,6 +10,7 @@ import kotlin.Deprecated import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.collections.Set @@ -30,6 +31,9 @@ public sealed class MessageType( public final override fun hashCode(): Int = code.hashCode() + public final override fun toString(): String = + "MessageType.${this::class.simpleName}(code=$code)" + /** * An unknown [MessageType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt index 5508bcc77d40..dc6e17e35b2a 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class NsfwLevel( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "NsfwLevel.${this::class.simpleName}(value=$value)" + /** * An unknown [NsfwLevel]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt index e4622d10029a..1db406385cd3 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class OverwriteType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "OverwriteType.${this::class.simpleName}(value=$value)" + /** * An unknown [OverwriteType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt index 9d12860d70d0..e2e132959932 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class PremiumTier( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "PremiumTier.${this::class.simpleName}(value=$value)" + /** * An unknown [PremiumTier]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt index 02194a92d980..bcf84ab5235e 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt @@ -32,7 +32,8 @@ public sealed class PresenceStatus( public final override fun hashCode(): Int = value.hashCode() - public final override fun toString(): String = "PresenceStatus(value=$value)" + public final override fun toString(): String = + "PresenceStatus.${this::class.simpleName}(value=$value)" /** * An unknown [PresenceStatus]. diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt index d0f9a3587ec7..6899c6a7330f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt @@ -11,6 +11,7 @@ import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.jvm.JvmField @@ -31,6 +32,9 @@ public sealed class ScheduledEntityType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "ScheduledEntityType.${this::class.simpleName}(value=$value)" + /** * An unknown [ScheduledEntityType]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt index 67b37c63a50c..dafcc50ea63c 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt @@ -11,6 +11,7 @@ import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.jvm.JvmField @@ -31,6 +32,9 @@ public sealed class StageInstancePrivacyLevel( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "StageInstancePrivacyLevel.${this::class.simpleName}(value=$value)" + /** * An unknown [StageInstancePrivacyLevel]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt index 946ebcf2fbe0..c98a9eede906 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt @@ -11,6 +11,7 @@ import kotlin.DeprecationLevel import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION import kotlin.ReplaceWith +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlin.jvm.JvmField @@ -31,6 +32,9 @@ public sealed class TeamMembershipState( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "TeamMembershipState.${this::class.simpleName}(value=$value)" + /** * An unknown [TeamMembershipState]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt index 5d1ad73ecb8b..b5ee1e06f1ee 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -30,6 +31,9 @@ public sealed class TextInputStyle( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "TextInputStyle.${this::class.simpleName}(value=$value)" + /** * An unknown [TextInputStyle]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt index 5ff43e1c44ea..2acf9b798556 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -30,6 +31,9 @@ public sealed class UserPremium( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "UserPremium.${this::class.simpleName}(value=$value)" + /** * An unknown [UserPremium]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt index aeb7fd6c199c..cb2ed7d597ad 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class VerificationLevel( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "VerificationLevel.${this::class.simpleName}(value=$value)" + /** * An unknown [VerificationLevel]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt index 8ede6a80e222..2b9255e92a7a 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class VideoQualityMode( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "VideoQualityMode.${this::class.simpleName}(value=$value)" + /** * An unknown [VideoQualityMode]. * diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt index 0cf11b7200ab..fb3458b94a13 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt @@ -8,6 +8,7 @@ import kotlin.Any import kotlin.Boolean import kotlin.Int import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String import kotlin.Suppress import kotlin.collections.List import kotlinx.serialization.KSerializer @@ -27,6 +28,9 @@ public sealed class WebhookType( public final override fun hashCode(): Int = value.hashCode() + public final override fun toString(): String = + "WebhookType.${this::class.simpleName}(value=$value)" + /** * An unknown [WebhookType]. * diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index 1cbfba1a2231..f7d65a6c57b9 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -131,11 +131,10 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addStatement("return $valueName.hashCode()") } - // TODO for all value types - if (valueType == STRING) addFunction("toString") { + addFunction("toString") { addModifiers(FINAL, OVERRIDE) returns() - addStatement("return \"%T($valueName=\$$valueName)\"", enumName) + addStatement("return \"%T.\${this::class.simpleName}($valueName=\$$valueName)\"", enumName) } From 735c464629a08544b984ea641224384dff173790 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 22:44:04 +0200 Subject: [PATCH 41/47] Put `KordEnumProcessorProvider` and `KordEnumProcessor` into same file --- .../src/main/kotlin/kordenum/KordEnumProcessor.kt | 11 +++++++---- .../main/kotlin/kordenum/KordEnumProcessorProvider.kt | 10 ---------- 2 files changed, 7 insertions(+), 14 deletions(-) delete mode 100644 ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt index 302cbf812eaf..a5c5f4a8489a 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessor.kt @@ -1,9 +1,6 @@ package dev.kord.ksp.kordenum -import com.google.devtools.ksp.processing.CodeGenerator -import com.google.devtools.ksp.processing.KSPLogger -import com.google.devtools.ksp.processing.Resolver -import com.google.devtools.ksp.processing.SymbolProcessor +import com.google.devtools.ksp.processing.* import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSFile import com.squareup.kotlinpoet.ksp.writeTo @@ -11,6 +8,12 @@ import dev.kord.ksp.GenerateKordEnum import dev.kord.ksp.getSymbolsWithAnnotation import dev.kord.ksp.isOfType +/** [SymbolProcessorProvider] for [KordEnumProcessor]. */ +class KordEnumProcessorProvider : SymbolProcessorProvider { + override fun create(environment: SymbolProcessorEnvironment) = + KordEnumProcessor(environment.codeGenerator, environment.logger) +} + /** [SymbolProcessor] for [GenerateKordEnum] annotation. */ class KordEnumProcessor(private val codeGenerator: CodeGenerator, private val logger: KSPLogger) : SymbolProcessor { diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt deleted file mode 100644 index d72dc4c91ec6..000000000000 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumProcessorProvider.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.kord.ksp.kordenum - -import com.google.devtools.ksp.processing.SymbolProcessorEnvironment -import com.google.devtools.ksp.processing.SymbolProcessorProvider - -/** [SymbolProcessorProvider] for [KordEnumProcessor]. */ -class KordEnumProcessorProvider : SymbolProcessorProvider { - override fun create(environment: SymbolProcessorEnvironment) = - KordEnumProcessor(environment.codeGenerator, environment.logger) -} From bb7bf54095424ec4cd1f04b1150345c24c316cbf Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Sun, 11 Sep 2022 23:03:42 +0200 Subject: [PATCH 42/47] Suppress "SpellCheckingInspection" and "GrazieInspection" in generated files --- .../dev/kord/common/entity/AllowedMentionType.kt | 2 +- .../kord/common/entity/ApplicationCommandOptionType.kt | 2 +- .../common/entity/ApplicationCommandPermissionType.kt | 2 +- .../dev/kord/common/entity/ApplicationCommandType.kt | 2 +- .../kotlin/dev/kord/common/entity/AuditLogEvent.kt | 2 +- .../dev/kord/common/entity/AutoModerationActionType.kt | 2 +- .../kord/common/entity/AutoModerationRuleEventType.kt | 2 +- .../entity/AutoModerationRuleKeywordPresetType.kt | 2 +- .../common/entity/AutoModerationRuleTriggerType.kt | 2 +- .../main/kotlin/dev/kord/common/entity/ButtonStyle.kt | 2 +- .../main/kotlin/dev/kord/common/entity/ChannelType.kt | 2 +- .../kotlin/dev/kord/common/entity/ComponentType.kt | 2 +- .../common/entity/DefaultMessageNotificationLevel.kt | 2 +- .../kord/common/entity/DiscordConnectionVisibility.kt | 2 +- .../dev/kord/common/entity/ExplicitContentFilter.kt | 2 +- .../main/kotlin/dev/kord/common/entity/GuildFeature.kt | 2 +- .../common/entity/GuildScheduledEventPrivacyLevel.kt | 2 +- .../kord/common/entity/GuildScheduledEventStatus.kt | 2 +- .../kord/common/entity/IntegrationExpireBehavior.kt | 2 +- .../dev/kord/common/entity/InteractionResponseType.kt | 2 +- .../kotlin/dev/kord/common/entity/InteractionType.kt | 2 +- .../kotlin/dev/kord/common/entity/InviteTargetType.kt | 2 +- .../ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt | 2 +- .../dev/kord/common/entity/MessageActivityType.kt | 2 +- .../dev/kord/common/entity/MessageStickerType.kt | 2 +- .../main/kotlin/dev/kord/common/entity/MessageType.kt | 2 +- .../main/kotlin/dev/kord/common/entity/NsfwLevel.kt | 2 +- .../kotlin/dev/kord/common/entity/OverwriteType.kt | 2 +- .../main/kotlin/dev/kord/common/entity/PremiumTier.kt | 2 +- .../kotlin/dev/kord/common/entity/PresenceStatus.kt | 2 +- .../dev/kord/common/entity/ScheduledEntityType.kt | 2 +- .../kord/common/entity/StageInstancePrivacyLevel.kt | 2 +- .../dev/kord/common/entity/TeamMembershipState.kt | 2 +- .../kotlin/dev/kord/common/entity/TextInputStyle.kt | 2 +- .../main/kotlin/dev/kord/common/entity/UserPremium.kt | 2 +- .../kotlin/dev/kord/common/entity/VerificationLevel.kt | 2 +- .../kotlin/dev/kord/common/entity/VideoQualityMode.kt | 2 +- .../main/kotlin/dev/kord/common/entity/WebhookType.kt | 2 +- .../src/main/kotlin/kordenum/KordEnumGeneration.kt | 10 +++++++++- 39 files changed, 47 insertions(+), 39 deletions(-) diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt index 96eef8aa35e7..9444bf04a17e 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt index f014e6068098..80b8a0b512ab 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt index 9d2dbfe69583..1ada4720569f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt index 685f60723c17..37981d208b38 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt index 162324a9c685..914c757cdd6e 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt index b42ac56ec7e6..6c7e53dbf22d 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt index 7e460f92313f..1ea70be3ae37 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt index 5d4463007ecd..88a8455c8a68 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt index a4b1216b0910..0c26ad5c358d 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt index 7f094e3503af..e66fc7189233 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index 11c7ffa4d3af..d074458e74c9 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt index d0f04f6a115c..84293de1b7c2 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt index 483b74ac8d53..a287b2e04e57 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt index 61bdba217498..9f3ced503135 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt index fef52679aea8..ac577ae1076f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt index fd08f6b69946..5f1706bdd844 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt index feaeef468fda..4ad664fc599b 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt index 0958614c9533..d70c2f5b471e 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt index e56ea3f085cc..f79b2a23bce7 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt index 7076e2a4f9c6..02fa12031064 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt index 46e08fd375bf..88e28dad8b61 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt index 520d1f513f8a..be77361c0b9b 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt index 13450afcc487..92c66643237c 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt index c8903a799fc8..a1d9089faa66 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt index baa8a0cd7b35..c691c259b3af 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt index d8a1c5459c8f..4494915aae7d 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt index dc6e17e35b2a..73215f348075 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt index 1db406385cd3..f7e0127396d2 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt index e2e132959932..acef3deecc09 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt index bcf84ab5235e..affbd758b02a 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt index 6899c6a7330f..42973bdd9644 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt index dafcc50ea63c..cbfc7fcfbd1f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt index c98a9eede906..5503b58491a8 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt index b5ee1e06f1ee..341ba2522066 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt index 2acf9b798556..f0e9822728f8 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt index cb2ed7d597ad..fdfc17d949a7 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt index 2b9255e92a7a..123064db848b 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt index fb3458b94a13..d157048b1355 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! @file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", - "ReplaceArrayOfWithLiteral")) + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) package dev.kord.common.entity diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index f7d65a6c57b9..ccbd581d0441 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -99,7 +99,15 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addFileComment("THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT!") @OptIn(DelicateKotlinPoetApi::class) // `AnnotationSpec.get` is ok for `Suppress` - addAnnotation(Suppress("RedundantVisibilityModifier", "IncorrectFormatting", "ReplaceArrayOfWithLiteral")) + addAnnotation( + Suppress( + "RedundantVisibilityModifier", + "IncorrectFormatting", + "ReplaceArrayOfWithLiteral", + "SpellCheckingInspection", + "GrazieInspection", + ) + ) addClass(enumName) { From 100e9be0db25e85d1465ebd35b32809f664d0785 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Mon, 12 Sep 2022 00:33:10 +0200 Subject: [PATCH 43/47] Add KDoc for `entries` and `value` --- .../kord/common/entity/AllowedMentionType.kt | 6 ++++ .../entity/ApplicationCommandOptionType.kt | 6 ++++ .../ApplicationCommandPermissionType.kt | 6 ++++ .../common/entity/ApplicationCommandType.kt | 6 ++++ .../dev/kord/common/entity/AuditLogEvent.kt | 10 ++++-- .../common/entity/AutoModerationActionType.kt | 6 ++++ .../entity/AutoModerationRuleEventType.kt | 6 ++++ .../AutoModerationRuleKeywordPresetType.kt | 6 ++++ .../entity/AutoModerationRuleTriggerType.kt | 6 ++++ .../dev/kord/common/entity/ButtonStyle.kt | 6 ++++ .../dev/kord/common/entity/ChannelType.kt | 9 ++++-- .../dev/kord/common/entity/ComponentType.kt | 6 ++++ .../entity/DefaultMessageNotificationLevel.kt | 6 ++++ .../entity/DiscordConnectionVisibility.kt | 6 ++++ .../common/entity/ExplicitContentFilter.kt | 6 ++++ .../dev/kord/common/entity/GuildFeature.kt | 6 ++++ .../entity/GuildScheduledEventPrivacyLevel.kt | 6 ++++ .../entity/GuildScheduledEventStatus.kt | 6 ++++ .../entity/IntegrationExpireBehavior.kt | 6 ++++ .../common/entity/InteractionResponseType.kt | 8 ++++- .../dev/kord/common/entity/InteractionType.kt | 6 ++++ .../kord/common/entity/InviteTargetType.kt | 6 ++++ .../kotlin/dev/kord/common/entity/MFALevel.kt | 6 ++++ .../kord/common/entity/MessageActivityType.kt | 6 ++++ .../kord/common/entity/MessageStickerType.kt | 6 ++++ .../dev/kord/common/entity/MessageType.kt | 6 ++++ .../dev/kord/common/entity/NsfwLevel.kt | 6 ++++ .../dev/kord/common/entity/OverwriteType.kt | 6 ++++ .../dev/kord/common/entity/PremiumTier.kt | 6 ++++ .../dev/kord/common/entity/PresenceStatus.kt | 6 ++++ .../kord/common/entity/ScheduledEntityType.kt | 6 ++++ .../entity/StageInstancePrivacyLevel.kt | 6 ++++ .../kord/common/entity/TeamMembershipState.kt | 6 ++++ .../dev/kord/common/entity/TextInputStyle.kt | 8 ++++- .../dev/kord/common/entity/UserPremium.kt | 6 ++++ .../kord/common/entity/VerificationLevel.kt | 6 ++++ .../kord/common/entity/VideoQualityMode.kt | 6 ++++ .../dev/kord/common/entity/WebhookType.kt | 6 ++++ common/src/main/kotlin/entity/AuditLog.kt | 4 +-- .../src/main/kotlin/entity/DiscordChannel.kt | 31 ++++++------------- .../main/kotlin/entity/DiscordComponent.kt | 6 ++-- common/src/main/kotlin/entity/Interactions.kt | 2 +- .../kotlin/kordenum/KordEnumGeneration.kt | 2 ++ 43 files changed, 251 insertions(+), 33 deletions(-) diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt index 9444bf04a17e..2feddd0df80f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AllowedMentionType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = AllowedMentionType.Serializer::class) public sealed class AllowedMentionType( + /** + * The raw value used by Discord. + */ public val `value`: String, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -73,6 +76,9 @@ public sealed class AllowedMentionType( } public companion object { + /** + * A [List] of all known [AllowedMentionType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( EveryoneMentions, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt index 80b8a0b512ab..49838edd4625 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandOptionType.kt @@ -19,6 +19,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = ApplicationCommandOptionType.Serializer::class) public sealed class ApplicationCommandOptionType( + /** + * The raw type used by Discord. + */ public val type: Int, ) { public final override fun equals(other: Any?): kotlin.Boolean = this === other || @@ -98,6 +101,9 @@ public sealed class ApplicationCommandOptionType( } public companion object { + /** + * A [List] of all known [ApplicationCommandOptionType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( SubCommand, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt index 1ada4720569f..389e729f9c8b 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandPermissionType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = ApplicationCommandPermissionType.Serializer::class) public sealed class ApplicationCommandPermissionType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -64,6 +67,9 @@ public sealed class ApplicationCommandPermissionType( } public companion object { + /** + * A [List] of all known [ApplicationCommandPermissionType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Role, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt index 37981d208b38..f4873233bcd8 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ApplicationCommandType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = ApplicationCommandType.Serializer::class) public sealed class ApplicationCommandType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -72,6 +75,9 @@ public sealed class ApplicationCommandType( } public companion object { + /** + * A [List] of all known [ApplicationCommandType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( ChatInput, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt index 914c757cdd6e..e0062d9919d5 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AuditLogEvent.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = AuditLogEvent.Serializer::class) public sealed class AuditLogEvent( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -51,7 +54,7 @@ public sealed class AuditLogEvent( public object ChannelCreate : AuditLogEvent(10) /** - * Channel settings were updated + * Channel settings were updated. */ public object ChannelUpdate : AuditLogEvent(11) @@ -191,7 +194,7 @@ public sealed class AuditLogEvent( public object MessageBulkDelete : AuditLogEvent(73) /** - * Message was pinned to a channel + * Message was pinned to a channel. */ public object MessagePin : AuditLogEvent(74) @@ -365,6 +368,9 @@ public sealed class AuditLogEvent( } public companion object { + /** + * A [List] of all known [AuditLogEvent]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( GuildUpdate, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt index 6c7e53dbf22d..4bea21c6f84f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationActionType.kt @@ -24,6 +24,9 @@ import kotlinx.serialization.encoding.Encoder */ @Serializable(with = AutoModerationActionType.Serializer::class) public sealed class AutoModerationActionType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -82,6 +85,9 @@ public sealed class AutoModerationActionType( } public companion object { + /** + * A [List] of all known [AutoModerationActionType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( BlockMessage, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt index 1ea70be3ae37..88ae933669d8 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleEventType.kt @@ -24,6 +24,9 @@ import kotlinx.serialization.encoding.Encoder */ @Serializable(with = AutoModerationRuleEventType.Serializer::class) public sealed class AutoModerationRuleEventType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -64,6 +67,9 @@ public sealed class AutoModerationRuleEventType( } public companion object { + /** + * A [List] of all known [AutoModerationRuleEventType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( MessageSend, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt index 88a8455c8a68..00009f875466 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleKeywordPresetType.kt @@ -24,6 +24,9 @@ import kotlinx.serialization.encoding.Encoder */ @Serializable(with = AutoModerationRuleKeywordPresetType.Serializer::class) public sealed class AutoModerationRuleKeywordPresetType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -76,6 +79,9 @@ public sealed class AutoModerationRuleKeywordPresetType( } public companion object { + /** + * A [List] of all known [AutoModerationRuleKeywordPresetType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Profanity, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt index 0c26ad5c358d..241a44984a57 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/AutoModerationRuleTriggerType.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder */ @Serializable(with = AutoModerationRuleTriggerType.Serializer::class) public sealed class AutoModerationRuleTriggerType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -91,6 +94,9 @@ public sealed class AutoModerationRuleTriggerType( } public companion object { + /** + * A [List] of all known [AutoModerationRuleTriggerType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Keyword, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt index e66fc7189233..25694f3a4056 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ButtonStyle.kt @@ -31,6 +31,9 @@ import kotlinx.serialization.encoding.Encoder */ @Serializable(with = ButtonStyle.NewSerializer::class) public sealed class ButtonStyle( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -107,6 +110,9 @@ public sealed class ButtonStyle( } public companion object { + /** + * A [List] of all known [ButtonStyle]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Primary, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt index d074458e74c9..d5880fa1e184 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ChannelType.kt @@ -23,6 +23,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = ChannelType.Serializer::class) public sealed class ChannelType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -87,8 +90,7 @@ public sealed class ChannelType( /** * A temporary sub-channel within a [GuildText] channel that is only viewable by those invited - * and those with - * the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission. + * and those with the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission. */ public object PrivateThread : ChannelType(12) @@ -142,6 +144,9 @@ public sealed class ChannelType( } public companion object { + /** + * A [List] of all known [ChannelType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( GuildText, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt index 84293de1b7c2..26eecbabcda1 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ComponentType.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = ComponentType.NewSerializer::class) public sealed class ComponentType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -95,6 +98,9 @@ public sealed class ComponentType( } public companion object { + /** + * A [List] of all known [ComponentType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( ActionRow, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt index a287b2e04e57..c94b50eda964 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DefaultMessageNotificationLevel.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = DefaultMessageNotificationLevel.Serializer::class) public sealed class DefaultMessageNotificationLevel( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -67,6 +70,9 @@ public sealed class DefaultMessageNotificationLevel( } public companion object { + /** + * A [List] of all known [DefaultMessageNotificationLevel]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( AllMessages, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt index 9f3ced503135..1645f0e18fb1 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/DiscordConnectionVisibility.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = DiscordConnectionVisibility.Serializer::class) public sealed class DiscordConnectionVisibility( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -67,6 +70,9 @@ public sealed class DiscordConnectionVisibility( } public companion object { + /** + * A [List] of all known [DiscordConnectionVisibility]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( None, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt index ac577ae1076f..aabaa5d1d001 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ExplicitContentFilter.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = ExplicitContentFilter.Serializer::class) public sealed class ExplicitContentFilter( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -72,6 +75,9 @@ public sealed class ExplicitContentFilter( } public companion object { + /** + * A [List] of all known [ExplicitContentFilter]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Disabled, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt index 5f1706bdd844..00acd7d5d57e 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildFeature.kt @@ -22,6 +22,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = GuildFeature.Serializer::class) public sealed class GuildFeature( + /** + * The raw value used by Discord. + */ public val `value`: String, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -207,6 +210,9 @@ public sealed class GuildFeature( } public companion object { + /** + * A [List] of all known [GuildFeature]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( AnimatedBanner, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt index 4ad664fc599b..d82a3c345bda 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventPrivacyLevel.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = GuildScheduledEventPrivacyLevel.Serializer::class) public sealed class GuildScheduledEventPrivacyLevel( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -61,6 +64,9 @@ public sealed class GuildScheduledEventPrivacyLevel( } public companion object { + /** + * A [List] of all known [GuildScheduledEventPrivacyLevel]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( GuildOnly, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt index d70c2f5b471e..facf2fc8afcc 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/GuildScheduledEventStatus.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = GuildScheduledEventStatus.NewSerializer::class) public sealed class GuildScheduledEventStatus( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -85,6 +88,9 @@ public sealed class GuildScheduledEventStatus( } public companion object { + /** + * A [List] of all known [GuildScheduledEventStatus]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Scheduled, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt index f79b2a23bce7..d265b7936470 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/IntegrationExpireBehavior.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = IntegrationExpireBehavior.NewSerializer::class) public sealed class IntegrationExpireBehavior( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -79,6 +82,9 @@ public sealed class IntegrationExpireBehavior( } public companion object { + /** + * A [List] of all known [IntegrationExpireBehavior]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( RemoveRole, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt index 02fa12031064..7b3caee4b911 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionResponseType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = InteractionResponseType.Serializer::class) public sealed class InteractionResponseType( + /** + * The raw type used by Discord. + */ public val type: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -42,7 +45,7 @@ public sealed class InteractionResponseType( ) : InteractionResponseType(type) /** - * ACK a [Ping][dev.kord.common.entity.InteractionType.Ping] + * ACK a [Ping][dev.kord.common.entity.InteractionType.Ping]. */ public object Pong : InteractionResponseType(1) @@ -98,6 +101,9 @@ public sealed class InteractionResponseType( } public companion object { + /** + * A [List] of all known [InteractionResponseType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Pong, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt index 88e28dad8b61..cd00f7b34afb 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InteractionType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = InteractionType.Serializer::class) public sealed class InteractionType( + /** + * The raw type used by Discord. + */ public val type: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -69,6 +72,9 @@ public sealed class InteractionType( } public companion object { + /** + * A [List] of all known [InteractionType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Ping, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt index be77361c0b9b..38347da753f2 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/InviteTargetType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = InviteTargetType.Serializer::class) public sealed class InviteTargetType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -60,6 +63,9 @@ public sealed class InviteTargetType( } public companion object { + /** + * A [List] of all known [InviteTargetType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Stream, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt index 92c66643237c..4a481c372f63 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MFALevel.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = MFALevel.Serializer::class) public sealed class MFALevel( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -65,6 +68,9 @@ public sealed class MFALevel( } public companion object { + /** + * A [List] of all known [MFALevel]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( None, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt index a1d9089faa66..9447811be291 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageActivityType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = MessageActivityType.Serializer::class) public sealed class MessageActivityType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -66,6 +69,9 @@ public sealed class MessageActivityType( } public companion object { + /** + * A [List] of all known [MessageActivityType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Join, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt index c691c259b3af..72e6d25e624e 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageStickerType.kt @@ -24,6 +24,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = MessageStickerType.Serializer::class) public sealed class MessageStickerType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -66,6 +69,9 @@ public sealed class MessageStickerType( } public companion object { + /** + * A [List] of all known [MessageStickerType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( PNG, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt index 4494915aae7d..db6c3049c82a 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/MessageType.kt @@ -24,6 +24,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = MessageType.Serializer::class) public sealed class MessageType( + /** + * The raw code used by Discord. + */ public val code: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -178,6 +181,9 @@ public sealed class MessageType( } public companion object { + /** + * A [List] of all known [MessageType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Default, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt index 73215f348075..6b8241cad028 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/NsfwLevel.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = NsfwLevel.Serializer::class) public sealed class NsfwLevel( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -65,6 +68,9 @@ public sealed class NsfwLevel( } public companion object { + /** + * A [List] of all known [NsfwLevel]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Default, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt index f7e0127396d2..1fb5d6485b6a 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/OverwriteType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = OverwriteType.Serializer::class) public sealed class OverwriteType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -59,6 +62,9 @@ public sealed class OverwriteType( } public companion object { + /** + * A [List] of all known [OverwriteType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Role, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt index acef3deecc09..3cecba0ea8d9 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PremiumTier.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = PremiumTier.Serializer::class) public sealed class PremiumTier( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -77,6 +80,9 @@ public sealed class PremiumTier( } public companion object { + /** + * A [List] of all known [PremiumTier]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( None, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt index affbd758b02a..27fa0e83b06c 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/PresenceStatus.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = PresenceStatus.Serializer::class) public sealed class PresenceStatus( + /** + * The raw value used by Discord. + */ public val `value`: String, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -103,6 +106,9 @@ public sealed class PresenceStatus( } public companion object { + /** + * A [List] of all known [PresenceStatus]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( DoNotDisturb, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt index 42973bdd9644..d2401a610806 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/ScheduledEntityType.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = ScheduledEntityType.NewSerializer::class) public sealed class ScheduledEntityType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -81,6 +84,9 @@ public sealed class ScheduledEntityType( } public companion object { + /** + * A [List] of all known [ScheduledEntityType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( StageInstance, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt index cbfc7fcfbd1f..9c652f0d9284 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/StageInstancePrivacyLevel.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = StageInstancePrivacyLevel.NewSerializer::class) public sealed class StageInstancePrivacyLevel( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -86,6 +89,9 @@ public sealed class StageInstancePrivacyLevel( } public companion object { + /** + * A [List] of all known [StageInstancePrivacyLevel]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( @Suppress("DEPRECATION") Public, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt index 5503b58491a8..5447a0b0e01b 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TeamMembershipState.kt @@ -25,6 +25,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = TeamMembershipState.Serializer::class) public sealed class TeamMembershipState( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -78,6 +81,9 @@ public sealed class TeamMembershipState( } public companion object { + /** + * A [List] of all known [TeamMembershipState]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Invited, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt index 341ba2522066..c02f7d955acf 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/TextInputStyle.kt @@ -20,10 +20,13 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder /** - * Style of a [text input][dev.kord.common.entity.ComponentType.TextInput] + * Style of a [text input][dev.kord.common.entity.ComponentType.TextInput]. */ @Serializable(with = TextInputStyle.Serializer::class) public sealed class TextInputStyle( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -69,6 +72,9 @@ public sealed class TextInputStyle( } public companion object { + /** + * A [List] of all known [TextInputStyle]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Short, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt index f0e9822728f8..858567d6f134 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/UserPremium.kt @@ -24,6 +24,9 @@ import kotlinx.serialization.encoding.Encoder */ @Serializable(with = UserPremium.Serializer::class) public sealed class UserPremium( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -65,6 +68,9 @@ public sealed class UserPremium( } public companion object { + /** + * A [List] of all known [UserPremium]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( None, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt index fdfc17d949a7..c8d45ed6d162 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VerificationLevel.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = VerificationLevel.Serializer::class) public sealed class VerificationLevel( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -84,6 +87,9 @@ public sealed class VerificationLevel( } public companion object { + /** + * A [List] of all known [VerificationLevel]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( None, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt index 123064db848b..d395f3be386f 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/VideoQualityMode.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = VideoQualityMode.Serializer::class) public sealed class VideoQualityMode( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -66,6 +69,9 @@ public sealed class VideoQualityMode( } public companion object { + /** + * A [List] of all known [VideoQualityMode]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Auto, diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt index d157048b1355..211eeb857128 100644 --- a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/WebhookType.kt @@ -21,6 +21,9 @@ import kotlinx.serialization.encoding.Encoder @Serializable(with = WebhookType.Serializer::class) public sealed class WebhookType( + /** + * The raw value used by Discord. + */ public val `value`: Int, ) { public final override fun equals(other: Any?): Boolean = this === other || @@ -72,6 +75,9 @@ public sealed class WebhookType( } public companion object { + /** + * A [List] of all known [WebhookType]s. + */ public val entries: List by lazy(mode = PUBLICATION) { listOf( Incoming, diff --git a/common/src/main/kotlin/entity/AuditLog.kt b/common/src/main/kotlin/entity/AuditLog.kt index 2295f72d71d3..4a125a5777be 100644 --- a/common/src/main/kotlin/entity/AuditLog.kt +++ b/common/src/main/kotlin/entity/AuditLog.kt @@ -3,7 +3,7 @@ entries = [ Entry("GuildUpdate", intValue = 1, kDoc = "Server settings were updated."), Entry("ChannelCreate", intValue = 10, kDoc = "Channel was created."), - Entry("ChannelUpdate", intValue = 11, kDoc = "Channel settings were updated"), + Entry("ChannelUpdate", intValue = 11, kDoc = "Channel settings were updated."), Entry("ChannelDelete", intValue = 12, kDoc = "Channel was deleted."), Entry("ChannelOverwriteCreate", intValue = 13, kDoc = "Permission overwrite was added to a channel."), Entry("ChannelOverwriteUpdate", intValue = 14, kDoc = "Permission overwrite was updated for a channel."), @@ -31,7 +31,7 @@ Entry("EmojiDelete", intValue = 62, kDoc = "Emoji was deleted."), Entry("MessageDelete", intValue = 72, kDoc = "Single message was deleted."), Entry("MessageBulkDelete", intValue = 73, kDoc = "Multiple messages were deleted."), - Entry("MessagePin", intValue = 74, kDoc = "Message was pinned to a channel"), + Entry("MessagePin", intValue = 74, kDoc = "Message was pinned to a channel."), Entry("MessageUnpin", intValue = 75, kDoc = "Message was unpinned from a channel."), Entry("IntegrationCreate", intValue = 80, kDoc = "App was added to server."), Entry("IntegrationUpdate", intValue = 81, kDoc = "App was updated (as an example, its scopes were updated)."), diff --git a/common/src/main/kotlin/entity/DiscordChannel.kt b/common/src/main/kotlin/entity/DiscordChannel.kt index 0bd43fd54faa..5916fcc59f52 100644 --- a/common/src/main/kotlin/entity/DiscordChannel.kt +++ b/common/src/main/kotlin/entity/DiscordChannel.kt @@ -7,41 +7,30 @@ Entry("GroupDM", intValue = 3, kDoc = "A direct message between multiple users."), Entry( "GuildCategory", intValue = 4, - kDoc = """ - An - [organizational·category](https://support.discord.com/hc/en-us/articles/115001580171-Channel-Categories-101) - that contains up to 50 channels. - """, + kDoc = "An [organizational·category](https://support.discord.com/hc/en-us/articles/115001580171-Channel-" + + "Categories-101) that contains up to 50 channels.", ), Entry( "GuildNews", intValue = 5, - kDoc = """ - A channel that - [users·can·follow·and·crosspost·into·their·own·server](https://support.discord.com/hc/en-us/articles/360032008192). - """, + kDoc = "A channel that [users·can·follow·and·crosspost·into·their·own·server]" + + "(https://support.discord.com/hc/en-us/articles/360032008192).", ), Entry("PublicNewsThread", intValue = 10, kDoc = "A temporary sub-channel within a [GuildNews] channel."), Entry("PublicGuildThread", intValue = 11, kDoc = "A temporary sub-channel within a [GuildText] channel."), Entry( "PrivateThread", intValue = 12, - kDoc = """ - A temporary sub-channel within a [GuildText] channel that is only viewable by those invited and those with - the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission. - """, + kDoc = "A temporary sub-channel within a [GuildText] channel that is only viewable by those invited and " + + "those with the [ManageThreads][dev.kord.common.entity.Permission.ManageThreads] permission.", ), Entry( "GuildStageVoice", intValue = 13, - kDoc = """ - A voice channel for - [hosting·events·with·an·audience](https://support.discord.com/hc/en-us/articles/1500005513722). - """, + kDoc = "A voice channel for [hosting·events·with·an·audience]" + + "(https://support.discord.com/hc/en-us/articles/1500005513722).", ), Entry( "GuildDirectory", intValue = 14, - kDoc = """ - The channel in a [hub](https://support.discord.com/hc/en-us/articles/4406046651927-Discord-Student-Hubs-FAQ) - containing the listed servers. - """, + kDoc = "The channel in a [hub](https://support.discord.com/hc/en-us/articles/4406046651927-Discord-" + + "Student-Hubs-FAQ) containing the listed servers.", ), ], deprecatedEntries = [ diff --git a/common/src/main/kotlin/entity/DiscordComponent.kt b/common/src/main/kotlin/entity/DiscordComponent.kt index f81690468939..6b608d6b0f05 100644 --- a/common/src/main/kotlin/entity/DiscordComponent.kt +++ b/common/src/main/kotlin/entity/DiscordComponent.kt @@ -13,8 +13,8 @@ name = "ButtonStyle", valueType = INT, deprecatedSerializerName = "Serializer", kDoc = "Style of a [button][dev.kord.common.entity.ComponentType.Button].\n\nA preview of the different styles " + - "can be found " + - "[here](https://discord.com/developers/docs/interactions/message-components#button-object-button-styles).", + "can be found [here]" + + "(https://discord.com/developers/docs/interactions/message-components#button-object-button-styles).", entries = [ Entry("Primary", intValue = 1, kDoc = "Blurple."), Entry("Secondary", intValue = 2, kDoc = "Grey."), @@ -26,7 +26,7 @@ @file:GenerateKordEnum( name = "TextInputStyle", valueType = INT, - kDoc = "Style of a [text·input][dev.kord.common.entity.ComponentType.TextInput]", + kDoc = "Style of a [text·input][dev.kord.common.entity.ComponentType.TextInput].", entries = [ Entry("Short", intValue = 1, kDoc = "A single-line input."), Entry("Paragraph", intValue = 2, kDoc = "A multi-line input."), diff --git a/common/src/main/kotlin/entity/Interactions.kt b/common/src/main/kotlin/entity/Interactions.kt index ee45e8cc5c59..33377dad2c83 100644 --- a/common/src/main/kotlin/entity/Interactions.kt +++ b/common/src/main/kotlin/entity/Interactions.kt @@ -41,7 +41,7 @@ @file:GenerateKordEnum( name = "InteractionResponseType", valueType = INT, valueName = "type", entries = [ - Entry("Pong", intValue = 1, kDoc = "ACK a [Ping][dev.kord.common.entity.InteractionType.Ping]"), + Entry("Pong", intValue = 1, kDoc = "ACK a [Ping][dev.kord.common.entity.InteractionType.Ping]."), Entry("ChannelMessageWithSource", intValue = 4, kDoc = "Respond to an interaction with a message."), Entry( "DeferredChannelMessageWithSource", intValue = 5, diff --git a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt index ccbd581d0441..5ee7a5317579 100644 --- a/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt +++ b/ksp-processors/src/main/kotlin/kordenum/KordEnumGeneration.kt @@ -123,6 +123,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addParameter(valueName, valueTypeName) } addProperty(valueName, valueTypeName, PUBLIC) { + addKdoc("The raw $valueName used by Discord.") initializer(valueName) } @@ -246,6 +247,7 @@ internal fun KordEnum.generateFileSpec(originatingFile: KSFile): FileSpec { addModifiers(PUBLIC) addProperty("entries", LIST.parameterizedBy(enumName), PUBLIC) { + addKdoc("A [List] of all known [%T]s.", enumName) delegate { withControlFlow("lazy(mode·=·%M)", PUBLICATION.asMemberName()) { addStatement("listOf(") From 1d7fb28dec46344275084ee51a563ecf6429946b Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Mon, 12 Sep 2022 04:13:15 +0200 Subject: [PATCH 44/47] Generate `EmbedType` --- common/api/common.api | 4 + .../dev/kord/common/entity/EmbedType.kt | 111 ++++++++++++++++++ .../src/main/kotlin/entity/DiscordMessage.kt | 71 ++--------- core/src/main/kotlin/cache/data/EmbedData.kt | 3 - core/src/main/kotlin/entity/Embed.kt | 17 +-- 5 files changed, 129 insertions(+), 77 deletions(-) create mode 100644 common/build/generated/ksp/main/kotlin/dev/kord/common/entity/EmbedType.kt diff --git a/common/api/common.api b/common/api/common.api index 0c746e165db2..0ecb3db2fb60 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -6043,7 +6043,10 @@ public final class dev/kord/common/entity/DiscordWelcomeScreenChannel$Companion public abstract class dev/kord/common/entity/EmbedType { public static final field Companion Ldev/kord/common/entity/EmbedType$Companion; public synthetic fun (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun equals (Ljava/lang/Object;)Z public final fun getValue ()Ljava/lang/String; + public final fun hashCode ()I + public final fun toString ()Ljava/lang/String; } public final class dev/kord/common/entity/EmbedType$Article : dev/kord/common/entity/EmbedType { @@ -6051,6 +6054,7 @@ public final class dev/kord/common/entity/EmbedType$Article : dev/kord/common/en } public final class dev/kord/common/entity/EmbedType$Companion { + public final fun getEntries ()Ljava/util/List; public final fun serializer ()Lkotlinx/serialization/KSerializer; } diff --git a/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/EmbedType.kt b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/EmbedType.kt new file mode 100644 index 000000000000..9b469bbbde8c --- /dev/null +++ b/common/build/generated/ksp/main/kotlin/dev/kord/common/entity/EmbedType.kt @@ -0,0 +1,111 @@ +// THIS FILE IS AUTO-GENERATED BY KordEnumProcessor.kt, DO NOT EDIT! +@file:Suppress(names = arrayOf("RedundantVisibilityModifier", "IncorrectFormatting", + "ReplaceArrayOfWithLiteral", "SpellCheckingInspection", "GrazieInspection")) + +package dev.kord.common.entity + +import kotlin.Any +import kotlin.Boolean +import kotlin.Int +import kotlin.LazyThreadSafetyMode.PUBLICATION +import kotlin.String +import kotlin.Suppress +import kotlin.collections.List +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable(with = EmbedType.Serializer::class) +public sealed class EmbedType( + /** + * The raw value used by Discord. + */ + public val `value`: String, +) { + public final override fun equals(other: Any?): Boolean = this === other || + (other is EmbedType && this.value == other.value) + + public final override fun hashCode(): Int = value.hashCode() + + public final override fun toString(): String = + "EmbedType.${this::class.simpleName}(value=$value)" + + /** + * An unknown [EmbedType]. + * + * This is used as a fallback for [EmbedType]s that haven't been added to Kord yet. + */ + public class Unknown( + `value`: String, + ) : EmbedType(value) + + /** + * Generic embed rendered from embed attributes. + */ + public object Rich : EmbedType("rich") + + /** + * Image embed. + */ + public object Image : EmbedType("image") + + /** + * Video embed. + */ + public object Video : EmbedType("video") + + /** + * Animated gif image embed rendered as a video embed. + */ + public object Gifv : EmbedType("gifv") + + /** + * Article embed. + */ + public object Article : EmbedType("article") + + /** + * Link embed. + */ + public object Link : EmbedType("link") + + internal object Serializer : KSerializer { + public override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("dev.kord.common.entity.EmbedType", PrimitiveKind.STRING) + + public override fun serialize(encoder: Encoder, `value`: EmbedType) = + encoder.encodeString(value.value) + + public override fun deserialize(decoder: Decoder) = + when (val value = decoder.decodeString()) { + "article" -> Article + "gifv" -> Gifv + "image" -> Image + "link" -> Link + "rich" -> Rich + "video" -> Video + else -> Unknown(value) + } + } + + public companion object { + /** + * A [List] of all known [EmbedType]s. + */ + public val entries: List by lazy(mode = PUBLICATION) { + listOf( + Article, + Gifv, + Image, + Link, + Rich, + Video, + ) + } + + } +} diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index 82d5ac0a289e..ee372b9ea997 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -67,6 +67,18 @@ ], ) +@file:GenerateKordEnum( + name = "EmbedType", valueType = STRING, + entries = [ + Entry("Rich", stringValue = "rich", kDoc = "Generic embed rendered from embed attributes."), + Entry("Image", stringValue = "image", kDoc = "Image embed."), + Entry("Video", stringValue = "video", kDoc = "Video embed."), + Entry("Gifv", stringValue = "gifv", kDoc = "Animated gif image embed rendered as a video embed."), + Entry("Article", stringValue = "article", kDoc = "Article embed."), + Entry("Link", stringValue = "link", kDoc = "Link embed."), + ], +) + @file:GenerateKordEnum( name = "AllowedMentionType", valueType = STRING, entries = [ @@ -550,7 +562,6 @@ public data class DiscordAttachment( @Serializable public data class DiscordEmbed( val title: Optional = Optional.Missing(), - @Suppress("DEPRECATION") val type: Optional = Optional.Missing(), val description: Optional = Optional.Missing(), val url: Optional = Optional.Missing(), @@ -674,64 +685,6 @@ public data class DiscordEmbed( ) } -/** - * A representation of a [Discord Embed Type structure](https://discord.com/developers/docs/resources/channel#embed-object-embed-types). - * - * Embed types are "loosely defined" and, for the most part, are not used by our clients for rendering. - * Embed attributes power what is rendered. - * Embed types should be considered deprecated and might be removed in a future API version. - */ -@Suppress("DEPRECATION") -@Deprecated( - """ - Embed types are "loosely defined" and, for the most part, are not used by clients for rendering. - Embed attributes power what is rendered. - Embed types should be considered deprecated and might be removed in a future API version. -""" -) -@Serializable(with = EmbedType.Serializer::class) -public sealed class EmbedType(public val value: String) { - public class Unknown(value: String) : EmbedType(value) - - /** Generic embed rendered from embed attributes. */ - public object Rich : EmbedType("rich") - - /** Image embed. */ - public object Image : EmbedType("image") - - /** Video embed. */ - public object Video : EmbedType("video") - - /** Animated gif image embed rendered as a video embed. */ - public object Gifv : EmbedType("gifv") - - /** Article embed. */ - public object Article : EmbedType("article") - - /** Link embed. */ - public object Link : EmbedType("link") - - internal object Serializer : KSerializer { - override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("Kord.EmbedType", PrimitiveKind.STRING) - - override fun deserialize(decoder: Decoder): EmbedType = when (val value = decoder.decodeString()) { - "rich" -> Rich - "image" -> Image - "video" -> Video - "gifv" -> Gifv - "article" -> Article - "Link" -> Link - else -> Unknown(value) - } - - override fun serialize(encoder: Encoder, value: EmbedType) { - encoder.encodeString(value.value) - } - } - -} - @Serializable public data class Reaction( val count: Int, diff --git a/core/src/main/kotlin/cache/data/EmbedData.kt b/core/src/main/kotlin/cache/data/EmbedData.kt index 0fc8bfd20af5..1e93f427366f 100644 --- a/core/src/main/kotlin/cache/data/EmbedData.kt +++ b/core/src/main/kotlin/cache/data/EmbedData.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package dev.kord.core.cache.data import dev.kord.common.entity.DiscordEmbed @@ -11,7 +9,6 @@ import kotlinx.serialization.Serializable @Serializable public data class EmbedData( val title: Optional = Optional.Missing(), - @Suppress("DEPRECATION") val type: Optional = Optional.Missing(), val description: Optional = Optional.Missing(), val url: Optional = Optional.Missing(), diff --git a/core/src/main/kotlin/entity/Embed.kt b/core/src/main/kotlin/entity/Embed.kt index ea72af212843..d22a4a94a090 100644 --- a/core/src/main/kotlin/entity/Embed.kt +++ b/core/src/main/kotlin/entity/Embed.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package dev.kord.core.entity import dev.kord.common.Color @@ -12,12 +10,6 @@ import dev.kord.core.cache.data.* import dev.kord.rest.builder.message.EmbedBuilder import kotlinx.datetime.Instant -internal const val embedDeprecationMessage = """ -Embed types should be considered deprecated and might be removed in a future API version. - -https://discord.com/developers/docs/resources/channel#embed-object-embed-types -""" - /** * An instance of a [Discord Embed](https://discord.com/developers/docs/resources/channel#embed-object). */ @@ -28,13 +20,8 @@ public data class Embed(val data: EmbedData, override val kord: Kord) : KordObje */ public val title: String? get() = data.title.value - /* - * The type, [Embed.Type.Rich] for webhook and bot created embeds. Null if unknown. - */ - @Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION") - @Deprecated(embedDeprecationMessage) - val type: EmbedType? - get() = data.type.value + /** The type of embed, if present. Always [Rich][EmbedType.Rich] for webhook embeds. */ + val type: EmbedType? get() = data.type.value /** * The description, if present. From 56804bdf07aa8f80fb1f0ac181c07aa86d83e2f9 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Mon, 12 Sep 2022 07:20:54 +0200 Subject: [PATCH 45/47] Update dokka config --- .../src/main/kotlin/kord-module.gradle.kts | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 489309347f03..5fc0b1a5f2c7 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -58,8 +58,6 @@ tasks { useJUnitPlatform() } - val compileKotlin by existing - // configure both dokkaHtml and dokkaHtmlPartial tasks // (dokkaHtmlMultiModule depends on dokkaHtmlPartial, dokkaJar depends on dokkaHtml) withType { @@ -74,7 +72,8 @@ tasks { jdkVersion.set(Jvm.targetInt) - val baseRemoteUrl = "https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.8.x")}/${project.name}" + val baseRemoteUrl = + "https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.8.x")}/${project.name}" sourceLink { localDirectory.set(file("src/main/kotlin")) @@ -83,14 +82,12 @@ tasks { } // config for files generated by ksp - val kspSrc = file("build/generated/ksp/main/kotlin") - if (kspSrc.exists()) { - suppressGeneratedFiles.set(false) - sourceLink { - localDirectory.set(kspSrc) - remoteUrl.set(URL("$baseRemoteUrl/build/generated/ksp/main/kotlin/")) - remoteLineSuffix.set("#L") - } + 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/") @@ -110,8 +107,6 @@ tasks { from(sourceSets.main.get().allSource) } - val dokkaHtml by existing - val dokkaJar by registering(Jar::class) { group = JavaBasePlugin.DOCUMENTATION_GROUP description = "Assembles Kotlin docs with Dokka" From 4750273a9f08184943e17296dc021eabf7d2e256 Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Mon, 12 Sep 2022 07:37:45 +0200 Subject: [PATCH 46/47] Remove double slash in dokka source links --- buildSrc/src/main/kotlin/kord-module.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/kord-module.gradle.kts b/buildSrc/src/main/kotlin/kord-module.gradle.kts index 5fc0b1a5f2c7..62bdb6d48afb 100644 --- a/buildSrc/src/main/kotlin/kord-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-module.gradle.kts @@ -77,7 +77,7 @@ tasks { sourceLink { localDirectory.set(file("src/main/kotlin")) - remoteUrl.set(URL("$baseRemoteUrl/src/main/kotlin/")) + remoteUrl.set(URL("$baseRemoteUrl/src/main/kotlin")) remoteLineSuffix.set("#L") } @@ -86,7 +86,7 @@ tasks { 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/")) + remoteUrl.set(URL("$baseRemoteUrl/build/generated/ksp/main/kotlin")) remoteLineSuffix.set("#L") } From 48fe7069f956cd237727d21f98fcd7462682de6e Mon Sep 17 00:00:00 2001 From: Lukellmann Date: Tue, 13 Sep 2022 23:53:54 +0200 Subject: [PATCH 47/47] `SOURCE` retention for `@KotlinPoetDsl` --- ksp-processors/src/main/kotlin/KotlinPoetDsl.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt index 5047799f9826..8b4f4689ed7c 100644 --- a/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt +++ b/ksp-processors/src/main/kotlin/KotlinPoetDsl.kt @@ -2,10 +2,12 @@ package dev.kord.ksp import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.MemberName.Companion.member +import kotlin.annotation.AnnotationRetention.SOURCE import kotlin.annotation.AnnotationTarget.TYPE // for scope control, see https://kotlinlang.org/docs/type-safe-builders.html#scope-control-dslmarker @DslMarker +@Retention(SOURCE) @Target(TYPE) internal annotation class KotlinPoetDsl