Skip to content

Commit

Permalink
Implement Monetization (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
viztea and lukellmann committed Sep 15, 2024
1 parent 4f6712f commit ad59083
Show file tree
Hide file tree
Showing 71 changed files with 4,329 additions and 75 deletions.
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

0 comments on commit ad59083

Please sign in to comment.