Skip to content

Commit

Permalink
Deprecate application command events (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann authored Mar 19, 2024
1 parent 4ad225c commit b3efeaf
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import dev.kord.core.entity.application.*
import dev.kord.core.event.Event


@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public sealed interface ApplicationCommandCreateEvent : Event {
public val command: GuildApplicationCommand
}

@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class ChatInputCommandCreateEvent(
override val command: GuildChatInputCommand,
override val kord: Kord,
Expand All @@ -17,6 +28,12 @@ public class ChatInputCommandCreateEvent(
) : ApplicationCommandCreateEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class UserCommandCreateEvent(
override val command: GuildUserCommand,
override val kord: Kord,
Expand All @@ -25,6 +42,12 @@ public class UserCommandCreateEvent(
) : ApplicationCommandCreateEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class MessageCommandCreateEvent(
override val command: GuildMessageCommand,
override val kord: Kord,
Expand All @@ -33,6 +56,12 @@ public class MessageCommandCreateEvent(
) : ApplicationCommandCreateEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class UnknownApplicationCommandCreateEvent(
override val command: UnknownGuildApplicationCommand,
override val kord: Kord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import dev.kord.core.entity.application.*
import dev.kord.core.event.Event


@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public sealed interface ApplicationCommandDeleteEvent : Event {
public val command: GuildApplicationCommand
}

@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class ChatInputCommandDeleteEvent(
override val command: GuildChatInputCommand,
override val kord: Kord,
Expand All @@ -17,6 +28,12 @@ public class ChatInputCommandDeleteEvent(
) : ApplicationCommandDeleteEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class UserCommandDeleteEvent(
override val command: GuildUserCommand,
override val kord: Kord,
Expand All @@ -25,6 +42,12 @@ public class UserCommandDeleteEvent(
) : ApplicationCommandDeleteEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class MessageCommandDeleteEvent(
override val command: GuildMessageCommand,
override val kord: Kord,
Expand All @@ -33,6 +56,12 @@ public class MessageCommandDeleteEvent(
) : ApplicationCommandDeleteEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class UnknownApplicationCommandDeleteEvent(
override val command: UnknownGuildApplicationCommand,
override val kord: Kord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ import dev.kord.core.entity.application.*
import dev.kord.core.event.Event


@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public sealed interface ApplicationCommandUpdateEvent : Event {
public val command: GuildApplicationCommand
}

@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class ChatInputCommandUpdateEvent(
override val command: GuildChatInputCommand,
override val kord: Kord,
Expand All @@ -17,6 +28,12 @@ public class ChatInputCommandUpdateEvent(
) : ApplicationCommandUpdateEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class UserCommandUpdateEvent(
override val command: GuildUserCommand,
override val kord: Kord,
Expand All @@ -25,13 +42,25 @@ public class UserCommandUpdateEvent(
) : ApplicationCommandUpdateEvent


@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class MessageCommandUpdateEvent(
override val command: GuildMessageCommand,
override val kord: Kord,
override val shard: Int,
override val customContext: Any?,
) : ApplicationCommandUpdateEvent

@Suppress("DEPRECATION")
@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public class UnknownApplicationCommandUpdateEvent(
override val command: UnknownGuildApplicationCommand,
override val kord: Kord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dev.kord.core.event.Event as CoreEvent

internal class InteractionEventHandler : BaseGatewayEventHandler() {

@Suppress("DEPRECATION")
override suspend fun handle(event: Event, shard: Int, kord: Kord, context: LazyContext?): CoreEvent? =
when (event) {
is InteractionCreate -> handle(event, shard, kord, context)
Expand Down Expand Up @@ -53,6 +54,7 @@ internal class InteractionEventHandler : BaseGatewayEventHandler() {
return coreEvent
}

@Suppress("DEPRECATION")
private suspend fun handle(
event: ApplicationCommandCreate,
shard: Int,
Expand All @@ -71,6 +73,7 @@ internal class InteractionEventHandler : BaseGatewayEventHandler() {
}


@Suppress("DEPRECATION")
private suspend fun handle(
event: ApplicationCommandUpdate,
shard: Int,
Expand All @@ -89,6 +92,7 @@ internal class InteractionEventHandler : BaseGatewayEventHandler() {
return coreEvent
}

@Suppress("DEPRECATION")
private suspend fun handle(
event: ApplicationCommandDelete,
shard: Int,
Expand Down
18 changes: 18 additions & 0 deletions gateway/src/commonMain/kotlin/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,13 @@ public sealed class Event {
// them too.
// See https://github.com/discord/discord-api-docs/pull/3691
"APPLICATION_COMMAND_CREATE" ->
@Suppress("DEPRECATION")
ApplicationCommandCreate(decode(DiscordApplicationCommand.serializer()), sequence)
"APPLICATION_COMMAND_UPDATE" ->
@Suppress("DEPRECATION")
ApplicationCommandUpdate(decode(DiscordApplicationCommand.serializer()), sequence)
"APPLICATION_COMMAND_DELETE" ->
@Suppress("DEPRECATION")
ApplicationCommandDelete(decode(DiscordApplicationCommand.serializer()), sequence)
else -> {
jsonLogger.debug { "Unknown gateway event name: $eventName" }
Expand Down Expand Up @@ -501,14 +504,29 @@ public data class WebhooksUpdate(val webhooksUpdateData: DiscordWebhooksUpdateDa
public data class InteractionCreate(val interaction: DiscordInteraction, override val sequence: Int?) : DispatchEvent()


@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public data class ApplicationCommandCreate(val application: DiscordApplicationCommand, override val sequence: Int?) :
DispatchEvent()


@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public data class ApplicationCommandUpdate(val application: DiscordApplicationCommand, override val sequence: Int?) :
DispatchEvent()


@Deprecated(
"This event is not supposed to be sent to bots. See https://github.com/discord/discord-api-docs/issues/3690 for " +
"details.",
level = DeprecationLevel.WARNING,
)
public data class ApplicationCommandDelete(val application: DiscordApplicationCommand, override val sequence: Int?) :
DispatchEvent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ class DispatchEventDeserializationTest {
""""default_member_permissions":null,"version":"0"}"""

@Test
@Suppress("DEPRECATION")
fun test_ApplicationCommandCreate_deserialization() = testDispatchEventDeserialization(
eventName = "APPLICATION_COMMAND_CREATE",
eventConstructor = ::ApplicationCommandCreate,
Expand All @@ -782,6 +783,7 @@ class DispatchEventDeserializationTest {
)

@Test
@Suppress("DEPRECATION")
fun test_ApplicationCommandUpdate_deserialization() = testDispatchEventDeserialization(
eventName = "APPLICATION_COMMAND_UPDATE",
eventConstructor = ::ApplicationCommandUpdate,
Expand All @@ -790,6 +792,7 @@ class DispatchEventDeserializationTest {
)

@Test
@Suppress("DEPRECATION")
fun test_ApplicationCommandDelete_deserialization() = testDispatchEventDeserialization(
eventName = "APPLICATION_COMMAND_DELETE",
eventConstructor = ::ApplicationCommandDelete,
Expand Down

0 comments on commit b3efeaf

Please sign in to comment.