Skip to content

Commit

Permalink
Unify names
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 27, 2024
1 parent 5c6ed1d commit 5fb4587
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,75 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

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

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

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

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

/**
* The app handles the interaction using an interaction token
*/
public object AppHandler : EntryPointCommandHandlerType(1)
public object AppHandler : PrimaryEntryPointCommandHandlerType(1)

/**
* Discord handles the interaction by launching an Activity and sending a follow-up message
* without coordinating with the app
*/
public object DiscordLaunchActivity : EntryPointCommandHandlerType(2)
public object DiscordLaunchActivity : PrimaryEntryPointCommandHandlerType(2)

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

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

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

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

/**
* Returns an instance of [EntryPointCommandHandlerType] with
* [EntryPointCommandHandlerType.value] equal to the specified [value].
* Returns an instance of [PrimaryEntryPointCommandHandlerType] with
* [PrimaryEntryPointCommandHandlerType.value] equal to the specified [value].
*/
public fun from(`value`: Int): EntryPointCommandHandlerType = when (value) {
public fun from(`value`: Int): PrimaryEntryPointCommandHandlerType = when (value) {
1 -> AppHandler
2 -> DiscordLaunchActivity
else -> Unknown(value)
Expand Down
2 changes: 1 addition & 1 deletion common/src/commonMain/kotlin/entity/Interactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)

@file:Generate(
INT_KORD_ENUM, name = "EntryPointCommandHandlerType",
INT_KORD_ENUM, name = "PrimaryEntryPointCommandHandlerType",
docUrl = "https://discord.com/developers/docs/interactions/application-commands#application-command-object-entry-point-command-handler-types",
entries = [
Entry("AppHandler", intValue = 1, kDoc = "The app handles the interaction using an interaction token"),
Expand Down
23 changes: 11 additions & 12 deletions core/src/commonMain/kotlin/Kord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dev.kord.cache.api.DataCache
import dev.kord.common.annotation.KordExperimental
import dev.kord.common.annotation.KordUnsafe
import dev.kord.common.entity.DiscordShard
import dev.kord.common.entity.EntryPointCommandHandlerType
import dev.kord.common.entity.PrimaryEntryPointCommandHandlerType
import dev.kord.common.entity.Snowflake
import dev.kord.common.exception.RequestException
import dev.kord.core.builder.kord.KordBuilder
Expand Down Expand Up @@ -646,15 +646,15 @@ public class Kord(
return GuildUserCommand(data, rest.interaction)
}

public suspend inline fun createGuildEntryPointCommand(
public suspend inline fun createGuildPrimaryEntryPointCommand(
guildId: Snowflake,
name: String,
description: String,
handler: EntryPointCommandHandlerType,
handler: PrimaryEntryPointCommandHandlerType,
builder: EntryPointCreateBuilder.() -> Unit = {},
): GuildEntryPointCommand {
): GuildPrimaryEntryPointCommand {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
val response = rest.interaction.createGuildEntryPointCommand(
val response = rest.interaction.createGuildPrimaryEntryPointCommand(
resources.applicationId,
guildId,
name,
Expand All @@ -664,18 +664,18 @@ public class Kord(
)

val data = ApplicationCommandData.from(response)
return GuildEntryPointCommand(data, rest.interaction)
return GuildPrimaryEntryPointCommand(data, rest.interaction)
}


public suspend inline fun createGlobalEntryPointCommand(
public suspend inline fun createGlobalPrimaryEntryPointCommand(
name: String,
description: String,
handler: EntryPointCommandHandlerType,
handler: PrimaryEntryPointCommandHandlerType,
builder: EntryPointCreateBuilder.() -> Unit = {},
): GlobalEntryPointCommand {
): GlobalPrimaryEntryPointCommand {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
val response = rest.interaction.createGlobalEntryPointCommand(
val response = rest.interaction.createGlobalPrimaryEntryPointCommand(
resources.applicationId,
name,
description,
Expand All @@ -684,7 +684,7 @@ public class Kord(
)

val data = ApplicationCommandData.from(response)
return GlobalEntryPointCommand(data, rest.interaction)
return GlobalPrimaryEntryPointCommand(data, rest.interaction)
}

public suspend inline fun createGuildApplicationCommands(
Expand All @@ -702,7 +702,6 @@ public class Kord(
}
}
}

}

/**
Expand Down
20 changes: 10 additions & 10 deletions core/src/commonMain/kotlin/behavior/EntryPointCommandBehaviors.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package dev.kord.core.behavior

import dev.kord.core.cache.data.ApplicationCommandData
import dev.kord.core.entity.application.EntryPointCommand
import dev.kord.core.entity.application.GlobalEntryPointCommand
import dev.kord.core.entity.application.GuildEntryPointCommand
import dev.kord.core.entity.application.PrimaryEntryPointCommand
import dev.kord.core.entity.application.GlobalPrimaryEntryPointCommand
import dev.kord.core.entity.application.GuildPrimaryEntryPointCommand
import dev.kord.rest.builder.interaction.EntryPointModifyBuilder

public interface EntryPointCommandBehavior : ApplicationCommandBehavior {
public suspend fun edit(builder: suspend EntryPointModifyBuilder.() -> Unit): EntryPointCommand
public suspend fun edit(builder: suspend EntryPointModifyBuilder.() -> Unit): PrimaryEntryPointCommand
}

public interface GuildEntryPointCommandBehavior : EntryPointCommandBehavior, GuildApplicationCommandBehavior {
override suspend fun edit(builder: suspend EntryPointModifyBuilder.() -> Unit): GuildEntryPointCommand {
val response = service.modifyGuildEntryPointApplicationCommand(applicationId, guildId, id) {
override suspend fun edit(builder: suspend EntryPointModifyBuilder.() -> Unit): GuildPrimaryEntryPointCommand {
val response = service.modifyGuildPrimaryEntryPointApplicationCommand(applicationId, guildId, id) {
builder()
}
val data = ApplicationCommandData.from(response)
return GuildEntryPointCommand(data, service)
return GuildPrimaryEntryPointCommand(data, service)
}
}

public interface GlobalEntryPointCommandBehavior : EntryPointCommandBehavior, GlobalApplicationCommandBehavior {
override suspend fun edit(builder: suspend EntryPointModifyBuilder.() -> Unit): GlobalEntryPointCommand {
val response = service.modifyGlobalEntryPointApplicationCommand(applicationId, id) {
override suspend fun edit(builder: suspend EntryPointModifyBuilder.() -> Unit): GlobalPrimaryEntryPointCommand {
val response = service.modifyGlobalPrimaryEntryPointApplicationCommand(applicationId, id) {
builder()
}
val data = ApplicationCommandData.from(response)
return GlobalEntryPointCommand(data, service)
return GlobalPrimaryEntryPointCommand(data, service)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public fun GlobalApplicationCommand(data: ApplicationCommandData, service: Inter
ApplicationCommandType.ChatInput -> GlobalChatInputCommand(data, service)
ApplicationCommandType.Message -> GlobalMessageCommand(data, service)
ApplicationCommandType.User -> GlobalUserCommand(data, service)
ApplicationCommandType.PrimaryEntryPoint -> GlobalEntryPointCommand(data, service)
ApplicationCommandType.PrimaryEntryPoint -> GlobalPrimaryEntryPointCommand(data, service)
is ApplicationCommandType.Unknown -> UnknownGlobalApplicationCommand(data, service)
null -> error("The type value is missing, can't determine the type")
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public fun GuildApplicationCommand(data: ApplicationCommandData, service: Intera
ApplicationCommandType.ChatInput -> GuildChatInputCommand(data, service)
ApplicationCommandType.Message -> GuildMessageCommand(data, service)
ApplicationCommandType.User -> GuildUserCommand(data, service)
ApplicationCommandType.PrimaryEntryPoint -> GuildEntryPointCommand(data, service)
ApplicationCommandType.PrimaryEntryPoint -> GuildPrimaryEntryPointCommand(data, service)
is ApplicationCommandType.Unknown -> UnknownGuildApplicationCommand(data, service)
null -> error("The type value is missing, can't determine the type")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import dev.kord.core.behavior.GuildEntryPointCommandBehavior
import dev.kord.core.cache.data.ApplicationCommandData
import dev.kord.rest.service.InteractionService

public interface EntryPointCommand : ApplicationCommand, EntryPointCommandBehavior
public interface PrimaryEntryPointCommand : ApplicationCommand, EntryPointCommandBehavior

public class GuildEntryPointCommand(
public class GuildPrimaryEntryPointCommand(
override val data: ApplicationCommandData,
override val service: InteractionService
) : EntryPointCommand, GuildApplicationCommand, GuildEntryPointCommandBehavior {
) : PrimaryEntryPointCommand, GuildApplicationCommand, GuildEntryPointCommandBehavior {
override val guildId: Snowflake
get() = data.guildId.value!!
}

public class GlobalEntryPointCommand(
public class GlobalPrimaryEntryPointCommand(
override val data: ApplicationCommandData,
override val service: InteractionService
) : EntryPointCommand, GlobalApplicationCommand, GlobalEntryPointCommandBehavior
) : PrimaryEntryPointCommand, GlobalApplicationCommand, GlobalEntryPointCommandBehavior
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public fun GlobalApplicationCommandInteraction(
ApplicationCommandType.ChatInput -> GlobalChatInputCommandInteraction(data, kord, supplier)
ApplicationCommandType.User -> GlobalUserCommandInteraction(data, kord, supplier)
ApplicationCommandType.Message -> GlobalMessageCommandInteraction(data, kord, supplier)
ApplicationCommandType.PrimaryEntryPoint -> GlobalPrimaryEntryPointInteraction(data, kord, supplier)
ApplicationCommandType.PrimaryEntryPoint -> GlobalPrimaryEntryPointCommandInteraction(data, kord, supplier)
is ApplicationCommandType.Unknown -> error("Unknown application command type ${type.value}")
null -> error("No application command type was provided")
}
Expand All @@ -77,7 +77,7 @@ public fun GuildApplicationCommandInteraction(
ApplicationCommandType.ChatInput -> GuildChatInputCommandInteraction(data, kord, supplier)
ApplicationCommandType.User -> GuildUserCommandInteraction(data, kord, supplier)
ApplicationCommandType.Message -> GuildMessageCommandInteraction(data, kord, supplier)
ApplicationCommandType.PrimaryEntryPoint -> GuildPrimaryEntryPointInteraction(data, kord, supplier)
ApplicationCommandType.PrimaryEntryPoint -> GuildPrimaryEntryPointCommandInteraction(data, kord, supplier)
is ApplicationCommandType.Unknown -> error("Unknown application command type ${type.value}")
null -> error("No application command type was provided")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import dev.kord.core.cache.data.InteractionData
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy

public sealed interface PrimaryEntryPointInteraction : ApplicationCommandInteraction {
override fun withStrategy(strategy: EntitySupplyStrategy<*>): PrimaryEntryPointInteraction
public sealed interface PrimaryEntryPointCommandInteraction : ApplicationCommandInteraction {
override fun withStrategy(strategy: EntitySupplyStrategy<*>): PrimaryEntryPointCommandInteraction
}

public class GlobalPrimaryEntryPointInteraction(
public class GlobalPrimaryEntryPointCommandInteraction(
override val data: InteractionData,
override val kord: Kord,
override val supplier: EntitySupplier
) : PrimaryEntryPointInteraction, GlobalApplicationCommandInteraction {
override fun withStrategy(strategy: EntitySupplyStrategy<*>): GlobalPrimaryEntryPointInteraction =
GlobalPrimaryEntryPointInteraction(data, kord, strategy.supply(kord))
) : PrimaryEntryPointCommandInteraction, GlobalApplicationCommandInteraction {
override fun withStrategy(strategy: EntitySupplyStrategy<*>): GlobalPrimaryEntryPointCommandInteraction =
GlobalPrimaryEntryPointCommandInteraction(data, kord, strategy.supply(kord))

override fun equals(other: Any?): Boolean = other is GlobalPrimaryEntryPointInteraction && this.id == other.id
override fun equals(other: Any?): Boolean = other is GlobalPrimaryEntryPointCommandInteraction && this.id == other.id
override fun hashCode(): Int = id.hashCode()
override fun toString(): String =
"GlobalPrimaryCommandInteraction(data=$data, kord=$kord, supplier=$supplier)"
}

public class GuildPrimaryEntryPointInteraction(
public class GuildPrimaryEntryPointCommandInteraction(
override val data: InteractionData,
override val kord: Kord,
override val supplier: EntitySupplier
) : PrimaryEntryPointInteraction, GuildApplicationCommandInteraction {
override fun withStrategy(strategy: EntitySupplyStrategy<*>): GuildPrimaryEntryPointInteraction =
GuildPrimaryEntryPointInteraction(data, kord, strategy.supply(kord))
) : PrimaryEntryPointCommandInteraction, GuildApplicationCommandInteraction {
override fun withStrategy(strategy: EntitySupplyStrategy<*>): GuildPrimaryEntryPointCommandInteraction =
GuildPrimaryEntryPointCommandInteraction(data, kord, strategy.supply(kord))

override fun equals(other: Any?): Boolean = other is GlobalPrimaryEntryPointInteraction && this.id == other.id
override fun equals(other: Any?): Boolean = other is GlobalPrimaryEntryPointCommandInteraction && this.id == other.id
override fun hashCode(): Int = id.hashCode()
override fun toString(): String =
"GuildPrimaryEntryPointInteraction(data=$data, kord=$kord, supplier=$supplier)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.kord.core.event.interaction

import dev.kord.common.annotation.KordPreview
import dev.kord.core.Kord
import dev.kord.core.entity.interaction.*
import dev.kord.core.event.Event
Expand Down Expand Up @@ -89,22 +88,22 @@ public class GlobalChatInputCommandInteractionCreateEvent(
override val customContext: Any?,
) : GlobalApplicationCommandInteractionCreateEvent, ChatInputCommandInteractionCreateEvent

/** An [Event] that fires when a [PrimaryEntryPointInteraction] is created. */
/** An [Event] that fires when a [PrimaryEntryPointCommandInteraction] is created. */
public sealed interface PrimaryEntryPointCommandInteractionCreateEvent : ApplicationCommandInteractionCreateEvent {
override val interaction: PrimaryEntryPointInteraction
override val interaction: PrimaryEntryPointCommandInteraction
}

/** An [Event] that fires when a [GuildPrimaryEntryPointInteraction] is created. */
/** An [Event] that fires when a [GuildPrimaryEntryPointCommandInteraction] is created. */
public class GuildPrimaryEntryPointCommandInteractionCreateEvent(
override val interaction: GuildPrimaryEntryPointInteraction,
override val interaction: GuildPrimaryEntryPointCommandInteraction,
override val kord: Kord,
override val shard: Int,
override val customContext: Any?
) : PrimaryEntryPointCommandInteractionCreateEvent, GuildApplicationCommandInteractionCreateEvent

/** An [Event] that fires when a [GlobalPrimaryEntryPointInteraction] is created. */
/** An [Event] that fires when a [GlobalPrimaryEntryPointCommandInteraction] is created. */
public class GlobalPrimaryEntryPointCommandInteractionCreateEvent(
override val interaction: GlobalPrimaryEntryPointInteraction,
override val interaction: GlobalPrimaryEntryPointCommandInteraction,
override val kord: Kord,
override val shard: Int,
override val customContext: Any?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ internal class InteractionEventHandler : BaseGatewayEventHandler() {
is GuildButtonInteraction -> GuildButtonInteractionCreateEvent(interaction, kord, shard, context?.get())
is GuildSelectMenuInteraction -> GuildSelectMenuInteractionCreateEvent(interaction, kord, shard, context?.get())
is GuildModalSubmitInteraction -> GuildModalSubmitInteractionCreateEvent(interaction, kord, shard, context?.get())
is GlobalPrimaryEntryPointInteraction -> GlobalPrimaryEntryPointCommandInteractionCreateEvent(interaction, kord, shard, context?.get())
is GuildPrimaryEntryPointInteraction -> GuildPrimaryEntryPointCommandInteractionCreateEvent(interaction, kord, shard, context?.get())
is GlobalPrimaryEntryPointCommandInteraction -> GlobalPrimaryEntryPointCommandInteractionCreateEvent(interaction, kord, shard, context?.get())
is GuildPrimaryEntryPointCommandInteraction -> GuildPrimaryEntryPointCommandInteractionCreateEvent(interaction, kord, shard, context?.get())
}
return coreEvent
}
Expand Down
Loading

0 comments on commit 5fb4587

Please sign in to comment.