Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package dev.kord.core.entity
import dev.kord.common.entity.*
import dev.kord.common.entity.MessageType.RoleSubscriptionPurchase
import dev.kord.common.entity.optional.mapNullable
import dev.kord.common.entity.optional.orEmpty
import dev.kord.common.entity.optional.unwrap
import dev.kord.common.entity.optional.value
import dev.kord.common.exception.RequestException
import dev.kord.core.Kord
import dev.kord.core.behavior.MessageBehavior
import dev.kord.core.behavior.UserBehavior
import dev.kord.core.behavior.channel.ChannelBehavior
import dev.kord.core.behavior.interaction.response.InteractionResponseBehavior
import dev.kord.core.cache.data.MessageData
import dev.kord.core.cache.data.MessageInteractionData
import dev.kord.core.entity.application.ApplicationCommand
import dev.kord.core.entity.channel.Channel
import dev.kord.core.entity.channel.GuildChannel
import dev.kord.core.entity.channel.MessageChannel
import dev.kord.core.entity.channel.TopGuildMessageChannel
import dev.kord.core.entity.component.ActionRowComponent
import dev.kord.core.entity.interaction.ActionInteraction
import dev.kord.core.entity.interaction.followup.FollowupMessage
import dev.kord.core.exception.EntityNotFoundException
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.core.supplier.getChannelOf
import dev.kord.core.supplier.getChannelOfOrNull
import kotlinx.coroutines.flow.*
import kotlinx.datetime.Instant
import dev.kord.core.hash
/**
* An instance of a [Discord Message][https://discord.com/developers/docs/resources/channel#message-object].
*/
public class Message(
public val data: MessageData,
override val kord: Kord,
override val supplier: EntitySupplier = kord.defaultSupplier,
) : MessageBehavior {
/**
* An instance of [MessageInteraction](https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object)
*
* This is sent on the [Message] object when the message is a response to an [ActionInteraction].
*/
public class Interaction(
public val data: MessageInteractionData,
override val kord: Kord,
override val supplier: EntitySupplier = kord.defaultSupplier
) : KordEntity, Strategizable {
/** [Id][ActionInteraction.id] of the [ActionInteraction] this message is responding to. */
override val id: Snowflake get() = data.id
/**
* The [name][ApplicationCommand.name] of the [ApplicationCommand] that triggered this message.
* This name includes subcommands and subcommand groups.
*/
public val name: String get() = data.name
/** The [UserBehavior] of the [user][ActionInteraction.user] who invoked the [ActionInteraction]. */
public val user: UserBehavior get() = UserBehavior(data.user, kord)
/** The [InteractionType] of the interaction [Interaction]. */
public 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.
*/
public 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.
*/
public suspend fun getUserOrNull(): User? = supplier.getUserOrNull(user.id)
override fun withStrategy(strategy: EntitySupplyStrategy<*>): Interaction =
Interaction(data, kord, strategy.supply(kord))
}
/**
* The id of this message.
*/
override val id: Snowflake
get() = data.id
/**
* The id of the [MessageChannel] this message was send in.
*/
override val channelId: Snowflake
get() = data.channelId
override suspend fun asMessageOrNull(): Message = this
/**
* The files attached to this message.
*/
public val attachments: Set get() = data.attachments.asSequence().map { Attachment(it, kord) }.toSet()
/**
* The author of this message, if it was created by a [User].
*
* Returns null if the author is not a Discord account, like a [Webhook] or systems message. This also applies to
* [interaction responses][InteractionResponseBehavior] and [followup messages][FollowupMessage] since
* [they are webhooks under the hood](https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction).
*/
public val author: User?
get() = if (data.webhookId.value == data.author.id) null
else User(data.author, kord)
/**
* The content of this message.
*/
public val content: String get() = data.content
/**
* The instant when this message was last edited, if ever.
*
* Returns null if the message was never edited.
*/
public val editedTimestamp: Instant? get() = data.editedTimestamp
/**
* The embedded content of this message.
*
* This includes automatically embedded [videos][Embed.video] and [urls][Embed.Provider].
*/
public val embeds: List