Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message interaction #283

Merged
merged 10 commits into from
May 15, 2021
4 changes: 2 additions & 2 deletions core/src/main/kotlin/cache/data/MessageInteractionData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ data class MessageInteractionData(
val id:Snowflake,
val type:InteractionType,
val name:String,
val user:UserData
val user: Snowflake
) {
companion object {
fun from(entity: DiscordMessageInteraction): MessageInteractionData = with(entity) {
MessageInteractionData(id, type, name, user.toData())
MessageInteractionData(id, type, name, user.id)
}
}
}
3 changes: 3 additions & 0 deletions core/src/main/kotlin/entity/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class Message(
*/
val mentionedUserBehaviors: Set<UserBehavior> get() = data.mentions.map { UserBehavior(it, kord) }.toSet()

/**
* The [MessageInteraction] sent on this message object when it is a response to an [dev.kord.core.entity.interaction.Interaction].
*/
@KordPreview
val interaction: MessageInteraction? get() = data.messageInteraction.mapNullable { MessageInteraction(it, kord) }.value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider documenting this


Expand Down
29 changes: 26 additions & 3 deletions core/src/main/kotlin/entity/interaction/MessageInteraction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,36 @@ import dev.kord.common.annotation.KordPreview
import dev.kord.common.entity.InteractionType
import dev.kord.common.entity.Snowflake
import dev.kord.core.Kord
import dev.kord.core.behavior.UserBehavior
import dev.kord.core.entity.KordEntity
import dev.kord.core.entity.User
import dev.kord.core.entity.Message

/**
* An instance of [MessageInteraction](https://discord.com/developers/docs/interactions/slash-commands#messageinteraction)
* This is sent on the [Message] object when the message is a response to an [Interaction].
*/
@KordPreview
class MessageInteraction(val data: MessageInteractionData, override val kord: Kord): KordEntity {
class MessageInteraction(
val data: MessageInteractionData,
override val kord: Kord,
) : KordEntity {
/**
* [id][Interaction.id] of the [Interaction] this message is responding to.
*/
override val id: Snowflake get() = data.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the interactions's ID, right? Is there any kind of behavior/entity we can get from this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there isn't but since it had an ID and requires Kord for the user object that it would be fine to consider it a KordEntity


/**
* the [name][ApplicationCommand.name] of the [ApplicationCommand] that triggered this message.
*/
val name: String get() = data.name
val user: User get() = User(data.user, kord)

/**
* The [UserBehavior] of the [user][Interaction.user] who invoked the [Interaction]
*/
val user: UserBehavior get() = UserBehavior(data.id, kord)
Comment on lines +37 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs the usual getUser and getUserOrNull


/**
* the [InteractionType] of the interaction [MessageInteraction].
*/
val type: InteractionType get() = data.type
}