Skip to content

Commit

Permalink
feat(gateway): subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Sep 9, 2024
1 parent ae46b1a commit 7c47744
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
39 changes: 39 additions & 0 deletions gateway/api/gateway.api
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,45 @@ public final class dev/kord/gateway/Resumed$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class dev/kord/gateway/SubscriptionCreate : dev/kord/gateway/DispatchEvent {
public fun <init> (Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;)V
public final fun component1 ()Ldev/kord/common/entity/DiscordSubscription;
public final fun component2 ()Ljava/lang/Integer;
public final fun copy (Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;)Ldev/kord/gateway/SubscriptionCreate;
public static synthetic fun copy$default (Ldev/kord/gateway/SubscriptionCreate;Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;ILjava/lang/Object;)Ldev/kord/gateway/SubscriptionCreate;
public fun equals (Ljava/lang/Object;)Z
public fun getSequence ()Ljava/lang/Integer;
public final fun getSubscription ()Ldev/kord/common/entity/DiscordSubscription;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/kord/gateway/SubscriptionDelete : dev/kord/gateway/DispatchEvent {
public fun <init> (Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;)V
public final fun component1 ()Ldev/kord/common/entity/DiscordSubscription;
public final fun component2 ()Ljava/lang/Integer;
public final fun copy (Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;)Ldev/kord/gateway/SubscriptionDelete;
public static synthetic fun copy$default (Ldev/kord/gateway/SubscriptionDelete;Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;ILjava/lang/Object;)Ldev/kord/gateway/SubscriptionDelete;
public fun equals (Ljava/lang/Object;)Z
public fun getSequence ()Ljava/lang/Integer;
public final fun getSubscription ()Ldev/kord/common/entity/DiscordSubscription;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/kord/gateway/SubscriptionUpdate : dev/kord/gateway/DispatchEvent {
public fun <init> (Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;)V
public final fun component1 ()Ldev/kord/common/entity/DiscordSubscription;
public final fun component2 ()Ljava/lang/Integer;
public final fun copy (Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;)Ldev/kord/gateway/SubscriptionUpdate;
public static synthetic fun copy$default (Ldev/kord/gateway/SubscriptionUpdate;Ldev/kord/common/entity/DiscordSubscription;Ljava/lang/Integer;ILjava/lang/Object;)Ldev/kord/gateway/SubscriptionUpdate;
public fun equals (Ljava/lang/Object;)Z
public fun getSequence ()Ljava/lang/Integer;
public final fun getSubscription ()Ldev/kord/common/entity/DiscordSubscription;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/kord/gateway/ThreadCreate : dev/kord/gateway/DispatchEvent {
public fun <init> (Ldev/kord/common/entity/DiscordChannel;Ljava/lang/Integer;)V
public final fun component1 ()Ldev/kord/common/entity/DiscordChannel;
Expand Down
48 changes: 48 additions & 0 deletions gateway/api/gateway.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,54 @@ final class dev.kord.gateway/Resumed : dev.kord.gateway/DispatchEvent { // dev.k
}
}

final class dev.kord.gateway/SubscriptionCreate : dev.kord.gateway/DispatchEvent { // dev.kord.gateway/SubscriptionCreate|null[0]
constructor <init>(dev.kord.common.entity/DiscordSubscription, kotlin/Int?) // dev.kord.gateway/SubscriptionCreate.<init>|<init>(dev.kord.common.entity.DiscordSubscription;kotlin.Int?){}[0]

final val sequence // dev.kord.gateway/SubscriptionCreate.sequence|{}sequence[0]
final fun <get-sequence>(): kotlin/Int? // dev.kord.gateway/SubscriptionCreate.sequence.<get-sequence>|<get-sequence>(){}[0]
final val subscription // dev.kord.gateway/SubscriptionCreate.subscription|{}subscription[0]
final fun <get-subscription>(): dev.kord.common.entity/DiscordSubscription // dev.kord.gateway/SubscriptionCreate.subscription.<get-subscription>|<get-subscription>(){}[0]

final fun component1(): dev.kord.common.entity/DiscordSubscription // dev.kord.gateway/SubscriptionCreate.component1|component1(){}[0]
final fun component2(): kotlin/Int? // dev.kord.gateway/SubscriptionCreate.component2|component2(){}[0]
final fun copy(dev.kord.common.entity/DiscordSubscription = ..., kotlin/Int? = ...): dev.kord.gateway/SubscriptionCreate // dev.kord.gateway/SubscriptionCreate.copy|copy(dev.kord.common.entity.DiscordSubscription;kotlin.Int?){}[0]
final fun equals(kotlin/Any?): kotlin/Boolean // dev.kord.gateway/SubscriptionCreate.equals|equals(kotlin.Any?){}[0]
final fun hashCode(): kotlin/Int // dev.kord.gateway/SubscriptionCreate.hashCode|hashCode(){}[0]
final fun toString(): kotlin/String // dev.kord.gateway/SubscriptionCreate.toString|toString(){}[0]
}

final class dev.kord.gateway/SubscriptionDelete : dev.kord.gateway/DispatchEvent { // dev.kord.gateway/SubscriptionDelete|null[0]
constructor <init>(dev.kord.common.entity/DiscordSubscription, kotlin/Int?) // dev.kord.gateway/SubscriptionDelete.<init>|<init>(dev.kord.common.entity.DiscordSubscription;kotlin.Int?){}[0]

final val sequence // dev.kord.gateway/SubscriptionDelete.sequence|{}sequence[0]
final fun <get-sequence>(): kotlin/Int? // dev.kord.gateway/SubscriptionDelete.sequence.<get-sequence>|<get-sequence>(){}[0]
final val subscription // dev.kord.gateway/SubscriptionDelete.subscription|{}subscription[0]
final fun <get-subscription>(): dev.kord.common.entity/DiscordSubscription // dev.kord.gateway/SubscriptionDelete.subscription.<get-subscription>|<get-subscription>(){}[0]

final fun component1(): dev.kord.common.entity/DiscordSubscription // dev.kord.gateway/SubscriptionDelete.component1|component1(){}[0]
final fun component2(): kotlin/Int? // dev.kord.gateway/SubscriptionDelete.component2|component2(){}[0]
final fun copy(dev.kord.common.entity/DiscordSubscription = ..., kotlin/Int? = ...): dev.kord.gateway/SubscriptionDelete // dev.kord.gateway/SubscriptionDelete.copy|copy(dev.kord.common.entity.DiscordSubscription;kotlin.Int?){}[0]
final fun equals(kotlin/Any?): kotlin/Boolean // dev.kord.gateway/SubscriptionDelete.equals|equals(kotlin.Any?){}[0]
final fun hashCode(): kotlin/Int // dev.kord.gateway/SubscriptionDelete.hashCode|hashCode(){}[0]
final fun toString(): kotlin/String // dev.kord.gateway/SubscriptionDelete.toString|toString(){}[0]
}

final class dev.kord.gateway/SubscriptionUpdate : dev.kord.gateway/DispatchEvent { // dev.kord.gateway/SubscriptionUpdate|null[0]
constructor <init>(dev.kord.common.entity/DiscordSubscription, kotlin/Int?) // dev.kord.gateway/SubscriptionUpdate.<init>|<init>(dev.kord.common.entity.DiscordSubscription;kotlin.Int?){}[0]

final val sequence // dev.kord.gateway/SubscriptionUpdate.sequence|{}sequence[0]
final fun <get-sequence>(): kotlin/Int? // dev.kord.gateway/SubscriptionUpdate.sequence.<get-sequence>|<get-sequence>(){}[0]
final val subscription // dev.kord.gateway/SubscriptionUpdate.subscription|{}subscription[0]
final fun <get-subscription>(): dev.kord.common.entity/DiscordSubscription // dev.kord.gateway/SubscriptionUpdate.subscription.<get-subscription>|<get-subscription>(){}[0]

final fun component1(): dev.kord.common.entity/DiscordSubscription // dev.kord.gateway/SubscriptionUpdate.component1|component1(){}[0]
final fun component2(): kotlin/Int? // dev.kord.gateway/SubscriptionUpdate.component2|component2(){}[0]
final fun copy(dev.kord.common.entity/DiscordSubscription = ..., kotlin/Int? = ...): dev.kord.gateway/SubscriptionUpdate // dev.kord.gateway/SubscriptionUpdate.copy|copy(dev.kord.common.entity.DiscordSubscription;kotlin.Int?){}[0]
final fun equals(kotlin/Any?): kotlin/Boolean // dev.kord.gateway/SubscriptionUpdate.equals|equals(kotlin.Any?){}[0]
final fun hashCode(): kotlin/Int // dev.kord.gateway/SubscriptionUpdate.hashCode|hashCode(){}[0]
final fun toString(): kotlin/String // dev.kord.gateway/SubscriptionUpdate.toString|toString(){}[0]
}

final class dev.kord.gateway/ThreadCreate : dev.kord.gateway/DispatchEvent { // dev.kord.gateway/ThreadCreate|null[0]
constructor <init>(dev.kord.common.entity/DiscordChannel, kotlin/Int?) // dev.kord.gateway/ThreadCreate.<init>|<init>(dev.kord.common.entity.DiscordChannel;kotlin.Int?){}[0]

Expand Down
15 changes: 14 additions & 1 deletion gateway/src/commonMain/kotlin/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ public sealed class Event {
"MESSAGE_REACTION_REMOVE_EMOJI" ->
MessageReactionRemoveEmoji(decode(DiscordRemovedEmoji.serializer()), sequence)
"PRESENCE_UPDATE" -> PresenceUpdate(decode(DiscordPresenceUpdate.serializer()), sequence)
// Missing: Stage Instance Create, Stage Instance Update, Stage Instance Delete
// Missing: Stage Instance Create, Stage Instance Update, Stage Instance Delete
"SUBSCRIPTION_CREATE" -> SubscriptionCreate(decode(DiscordSubscription.serializer()), sequence)
"SUBSCRIPTION_UPDATE" -> SubscriptionUpdate(decode(DiscordSubscription.serializer()), sequence)
"SUBSCRIPTION_DELETE" -> SubscriptionDelete(decode(DiscordSubscription.serializer()), sequence)
"TYPING_START" -> TypingStart(decode(DiscordTyping.serializer()), sequence)
"USER_UPDATE" -> UserUpdate(decode(DiscordUser.serializer()), sequence)
// Missing: Voice Channel Effect Send
"VOICE_STATE_UPDATE" -> VoiceStateUpdate(decode(DiscordVoiceState.serializer()), sequence)
"VOICE_SERVER_UPDATE" -> VoiceServerUpdate(decode(DiscordVoiceServerUpdateData.serializer()), sequence)
"WEBHOOKS_UPDATE" -> WebhooksUpdate(decode(DiscordWebhooksUpdateData.serializer()), sequence)
Expand Down Expand Up @@ -654,3 +658,12 @@ public data class EntitlementCreate(val entitlement: DiscordEntitlement, overrid
public data class EntitlementUpdate(val entitlement: DiscordEntitlement, override val sequence: Int?) : DispatchEvent()

public data class EntitlementDelete(val entitlement: DiscordEntitlement, override val sequence: Int?) : DispatchEvent()

public data class SubscriptionCreate(val subscription: DiscordSubscription, override val sequence: Int?) :
DispatchEvent()

public data class SubscriptionUpdate(val subscription: DiscordSubscription, override val sequence: Int?) :
DispatchEvent()

public data class SubscriptionDelete(val subscription: DiscordSubscription, override val sequence: Int?) :
DispatchEvent()
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ class DispatchEventDeserializationTest {
)
private val integrationJson =
"""{"id":"0","name":"name","type":"discord","enabled":true,"account":{"id":"id","name":"name"}}"""
private val subscription = DiscordSubscription(
id = Snowflake.min,
userId = Snowflake.min,
skuIds = emptyList(),
entitlementIds = emptyList(),
currentPeriodStart = instant,
currentPeriodEnd = instant,
status = SubscriptionStatus.Active,
canceledAt = null,
)
private val subscriptionJson = """{"id":"0","user_id":"0","sku_ids":[],"entitlement_ids":[],""" +
""""current_period_start":"$instant","current_period_end":"$instant","status":0,"canceled_at":null}"""


/*
Expand Down Expand Up @@ -719,6 +731,30 @@ class DispatchEventDeserializationTest {
* - StageInstanceDelete
*/

@Test
fun test_SubscriptionCreate_deserialization() = testDispatchEventDeserialization(
eventName = "SUBSCRIPTION_CREATE",
eventConstructor = ::SubscriptionCreate,
data = subscription,
json = subscriptionJson,
)

@Test
fun test_SubscriptionUpdate_deserialization() = testDispatchEventDeserialization(
eventName = "SUBSCRIPTION_UPDATE",
eventConstructor = ::SubscriptionUpdate,
data = subscription,
json = subscriptionJson,
)

@Test
fun test_SubscriptionDelete_deserialization() = testDispatchEventDeserialization(
eventName = "SUBSCRIPTION_DELETE",
eventConstructor = ::SubscriptionDelete,
data = subscription,
json = subscriptionJson,
)

@Test
fun test_TypingStart_deserialization() = testDispatchEventDeserialization(
eventName = "TYPING_START",
Expand All @@ -739,6 +775,11 @@ class DispatchEventDeserializationTest {
json = userJson,
)

/*
* Missing:
* - VoiceChannelEffectSend
*/

@Test
fun test_VoiceStateUpdate_deserialization() = testDispatchEventDeserialization(
eventName = "VOICE_STATE_UPDATE",
Expand Down

0 comments on commit 7c47744

Please sign in to comment.