Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Monetization #932

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
63c4841
feat: entitlements
viztea Apr 8, 2024
c2a4cb7
feat: skus
viztea Apr 8, 2024
50f0f23
feat: core api & fixes
viztea Apr 8, 2024
8de1fa8
merge: main -> feat/entitlements
viztea Apr 8, 2024
9ed8562
chore: remove RequiresMonetization annotation
viztea Apr 8, 2024
f4eab01
chore: api dump
viztea Apr 8, 2024
2d3e2b1
feat: respond premium required, getEntitlements, fix model bugs
viztea Apr 8, 2024
2f0153d
feat(rest): monetization error codes
viztea Apr 9, 2024
ef283ac
chore: implement requested changes
viztea Apr 9, 2024
eb1fa32
fix(common): premium required kdoc
viztea Apr 9, 2024
d4d9bef
chore: ksp
viztea Apr 9, 2024
14267aa
fix(core): only match against entitlement id
viztea Apr 9, 2024
29e0a01
chore: apply simple suggestions via github
viztea Apr 10, 2024
51063c7
chore: reorder service properties
viztea Apr 10, 2024
8ddf3f2
chore(rest): SkuService#getSkus -> listSkus
viztea Apr 10, 2024
c706e2a
chore: import Generate subtypes
viztea Apr 10, 2024
0e27632
chore: implement requested changes to rest
viztea Apr 10, 2024
a123744
feat(gateway/test): entitlement event deser tests
viztea Apr 10, 2024
cb34d9f
chore: requested changes
viztea Apr 11, 2024
da273bc
fix(core/cache): link user data -> entitlement data
viztea Apr 11, 2024
bb4e709
fix: api dump + missing optional stuff
viztea Apr 11, 2024
d9046af
feat: update error code name
viztea Apr 11, 2024
0a96289
chore: requested changes
viztea Apr 12, 2024
3f9b1ff
merge: main -> feat/entitlements
viztea Apr 12, 2024
d771c6b
chore: remove unnecessary json field
viztea Apr 12, 2024
ade3737
feat(core): add entitlements cache builder
viztea Apr 12, 2024
af49b06
feat(core): update kdoc
viztea Apr 12, 2024
10bfef2
chore: requested changes
viztea Apr 19, 2024
39b4978
chore: requested changes
viztea Apr 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 237 additions & 4 deletions common/api/common.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
@file:Suppress(names = arrayOf("IncorrectFormatting", "ReplaceArrayOfWithLiteral",
"SpellCheckingInspection", "GrazieInspection"))

package dev.kord.common.entity

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

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

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

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

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

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

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

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

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

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

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


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

package dev.kord.common.entity

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

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

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

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

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

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

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

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

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

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


/**
* Returns an instance of [EntitlementType] with [EntitlementType.value] equal to the
* specified [value].
*/
public fun from(`value`: Int): EntitlementType = when (value) {
8 -> ApplicationSubscription
else -> Unknown(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public sealed class InteractionResponseType(
*/
public object Modal : InteractionResponseType(9)

/**
* Respond to an interaction with an upgrade button, only available for apps with monetization
* enabled.
*/
public object PremiumRequired : InteractionResponseType(10)

internal object Serializer : KSerializer<InteractionResponseType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.InteractionResponseType",
Expand All @@ -105,6 +111,7 @@ public sealed class InteractionResponseType(
UpdateMessage,
ApplicationCommandAutoCompleteResult,
Modal,
PremiumRequired,
)
}

Expand All @@ -121,6 +128,7 @@ public sealed class InteractionResponseType(
7 -> UpdateMessage
8 -> ApplicationCommandAutoCompleteResult
9 -> Modal
10 -> PremiumRequired
else -> Unknown(type)
}
}
Expand Down
Loading
Loading