diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index a802889e7c8..6bdd8fc009a 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -719,42 +719,77 @@ data class AllRemovedMessageReactions( ) @Serializable(with = MessageType.MessageTypeSerializer::class) -enum class MessageType(val code: Int) { +sealed class MessageType(val code: Int) { /** The default code for unknown values. */ - Unknown(Int.MIN_VALUE), - Default(0), - RecipientAdd(1), - RecipientRemove(2), - Call(3), - ChannelNameChange(4), - ChannelIconChange(5), - ChannelPinnedMessage(6), - GuildMemberJoin(7), - UserPremiumGuildSubscription(8), - UserPremiumGuildSubscriptionTierOne(9), - UserPremiumGuildSubscriptionTwo(10), - UserPremiumGuildSubscriptionThree(11), - ChannelFollowAdd(12), - GuildDiscoveryDisqualified(14), + class Unknown(code: Int) : MessageType(code) + object Default : MessageType(0) + object RecipientAdd : MessageType(1) + object RecipientRemove : MessageType(2) + object Call : MessageType(3) + object ChannelNameChange : MessageType(4) + object ChannelIconChange : MessageType(5) + object ChannelPinnedMessage : MessageType(6) + object GuildMemberJoin : MessageType(7) + object UserPremiumGuildSubscription : MessageType(8) + object UserPremiumGuildSubscriptionTierOne : MessageType(9) + object UserPremiumGuildSubscriptionTwo : MessageType(10) + object UserPremiumGuildSubscriptionThree : MessageType(11) + object ChannelFollowAdd : MessageType(12) + object GuildDiscoveryDisqualified : MessageType(14) @Suppress("SpellCheckingInspection") - GuildDiscoveryRequalified(15), - Reply(19); + object GuildDiscoveryRequalified : MessageType(15) + object GuildDiscoveryGracePeriodInitialWarning : MessageType(16) + object GuildDiscoveryGracePeriodFinalWarning : MessageType(17) + object ThreadCreated : MessageType(18) + object Reply : MessageType(19) + object ApplicationCommand : MessageType(20) + object ThreadStarterMessage : MessageType(21) + object GuildInviteReminder : MessageType(22) - companion object MessageTypeSerializer : KSerializer { + internal object MessageTypeSerializer : KSerializer { override val descriptor: SerialDescriptor get() = PrimitiveSerialDescriptor("type", PrimitiveKind.INT) override fun deserialize(decoder: Decoder): MessageType { val code = decoder.decodeInt() - return values().firstOrNull { it.code == code } ?: Unknown + return values.firstOrNull { it.code == code } ?: Unknown(code) } override fun serialize(encoder: Encoder, value: MessageType) { encoder.encodeInt(value.code) } } + + companion object { + val values: Set + get() = setOf( + Default, + RecipientAdd, + RecipientRemove, + Call, + ChannelNameChange, + ChannelIconChange, + ChannelPinnedMessage, + GuildMemberJoin, + UserPremiumGuildSubscription, + UserPremiumGuildSubscriptionTierOne, + UserPremiumGuildSubscriptionTwo, + UserPremiumGuildSubscriptionThree, + ChannelFollowAdd, + GuildDiscoveryDisqualified, + GuildDiscoveryRequalified, + Reply, + GuildDiscoveryGracePeriodInitialWarning, + GuildDiscoveryGracePeriodFinalWarning, + ThreadCreated, + ApplicationCommand, + ThreadStarterMessage, + GuildInviteReminder, + + ) + } } @Serializable(with = AllowedMentionType.Serializer::class) diff --git a/core/src/main/kotlin/Unsafe.kt b/core/src/main/kotlin/Unsafe.kt index dc3edb0017e..b09c1e206ba 100644 --- a/core/src/main/kotlin/Unsafe.kt +++ b/core/src/main/kotlin/Unsafe.kt @@ -6,6 +6,7 @@ import dev.kord.common.annotation.KordUnsafe import dev.kord.common.entity.Snowflake import dev.kord.core.behavior.* import dev.kord.core.behavior.channel.* +import dev.kord.rest.service.InteractionService /** * A class that exposes the creation of `{Entity}Behavior` classes. @@ -71,4 +72,20 @@ class Unsafe(private val kord: Kord) { return "Unsafe" } + fun guildApplicationCommand( + guildId: Snowflake, + applicationId: Snowflake, + commandId: Snowflake, + service: InteractionService = kord.rest.interaction + ): GuildApplicationCommandBehavior = + GuildApplicationCommandBehavior(guildId, applicationId, commandId, service) + + fun globalApplicationCommand( + applicationId: Snowflake, + commandId: Snowflake, + service: InteractionService = kord.rest.interaction + ): GlobalApplicationCommandBehavior = + GlobalApplicationCommandBehavior(applicationId, commandId, service) + + } \ No newline at end of file diff --git a/core/src/main/kotlin/behavior/GlobalApplicationCommandBehavior.kt b/core/src/main/kotlin/behavior/GlobalApplicationCommandBehavior.kt index 9c3168ed4a0..72a0d953b6e 100644 --- a/core/src/main/kotlin/behavior/GlobalApplicationCommandBehavior.kt +++ b/core/src/main/kotlin/behavior/GlobalApplicationCommandBehavior.kt @@ -79,4 +79,37 @@ interface GuildApplicationCommandBehavior : ApplicationCommandBehavior { override suspend fun delete() { service.deleteGuildApplicationCommand(applicationId, guildId, id) } + +} + +@KordPreview +fun GuildApplicationCommandBehavior( + guildId: Snowflake, + applicationId: Snowflake, + id: Snowflake, + service: InteractionService +): GuildApplicationCommandBehavior = object : GuildApplicationCommandBehavior { + override val guildId: Snowflake + get() = guildId + override val applicationId: Snowflake + get() = applicationId + override val service: InteractionService + get() = service + override val id: Snowflake + get() = id } + + +@KordPreview +fun GlobalApplicationCommandBehavior( + applicationId: Snowflake, + id: Snowflake, + service: InteractionService +): GlobalApplicationCommandBehavior = object : GlobalApplicationCommandBehavior { + override val applicationId: Snowflake + get() = applicationId + override val service: InteractionService + get() = service + override val id: Snowflake + get() = id +} \ No newline at end of file