-
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.
Add support for Application Role Connection Metadata
The DSL looks like this: val records = kord.updateApplicationRoleConnectionMetadataRecords { record( type = BooleanEqual, key = "member", name = "Member of the secret circle", description = "Must be a member of the secret circle", ) { name(Locale.GERMAN, "Mitglied im geheimen Kreis") description(Locale.GERMAN, "Muss ein Mitglied im geheimen Kreis sein") } record( type = DateTimeLessThanOrEqual, key = "account_age", name = "Account age", description = "Account must be at least this many days old", ) { name(Locale.GERMAN, "Account Alter") description(Locale.GERMAN, "Der Account muss zumindest so viele Tage alt sein") } } println(records) Note that this does not contain the ability to update the application role connection for a user as it requires an OAuth2 access token which Kord doesn't support. see discord/discord-api-docs#5668
- Loading branch information
1 parent
4bca754
commit 2e61173
Showing
15 changed files
with
612 additions
and
20 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
140 changes: 140 additions & 0 deletions
140
...etadata/commonMain/kotlin/dev/kord/common/entity/ApplicationRoleConnectionMetadataType.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,140 @@ | ||
// 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 | ||
|
||
/** | ||
* Each [ApplicationRoleConnectionMetadataType] offers a comparison operation that allows guilds to | ||
* configure role requirements based on metadata values stored by the bot. Bots specify a 'metadata | ||
* value' for each user and guilds specify the required 'guild's configured value' within the guild | ||
* role settings. | ||
* | ||
* See [ApplicationRoleConnectionMetadataType]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 = ApplicationRoleConnectionMetadataType.Serializer::class) | ||
public sealed class ApplicationRoleConnectionMetadataType( | ||
/** | ||
* The raw value used by Discord. | ||
*/ | ||
public val `value`: Int, | ||
) { | ||
public final override fun equals(other: Any?): Boolean = this === other || | ||
(other is ApplicationRoleConnectionMetadataType && this.value == other.value) | ||
|
||
public final override fun hashCode(): Int = value.hashCode() | ||
|
||
public final override fun toString(): String = | ||
"ApplicationRoleConnectionMetadataType.${this::class.simpleName}(value=$value)" | ||
|
||
/** | ||
* An unknown [ApplicationRoleConnectionMetadataType]. | ||
* | ||
* This is used as a fallback for [ApplicationRoleConnectionMetadataType]s that haven't been | ||
* added to Kord yet. | ||
*/ | ||
public class Unknown( | ||
`value`: Int, | ||
) : ApplicationRoleConnectionMetadataType(value) | ||
|
||
/** | ||
* The metadata value (`integer`) is less than or equal to the guild's configured value | ||
* (`integer`). | ||
*/ | ||
public object IntegerLessThanOrEqual : ApplicationRoleConnectionMetadataType(1) | ||
|
||
/** | ||
* The metadata value (`integer`) is greater than or equal to the guild's configured value | ||
* (`integer`). | ||
*/ | ||
public object IntegerGreaterThanOrEqual : ApplicationRoleConnectionMetadataType(2) | ||
|
||
/** | ||
* The metadata value (`integer`) is equal to the guild's configured value (`integer`). | ||
*/ | ||
public object IntegerEqual : ApplicationRoleConnectionMetadataType(3) | ||
|
||
/** | ||
* The metadata value (`integer`) is not equal to the guild's configured value (`integer`). | ||
*/ | ||
public object IntegerNotEqual : ApplicationRoleConnectionMetadataType(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 : ApplicationRoleConnectionMetadataType(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 : ApplicationRoleConnectionMetadataType(6) | ||
|
||
/** | ||
* The metadata value (`integer`) is equal to the guild's configured value (`integer; 1`). | ||
*/ | ||
public object BooleanEqual : ApplicationRoleConnectionMetadataType(7) | ||
|
||
/** | ||
* The metadata value (`integer`) is not equal to the guild's configured value (`integer; 1`). | ||
*/ | ||
public object BooleanNotEqual : ApplicationRoleConnectionMetadataType(8) | ||
|
||
internal object Serializer : KSerializer<ApplicationRoleConnectionMetadataType> { | ||
public override val descriptor: SerialDescriptor = | ||
PrimitiveSerialDescriptor("dev.kord.common.entity.ApplicationRoleConnectionMetadataType", | ||
PrimitiveKind.INT) | ||
|
||
public override fun serialize(encoder: Encoder, | ||
`value`: ApplicationRoleConnectionMetadataType) = 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 [ApplicationRoleConnectionMetadataType]s. | ||
*/ | ||
public val entries: List<ApplicationRoleConnectionMetadataType> by | ||
lazy(mode = PUBLICATION) { | ||
listOf( | ||
IntegerLessThanOrEqual, | ||
IntegerGreaterThanOrEqual, | ||
IntegerEqual, | ||
IntegerNotEqual, | ||
DateTimeLessThanOrEqual, | ||
DateTimeGreaterThanOrEqual, | ||
BooleanEqual, | ||
BooleanNotEqual, | ||
) | ||
} | ||
|
||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
common/src/commonMain/kotlin/entity/ApplicationRoleConnectionMetadata.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,66 @@ | ||
@file: GenerateKordEnum( | ||
name = "ApplicationRoleConnectionMetadataType", valueType = INT, | ||
kDoc = "Each [ApplicationRoleConnectionMetadataType] offers a comparison operation that allows guilds to " + | ||
"configure role requirements based on metadata values stored by the bot. Bots specify a 'metadata value' for " + | ||
"each user and guilds specify the required 'guild's configured value' within the guild role settings.", | ||
docUrl = "https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object-application-role-connection-metadata-type", | ||
entries = [ | ||
Entry( | ||
"IntegerLessThanOrEqual", intValue = 1, | ||
kDoc = "The metadata value (`integer`) is less than or equal to the guild's configured value (`integer`).", | ||
), | ||
Entry( | ||
"IntegerGreaterThanOrEqual", intValue = 2, | ||
kDoc = "The metadata value (`integer`) is greater than or equal to the guild's configured value " + | ||
"(`integer`).", | ||
), | ||
Entry( | ||
"IntegerEqual", intValue = 3, | ||
kDoc = "The metadata value (`integer`) is equal to the guild's configured value (`integer`).", | ||
), | ||
Entry( | ||
"IntegerNotEqual", intValue = 4, | ||
kDoc = "The metadata value (`integer`) is not equal to the guild's configured value (`integer`).", | ||
), | ||
Entry( | ||
"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`).", | ||
), | ||
Entry( | ||
"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`).", | ||
), | ||
Entry( | ||
"BooleanEqual", intValue = 7, | ||
kDoc = "The metadata value (`integer`) is equal to the guild's configured value (`integer; 1`).", | ||
), | ||
Entry( | ||
"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 dev.kord.ksp.GenerateKordEnum.Entry | ||
import dev.kord.ksp.GenerateKordEnum.ValueType.INT | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
public data class DiscordApplicationRoleConnectionMetadata( | ||
val type: ApplicationRoleConnectionMetadataType, | ||
val key: String, | ||
val name: String, | ||
@SerialName("name_localizations") | ||
val nameLocalizations: Optional<Map<Locale, String>> = Optional.Missing(), | ||
val description: String, | ||
@SerialName("description_localizations") | ||
val descriptionLocalizations: Optional<Map<Locale, String>> = Optional.Missing(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.