-
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
Message interaction #283
Changes from 3 commits
46ce222
9845a9e
ffc820e
e0beb76
2eb43db
9c05902
52aec9c
109a947
3eee684
960c6f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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:UserData | ||
) { | ||
companion object { | ||
fun from(entity: DiscordMessageInteraction): MessageInteractionData = with(entity) { | ||
MessageInteractionData(id, type, name, user.toData()) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package dev.kord.core.entity | ||
|
||
import dev.kord.common.annotation.KordPreview | ||
import dev.kord.common.entity.MessageType | ||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.common.entity.optional.map | ||
import dev.kord.common.entity.optional.mapNullable | ||
import dev.kord.common.entity.optional.orEmpty | ||
import dev.kord.common.exception.RequestException | ||
import dev.kord.core.Kord | ||
|
@@ -13,6 +16,7 @@ import dev.kord.core.entity.channel.Channel | |
import dev.kord.core.entity.channel.GuildChannel | ||
import dev.kord.core.entity.channel.GuildMessageChannel | ||
import dev.kord.core.entity.channel.MessageChannel | ||
import dev.kord.core.entity.interaction.MessageInteraction | ||
import dev.kord.core.exception.EntityNotFoundException | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
|
@@ -174,6 +178,9 @@ class Message( | |
*/ | ||
val mentionedUserBehaviors: Set<UserBehavior> get() = data.mentions.map { UserBehavior(it, kord) }.toSet() | ||
|
||
@KordPreview | ||
val interaction: MessageInteraction? get() = data.messageInteraction.mapNullable { MessageInteraction(it, kord) }.value | ||
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. Consider documenting this |
||
|
||
/** | ||
* The [users][User] mentioned in this message. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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.core.Kord | ||
import dev.kord.core.entity.KordEntity | ||
import dev.kord.core.entity.User | ||
|
||
@KordPreview | ||
class MessageInteraction(val data: MessageInteractionData, override val kord: Kord): KordEntity { | ||
override val id: Snowflake get() = data.id | ||
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 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 commentThe 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 |
||
val name: String get() = data.name | ||
val user: User get() = User(data.user, kord) | ||
val type: InteractionType get() = data.type | ||
} | ||
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. Consider documenting 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.
Flatten this out to the user id
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.
I applied the user data based on #147.
But I guess that's not the scope for this PR will turn this into the user id.