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

Merged
merged 78 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 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
2e04524
feat: update according to docs
viztea Jul 11, 2024
9cea72f
feat: rework list entitlements
viztea Jul 11, 2024
c68f2cd
Merge branch 'main' into feat/entitlements
viztea Jul 11, 2024
be62d24
chore: api dump
viztea Jul 11, 2024
c01b8bc
chore: requested changes
viztea Aug 15, 2024
f9a8289
Merge branch 'main' into feat/entitlements
lukellmann Sep 7, 2024
d1cc987
feat(rest): error codes 40018 and 40019
lukellmann Sep 7, 2024
4b85cef
chore(core): remove suspend from EntitySupplier.getEntitlements
lukellmann Sep 7, 2024
d46c328
chore(core): remove unused RestEntitySupplier.sku
lukellmann Sep 7, 2024
7962fcf
chore(rest): defensive copy in EntitlementsListRequestBuilder
lukellmann Sep 7, 2024
2eae328
chore(core): remove suspend from Kord.getEntitlements
lukellmann Sep 8, 2024
8dd41c3
chore(core): rename Events.kt to EntitlementEvents.kt
lukellmann Sep 8, 2024
54827ee
chore: update links
lukellmann Sep 8, 2024
930fead
chore: remove getting single entitlement
lukellmann Sep 8, 2024
3e4498d
chore: document Kord.createTestEntitlement
lukellmann Sep 8, 2024
1b68967
chore: don't implement Strategizable for Entitlement
lukellmann Sep 8, 2024
27135cd
fix(core): correct pagination for getEntitlements
lukellmann Sep 8, 2024
c2a983f
feat(core): add ActionRowComponent.premiumButtons
lukellmann Sep 8, 2024
2988a4a
fix(core): Entitlement.endsAt is nullable
lukellmann Sep 9, 2024
4d46fb2
chore(core): remove Entitlement.isTest
lukellmann Sep 9, 2024
a06abeb
chore(core): use QueryBuilder in CacheEntitySupplier
lukellmann Sep 9, 2024
8ce5b64
chore: update KDoc
lukellmann Sep 9, 2024
382b887
chore: restore formatting of unrelated code
lukellmann Sep 9, 2024
4fefe6b
chore: formatting
lukellmann Sep 9, 2024
2c44cb7
chore: change equals implementations
lukellmann Sep 9, 2024
104ada0
chore: reorder
lukellmann Sep 9, 2024
0b29428
chore(core): update KDoc for methods of Kord
lukellmann Sep 9, 2024
81fb5a5
chore(common): use singular file names
lukellmann Sep 9, 2024
1ecefc2
feat(common): subscriptions
lukellmann Sep 9, 2024
ae46b1a
feat(rest): subscriptions
lukellmann Sep 9, 2024
7c47744
feat(gateway): subscriptions
lukellmann Sep 9, 2024
4753b78
Merge branch 'main' into feat/entitlements
lukellmann Sep 10, 2024
3516eb6
chore: shared monetization packages
lukellmann Sep 11, 2024
2558e28
chore: tweak KDoc
lukellmann Sep 11, 2024
ef01707
chore(core): rename parameter of EntitlementData.from
lukellmann Sep 11, 2024
b108060
chore(core): formatting
lukellmann Sep 11, 2024
6d74f96
chore(core): create Entitlements after caching
lukellmann Sep 11, 2024
c87d748
feat(core): subscriptions
lukellmann Sep 12, 2024
03ffa81
chore(core): gotta give the toString some space
lukellmann Sep 12, 2024
d4e9018
chore(common): polish SkuType KDoc
lukellmann Sep 14, 2024
37afa95
fix(core): remove unused parameter
lukellmann Sep 14, 2024
3ab3e4e
chore(core): add name to argument
lukellmann Sep 14, 2024
809f7af
chore(core): add more names to arguments
lukellmann Sep 14, 2024
cc36c98
chore(core): consistent use of "an SKU"
lukellmann Sep 14, 2024
3f5b8a1
chore(core): move consume above delete
lukellmann Sep 14, 2024
92d5131
chore(core): tweak KDoc
lukellmann Sep 14, 2024
eddd6c6
chore(core): link to Entitlement in Subscription KDoc
lukellmann Sep 14, 2024
cdf41be
chore(core): Subscription KDoc: mention IDs
lukellmann Sep 14, 2024
28923af
feat(core): Subscription.skus
lukellmann Sep 14, 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
367 changes: 359 additions & 8 deletions common/api/common.api

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

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

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

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

package dev.kord.common.entity

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

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

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

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

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

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

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

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

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

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

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

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

package dev.kord.common.entity

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/**
* Returns an instance of [EntitlementType] with [EntitlementType.value] equal to the
* specified [value].
*/
public fun from(`value`: Int): EntitlementType = when (value) {
1 -> Purchase
2 -> PremiumSubscription
3 -> DeveloperGift
4 -> TestModePurchase
5 -> FreePurchase
6 -> UserGift
7 -> PremiumPurchase
8 -> ApplicationSubscription
else -> Unknown(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [GuildScheduledEventStatus]s in the
* See [GuildScheduledEventStatus]es in the
* [Discord Developer Documentation](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status).
*/
@Serializable(with = GuildScheduledEventStatus.Serializer::class)
Expand All @@ -36,7 +36,7 @@ public sealed class GuildScheduledEventStatus(
/**
* An unknown [GuildScheduledEventStatus].
*
* This is used as a fallback for [GuildScheduledEventStatus]s that haven't been added to Kord
* This is used as a fallback for [GuildScheduledEventStatus]es that haven't been added to Kord
* yet.
*/
public class Unknown internal constructor(
Expand Down Expand Up @@ -66,7 +66,7 @@ public sealed class GuildScheduledEventStatus(

public companion object {
/**
* A [List] of all known [GuildScheduledEventStatus]s.
* A [List] of all known [GuildScheduledEventStatus]es.
*/
public val entries: List<GuildScheduledEventStatus> by lazy(mode = PUBLICATION) {
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public sealed class MessageType(

public object GuildApplicationPremiumSubscription : MessageType(32)

public object PurchaseNotification : MessageType(44)

internal object Serializer : KSerializer<MessageType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.MessageType", PrimitiveKind.INT)
Expand Down Expand Up @@ -151,6 +153,7 @@ public sealed class MessageType(
StageSpeaker,
StageTopic,
GuildApplicationPremiumSubscription,
PurchaseNotification,
)
}

Expand Down Expand Up @@ -190,6 +193,7 @@ public sealed class MessageType(
29 -> StageSpeaker
31 -> StageTopic
32 -> GuildApplicationPremiumSubscription
44 -> PurchaseNotification
else -> Unknown(code)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [PresenceStatus]s in the
* See [PresenceStatus]es in the
* [Discord Developer Documentation](https://discord.com/developers/docs/topics/gateway-events#update-presence-status-types).
*/
@Serializable(with = PresenceStatus.Serializer::class)
Expand All @@ -36,7 +36,7 @@ public sealed class PresenceStatus(
/**
* An unknown [PresenceStatus].
*
* This is used as a fallback for [PresenceStatus]s that haven't been added to Kord yet.
* This is used as a fallback for [PresenceStatus]es that haven't been added to Kord yet.
*/
public class Unknown internal constructor(
`value`: String,
Expand Down Expand Up @@ -81,7 +81,7 @@ public sealed class PresenceStatus(

public companion object {
/**
* A [List] of all known [PresenceStatus]s.
* A [List] of all known [PresenceStatus]es.
*/
public val entries: List<PresenceStatus> by lazy(mode = PUBLICATION) {
listOf(
Expand Down
Loading