Skip to content

Commit

Permalink
Add ActionInteractionCreateEvent (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi authored Dec 23, 2021
1 parent 7e5aa06 commit 06bb870
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
6 changes: 3 additions & 3 deletions core/src/main/kotlin/entity/interaction/ActionInteraction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@ public sealed interface GlobalInteraction : Interaction {
/**
* An [ActionInteraction] that took place in a Global Context with [GlobalApplicationCommand].
*/
public sealed interface GlobalApplicationCommandInteraction : ApplicationCommandInteraction, GlobalInteraction {
public sealed interface GlobalApplicationCommandInteraction : ApplicationCommandInvocationInteraction, GlobalInteraction {
/**
* The user who invoked the interaction.
*/
override fun withStrategy(strategy: EntitySupplyStrategy<*>): GlobalApplicationCommandInteraction =
GlobalApplicationCommandInteraction(data, kord, strategy.supply(kord))

override val applicationId: Snowflake
get() = super<ApplicationCommandInteraction>.applicationId
get() = super<ApplicationCommandInvocationInteraction>.applicationId
}

public fun GlobalApplicationCommandInteraction(
Expand All @@ -357,7 +357,7 @@ public fun GlobalApplicationCommandInteraction(
*/


public sealed interface GuildApplicationCommandInteraction : ApplicationCommandInteraction, GuildInteractionBehavior {
public sealed interface GuildApplicationCommandInteraction : ApplicationCommandInvocationInteraction, GuildInteractionBehavior {

override val guildId: Snowflake
get() = data.guildId.value!!
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/kotlin/entity/interaction/ContextInteraction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ import dev.kord.core.supplier.EntitySupplyStrategy
import java.util.Objects

/**
* Represents an interaction of type [ApplicationCommand][dev.kord.common.entity.InteractionType.ApplicationCommand]
* Interaction which contains a contains command data.
*/
public sealed interface ApplicationCommandInteraction : Interaction, ApplicationCommandInteractionBehavior {
public val invokedCommandId: Snowflake get() = data.data.id.value!!

public val name: String get() = data.data.name.value!!

}

/**
* Represents an interaction of type [ApplicationCommand][dev.kord.common.entity.InteractionType.ApplicationCommand]
*/
public sealed interface ApplicationCommandInvocationInteraction : ActionInteraction, ApplicationCommandInteraction {
public val invokedCommandType: ApplicationCommandType get() = data.data.type.value!!

public val resolvedObjects: ResolvedObjects?
Expand All @@ -44,7 +50,7 @@ public sealed interface ChatInputCommandInteraction : Interaction {
/**
* An [ApplicationCommandInteraction] that's invoked through chat input.
*/
public sealed interface ChatInputCommandInvocationInteraction : ChatInputCommandInteraction, ApplicationCommandInteraction
public sealed interface ChatInputCommandInvocationInteraction : ChatInputCommandInteraction, ApplicationCommandInvocationInteraction


/**
Expand Down Expand Up @@ -88,7 +94,7 @@ public class GlobalChatInputCommandInteraction(
/**
* An [ApplicationCommandInteraction] that's invoked through user commands.
*/
public sealed interface UserCommandInteraction : ApplicationCommandInteraction {
public sealed interface UserCommandInteraction : ApplicationCommandInvocationInteraction {

public val targetId: Snowflake get() = data.data.targetId.value!!

Expand Down Expand Up @@ -141,7 +147,7 @@ public class GlobalUserCommandInteraction(
/**
* An [ApplicationCommandInteraction] that's invoked through messages.
*/
public sealed interface MessageCommandInteraction : ApplicationCommandInteraction {
public sealed interface MessageCommandInteraction : ApplicationCommandInvocationInteraction {

public val targetId: Snowflake get() = data.data.targetId.value!!

Expand Down
25 changes: 6 additions & 19 deletions core/src/main/kotlin/event/interaction/ApplicationCreate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,7 @@ import dev.kord.core.behavior.interaction.followUp
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.behavior.interaction.respondPublic
import dev.kord.core.entity.application.ApplicationCommand
import dev.kord.core.entity.interaction.ActionInteraction
import dev.kord.core.entity.interaction.ApplicationCommandInteraction
import dev.kord.core.entity.interaction.AutoCompleteInteraction
import dev.kord.core.entity.interaction.ChatInputCommandInvocationInteraction
import dev.kord.core.entity.interaction.GlobalApplicationCommandInteraction
import dev.kord.core.entity.interaction.GlobalAutoCompleteInteraction
import dev.kord.core.entity.interaction.GlobalChatInputCommandInteraction
import dev.kord.core.entity.interaction.GlobalMessageCommandInteraction
import dev.kord.core.entity.interaction.GlobalUserCommandInteraction
import dev.kord.core.entity.interaction.GuildApplicationCommandInteraction
import dev.kord.core.entity.interaction.GuildAutoCompleteInteraction
import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction
import dev.kord.core.entity.interaction.GuildMessageCommandInteraction
import dev.kord.core.entity.interaction.GuildUserCommandInteraction
import dev.kord.core.entity.interaction.MessageCommandInteraction
import dev.kord.core.entity.interaction.UserCommandInteraction
import dev.kord.core.entity.interaction.*
import dev.kord.core.event.kordCoroutineScope
import kotlinx.coroutines.CoroutineScope

Expand Down Expand Up @@ -53,8 +38,8 @@ import kotlinx.coroutines.CoroutineScope
* In the current iteration, ephemeral messages (regardless of the type) don't support files and/or embeds.
*/

public sealed interface ApplicationInteractionCreateEvent : InteractionCreateEvent {
override val interaction: ApplicationCommandInteraction
public sealed interface ApplicationInteractionCreateEvent : ActionInteractionCreateEvent {
override val interaction: ApplicationCommandInvocationInteraction
}

public sealed interface GlobalApplicationInteractionCreateEvent : ApplicationInteractionCreateEvent {
Expand Down Expand Up @@ -128,7 +113,9 @@ public class GlobalChatInputCommandInteractionCreateEvent(
*
* @see AutoCompleteInteraction
*/
public sealed interface AutoCompleteInteractionCreateEvent : InteractionCreateEvent
public sealed interface AutoCompleteInteractionCreateEvent : DataInteractionCreateEvent {
override val interaction: AutoCompleteInteraction
}

internal fun AutoCompleteInteractionCreateEvent(
interaction: AutoCompleteInteraction,
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/kotlin/event/interaction/InteractionCreate.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package dev.kord.core.event.interaction

import dev.kord.core.entity.interaction.ActionInteraction
import dev.kord.core.entity.interaction.DataInteraction
import dev.kord.core.entity.interaction.Interaction
import dev.kord.core.event.Event

public sealed interface InteractionCreateEvent : Event {
public val interaction: Interaction
}

public sealed interface ActionInteractionCreateEvent : InteractionCreateEvent {
override val interaction: ActionInteraction
}

public sealed interface DataInteractionCreateEvent : InteractionCreateEvent {
override val interaction: DataInteraction
}

0 comments on commit 06bb870

Please sign in to comment.