-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '0.7.x' into kotlin-1.5
- Loading branch information
Showing
25 changed files
with
351 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.kord.common.entity | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
|
||
/** | ||
* A _Stage Instance_ holds information about a live stage. | ||
* | ||
* @property id The id of this Stage instance | ||
* @property guildId The guild id of the associated Stage channel | ||
* @property channelId The id of the associated Stage channel | ||
* @property topic The topic of the Stage instance (1-120 characters) | ||
*/ | ||
@Serializable | ||
data class DiscordStageInstance( | ||
val id: Snowflake, | ||
@SerialName("guild_id") | ||
val guildId: Snowflake, | ||
@SerialName("channel_id") | ||
val channelId: Snowflake, | ||
val topic: String | ||
) |
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,45 @@ | ||
package dev.kord.core.behavior | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.Kord | ||
import dev.kord.core.cache.data.StageInstanceData | ||
import dev.kord.core.entity.KordEntity | ||
import dev.kord.core.entity.StageInstance | ||
import dev.kord.core.entity.Strategizable | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
import dev.kord.rest.json.request.StageInstanceUpdateRequest | ||
|
||
interface StageInstanceBehavior : KordEntity, Strategizable { | ||
val channelId: Snowflake | ||
|
||
suspend fun delete(): Unit = kord.rest.stageInstance.deleteStageInstance(channelId) | ||
|
||
suspend fun update(topic: String): StageInstance { | ||
val instance = kord.rest.stageInstance.updateStageInstance(channelId, StageInstanceUpdateRequest(topic)) | ||
val data = StageInstanceData.from(instance) | ||
|
||
return StageInstance(data, kord, supplier) | ||
} | ||
|
||
suspend fun asStageInstance(): StageInstance = supplier.getStageInstance(channelId) | ||
|
||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): StageInstanceBehavior = | ||
StageInstanceBehavior(id, channelId, kord, strategy.supply(kord)) | ||
} | ||
|
||
internal fun StageInstanceBehavior(id: Snowflake, channelId: Snowflake, kord: Kord, supplier: EntitySupplier) = | ||
object : StageInstanceBehavior { | ||
override val channelId: Snowflake | ||
get() = channelId | ||
override val kord: Kord | ||
get() = kord | ||
override val id: Snowflake | ||
get() = id | ||
override val supplier: EntitySupplier | ||
get() = supplier | ||
|
||
override fun toString(): String { | ||
return "StageInstanceBehavior(id=$id, channelId=$id, kord=$kord, supplier=$supplier)" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.kord.core.cache.data | ||
|
||
import dev.kord.common.entity.DiscordStageInstance | ||
import dev.kord.common.entity.Snowflake | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class StageInstanceData( | ||
val id: Snowflake, | ||
val guildId: Snowflake, | ||
val channelId: Snowflake, | ||
val topic: String | ||
) { | ||
companion object { | ||
fun from(stageInstance: DiscordStageInstance) = with(stageInstance) { | ||
StageInstanceData(id, guildId, channelId, topic) | ||
} | ||
} | ||
} |
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,19 @@ | ||
package dev.kord.core.entity | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.Kord | ||
import dev.kord.core.behavior.StageInstanceBehavior | ||
import dev.kord.core.cache.data.StageInstanceData | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
|
||
class StageInstance(val data: StageInstanceData, override val kord: Kord, override val supplier: EntitySupplier) : StageInstanceBehavior { | ||
override val id: Snowflake get() = data.id | ||
val guildId: Snowflake get() = data.guildId | ||
override val channelId: Snowflake get() = data.channelId | ||
val topic: String get() = data.topic | ||
|
||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): StageInstanceBehavior = | ||
StageInstance(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
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) | ||
|
||
/** | ||
* 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<*>): MessageInteraction { | ||
return MessageInteraction(data, kord, strategy.supply(kord)) | ||
} | ||
} |
Oops, something went wrong.