-
Notifications
You must be signed in to change notification settings - Fork 81
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
Message interaction #283
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
46ce222
Expose the creation of application commands behavior
HopeBaron 9845a9e
Merge branch '0.7.x' of https://github.com/kordlib/kord into 0.7.x
HopeBaron ffc820e
Add interaction message
HopeBaron e0beb76
Apply suggestions
HopeBaron 2eb43db
reference the MessageInteraction in docs
HopeBaron 9c05902
Implement Strategizable for MessageInteraction
HopeBaron 52aec9c
cache user from interaction message
HopeBaron 109a947
Fix compilation errors
HopeBaron 3eee684
Fix withStrategy return type
HopeBaron 960c6f5
Merge branch '0.7.x' into message-interaction
HopeBaron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cache.data; | ||
|
||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.entity.DiscordMessageInteraction | ||
import dev.kord.common.entity.InteractionType | ||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.cache.data.UserData | ||
import dev.kord.core.cache.data.toData | ||
import kotlinx.serialization.Serializable | ||
|
||
@KordPreview | ||
@Serializable | ||
data class MessageInteractionData( | ||
val id:Snowflake, | ||
val type:InteractionType, | ||
val name:String, | ||
val user: Snowflake | ||
) { | ||
companion object { | ||
fun from(entity: DiscordMessageInteraction): MessageInteractionData = with(entity) { | ||
MessageInteractionData(id, type, name, user.id) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/main/kotlin/entity/interaction/MessageInteraction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package dev.kord.core.entity.interaction | ||
|
||
import cache.data.MessageInteractionData | ||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.entity.InteractionType | ||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.common.exception.RequestException | ||
import dev.kord.core.Kord | ||
import dev.kord.core.behavior.UserBehavior | ||
import dev.kord.core.entity.KordEntity | ||
import dev.kord.core.entity.Message | ||
import dev.kord.core.entity.Strategizable | ||
import dev.kord.core.entity.User | ||
import dev.kord.core.exception.EntityNotFoundException | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
|
||
/** | ||
* 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, | ||
override val supplier: EntitySupplier = kord.defaultSupplier | ||
) : KordEntity, Strategizable { | ||
/** | ||
* [id][Interaction.id] of the [Interaction] this message is responding to. | ||
*/ | ||
override val id: Snowflake get() = data.id | ||
|
||
/** | ||
* the [name][ApplicationCommand.name] of the [ApplicationCommand] that triggered this message. | ||
*/ | ||
val name: String get() = data.name | ||
|
||
/** | ||
* 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs the usual |
||
|
||
/** | ||
* the [InteractionType] of the interaction [MessageInteraction]. | ||
*/ | ||
val type: InteractionType get() = data.type | ||
|
||
/** | ||
* Requests the [User] of this interaction message. | ||
* | ||
* @throws RequestException if something went wrong while retrieving the user. | ||
* @throws EntityNotFoundException if the user was null. | ||
*/ | ||
suspend fun getUser(): User = supplier.getUser(user.id) | ||
|
||
/** | ||
* Requests to get the user of this interaction message, | ||
* returns null if the [User] isn't present. | ||
* | ||
* @throws [RequestException] if anything went wrong during the request. | ||
*/ | ||
suspend fun getUserOrNull(): User? = supplier.getUserOrNull(user.id) | ||
|
||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): Strategizable { | ||
HopeBaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return MessageInteraction(data, kord, strategy.supply(kord)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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