-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e81dc5
commit 3ecaf4e
Showing
4 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
...nMain/kotlin/dev/kord/common/entity/DiscordApplicationRoleConnectionMetadataRecordType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// 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 | ||
|
||
/** | ||
* Type of [DiscordRoleConnectionMetadata] values | ||
* | ||
* See [DiscordApplicationRoleConnectionMetadataRecordType]s in the | ||
* [Discord Developer Documentation](https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type). | ||
*/ | ||
@Serializable(with = DiscordApplicationRoleConnectionMetadataRecordType.Serializer::class) | ||
public sealed class DiscordApplicationRoleConnectionMetadataRecordType( | ||
/** | ||
* The raw value used by Discord. | ||
*/ | ||
public val `value`: Int, | ||
) { | ||
public final override fun equals(other: Any?): Boolean = this === other || | ||
(other is DiscordApplicationRoleConnectionMetadataRecordType && this.value == other.value) | ||
|
||
public final override fun hashCode(): Int = value.hashCode() | ||
|
||
public final override fun toString(): String = | ||
"DiscordApplicationRoleConnectionMetadataRecordType.${this::class.simpleName}(value=$value)" | ||
|
||
/** | ||
* An unknown [DiscordApplicationRoleConnectionMetadataRecordType]. | ||
* | ||
* This is used as a fallback for [DiscordApplicationRoleConnectionMetadataRecordType]s that | ||
* haven't been added to Kord yet. | ||
*/ | ||
public class Unknown( | ||
`value`: Int, | ||
) : DiscordApplicationRoleConnectionMetadataRecordType(value) | ||
|
||
/** | ||
* The metadata value (integer) is less than or equal to the guild's configured value (integer) | ||
*/ | ||
public object IntegerLessThanOrEqual : DiscordApplicationRoleConnectionMetadataRecordType(1) | ||
|
||
/** | ||
* The metadata value (integer) is greater than or equal to the guild's configured value | ||
* (integer) | ||
*/ | ||
public object IntegerGreaterThanOrEqual : DiscordApplicationRoleConnectionMetadataRecordType(2) | ||
|
||
/** | ||
* The metadata value (integer) is equal to the guild's configured value (integer) | ||
*/ | ||
public object IntegerEqual : DiscordApplicationRoleConnectionMetadataRecordType(3) | ||
|
||
/** | ||
* The metadata value (integer) is not equal to the guild's configured value (integer) | ||
*/ | ||
public object IntegerNotEqual : DiscordApplicationRoleConnectionMetadataRecordType(4) | ||
|
||
/** | ||
* The metadata value (ISO8601 string) is less than or equal to the guild's configured value | ||
* (integer; days before current date) | ||
*/ | ||
public object DateTimeLessThanOrEqual : DiscordApplicationRoleConnectionMetadataRecordType(5) | ||
|
||
/** | ||
* The metadata value (ISO8601 string) is greater than or equal to the guild's configured value | ||
* (integer; days before current date) | ||
*/ | ||
public object DateTimeGreaterThanOrEqual : DiscordApplicationRoleConnectionMetadataRecordType(6) | ||
|
||
/** | ||
* The metadata value (integer) is equal to the guild's configured value (integer; 1) | ||
*/ | ||
public object BooleanEqual : DiscordApplicationRoleConnectionMetadataRecordType(7) | ||
|
||
/** | ||
* The metadata value (integer) is not equal to the guild's configured value (integer; 1) | ||
*/ | ||
public object BooleanNotEqual : DiscordApplicationRoleConnectionMetadataRecordType(8) | ||
|
||
internal object Serializer : KSerializer<DiscordApplicationRoleConnectionMetadataRecordType> { | ||
public override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("dev.kord.common.entity.DiscordApplicationRoleConnectionMetadataRecordType", | ||
PrimitiveKind.INT) | ||
|
||
public override fun serialize(encoder: Encoder, | ||
`value`: DiscordApplicationRoleConnectionMetadataRecordType) = | ||
encoder.encodeInt(value.value) | ||
|
||
public override fun deserialize(decoder: Decoder) = when (val value = decoder.decodeInt()) { | ||
1 -> IntegerLessThanOrEqual | ||
2 -> IntegerGreaterThanOrEqual | ||
3 -> IntegerEqual | ||
4 -> IntegerNotEqual | ||
5 -> DateTimeLessThanOrEqual | ||
6 -> DateTimeGreaterThanOrEqual | ||
7 -> BooleanEqual | ||
8 -> BooleanNotEqual | ||
else -> Unknown(value) | ||
} | ||
} | ||
|
||
public companion object { | ||
/** | ||
* A [List] of all known [DiscordApplicationRoleConnectionMetadataRecordType]s. | ||
*/ | ||
public val entries: List<DiscordApplicationRoleConnectionMetadataRecordType> by | ||
lazy(mode = PUBLICATION) { | ||
listOf( | ||
IntegerLessThanOrEqual, | ||
IntegerGreaterThanOrEqual, | ||
IntegerEqual, | ||
IntegerNotEqual, | ||
DateTimeLessThanOrEqual, | ||
DateTimeGreaterThanOrEqual, | ||
BooleanEqual, | ||
BooleanNotEqual, | ||
) | ||
} | ||
|
||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
common/src/commonMain/kotlin/entity/DiscordRoleConnectionMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
@file:GenerateKordEnum( | ||
name = "DiscordApplicationRoleConnectionMetadataRecordType", | ||
valueType = GenerateKordEnum.ValueType.INT, | ||
docUrl = "https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type", | ||
kDoc = "Type of [DiscordRoleConnectionMetadata] values", | ||
entries = [ | ||
GenerateKordEnum.Entry( | ||
name = "IntegerLessThanOrEqual", | ||
intValue = 1, | ||
kDoc = "The metadata value (integer) is less than or equal to the guild's configured value (integer)" | ||
), | ||
GenerateKordEnum.Entry( | ||
name = "IntegerGreaterThanOrEqual", | ||
intValue = 2, | ||
kDoc = "The metadata value (integer) is greater than or equal to the guild's configured value (integer)" | ||
), | ||
GenerateKordEnum.Entry( | ||
name = "IntegerEqual", | ||
intValue = 3, | ||
kDoc = "The metadata value (integer) is equal to the guild's configured value (integer)" | ||
), | ||
GenerateKordEnum.Entry( | ||
name = "IntegerNotEqual", | ||
intValue = 4, | ||
kDoc = "The metadata value (integer) is not equal to the guild's configured value (integer)" | ||
), | ||
GenerateKordEnum.Entry( | ||
name = "DateTimeLessThanOrEqual", | ||
intValue = 5, | ||
kDoc = "The metadata value (ISO8601 string) is less than or equal to the guild's configured value (integer; days before current date)" | ||
), | ||
GenerateKordEnum.Entry( | ||
name = "DateTimeGreaterThanOrEqual", | ||
intValue = 6, | ||
kDoc = "The metadata value (ISO8601 string) is greater than or equal to the guild's configured value (integer; days before current date)" | ||
), | ||
GenerateKordEnum.Entry( | ||
name = "BooleanEqual", | ||
intValue = 7, | ||
kDoc = "The metadata value (integer) is equal to the guild's configured value (integer; 1)" | ||
), | ||
GenerateKordEnum.Entry( | ||
name = "BooleanNotEqual", | ||
intValue = 8, | ||
kDoc = "The metadata value (integer) is not equal to the guild's configured value (integer; 1)" | ||
) | ||
] | ||
) | ||
|
||
package dev.kord.common.entity | ||
|
||
import dev.kord.common.Locale | ||
import dev.kord.common.entity.optional.Optional | ||
import dev.kord.ksp.GenerateKordEnum | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* A representation of role connection metadata for an [application][DiscordApplication]. | ||
* | ||
* @property type [type][DiscordApplicationRoleConnectionMetadataRecordType] of metadata value | ||
* @property key dictionary key for the metadata field (must be a-z, 0-9, or _ characters; 1-50 characters) | ||
* @property name name of the metadata field (1-100 characters) | ||
* @property nameLocalizations with keys in available locales translations of the name | ||
* @property description description of the metadata field (1-200 characters) | ||
* @property descriptionLocalizations with keys in available locales translations of the description | ||
*/ | ||
@Serializable | ||
public data class DiscordApplicationRoleConnectionMetadataRecord( | ||
val type: DiscordApplicationRoleConnectionMetadataRecordType, | ||
val key: String, | ||
val name: String, | ||
val nameLocalizations: Optional<Map<Locale, String>> = Optional.Missing(), | ||
val description: String, | ||
val descriptionLocalizations: Optional<Map<Locale, String>> = Optional.Missing() | ||
) |
39 changes: 39 additions & 0 deletions
39
core/src/commonMain/kotlin/cache/data/ApplicationRoleConnectionMetadataData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.kord.core.cache.data | ||
|
||
import dev.kord.common.Locale | ||
import dev.kord.common.entity.DiscordApplication | ||
import dev.kord.common.entity.DiscordApplicationRoleConnectionMetadataRecord | ||
import dev.kord.common.entity.DiscordApplicationRoleConnectionMetadataRecordType | ||
import dev.kord.common.entity.optional.Optional | ||
|
||
/** | ||
* A representation of role connection metadata for an [application][DiscordApplication]. | ||
* | ||
* @property type [type][DiscordApplicationRoleConnectionMetadataRecordType] of metadata value | ||
* @property key dictionary key for the metadata field (must be a-z, 0-9, or _ characters; 1-50 characters) | ||
* @property name name of the metadata field (1-100 characters) | ||
* @property nameLocalizations with keys in available locales translations of the name | ||
* @property description description of the metadata field (1-200 characters) | ||
* @property descriptionLocalizations with keys in available locales translations of the description | ||
*/ | ||
|
||
public data class ApplicationRoleConnectionMetadataData( | ||
val type: DiscordApplicationRoleConnectionMetadataRecordType, | ||
val key: String, | ||
val name: String, | ||
val nameLocalizations: Optional<Map<Locale, String>> = Optional.Missing(), | ||
val description: String, | ||
val descriptionLocalizations: Optional<Map<Locale, String>> = Optional.Missing() | ||
) { | ||
public companion object { | ||
public fun from(record: DiscordApplicationRoleConnectionMetadataRecord): ApplicationRoleConnectionMetadataData = | ||
ApplicationRoleConnectionMetadataData( | ||
record.type, | ||
record.key, | ||
record.name, | ||
record.nameLocalizations, | ||
record.description, | ||
record.descriptionLocalizations | ||
) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core/src/commonMain/kotlin/entity/application/RoleConnectionMetadataRecord.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.kord.core.entity.application | ||
|
||
import dev.kord.common.Locale | ||
import dev.kord.common.entity.DiscordApplicationRoleConnectionMetadataRecordType | ||
import dev.kord.core.cache.data.ApplicationRoleConnectionMetadataData | ||
|
||
/** | ||
* A representation of role connection metadata for an [application][Application]. | ||
* | ||
* @property type [type][DiscordApplicationRoleConnectionMetadataRecordType] of metadata value | ||
* @property key dictionary key for the metadata field (must be a-z, 0-9, or _ characters; 1-50 characters) | ||
* @property name name of the metadata field (1-100 characters) | ||
* @property nameLocalizations with keys in available locales translations of the name | ||
* @property description description of the metadata field (1-200 characters) | ||
* @property descriptionLocalizations with keys in available locales translations of the description | ||
*/ | ||
public class RoleConnectionMetadataRecord(public val data: ApplicationRoleConnectionMetadataData) { | ||
public val type: DiscordApplicationRoleConnectionMetadataRecordType get() = data.type | ||
public val key: String get() = data.key | ||
public val name: String get() = data.name | ||
public val nameLocalizations: Map<Locale, String> | ||
get() = data.nameLocalizations.value ?: emptyMap() | ||
public val description: String get() = data.description | ||
public val descriptionLocalizations: Map<Locale, String> | ||
get() = data.nameLocalizations.value ?: emptyMap() | ||
} |