-
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.
* Add low-level implementation of stage instances * Add helper functions * Add core entities and api representations * Expose creation of StageInstanceBehavior to unsafe - Revert outdated change * Final additions - Add StageInstanceBehavior.asStageInstance - Fix compiler issue - Add StageChannelBehavior.getStageInstance() * Add StageInstances to EntitySupplier.kt * Add StageInstances to EntitySupplier.kt * Fix typo * Apply requested changes
- Loading branch information
1 parent
b77f326
commit 60ab212
Showing
17 changed files
with
217 additions
and
3 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
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
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
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
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
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
15 changes: 15 additions & 0 deletions
15
rest/src/main/kotlin/json/request/StageInstanceRequests.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,15 @@ | ||
package dev.kord.rest.json.request | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class StageInstanceCreateRequest( | ||
@SerialName("channel_id") | ||
val channelId: Snowflake, | ||
val topic: String | ||
) | ||
|
||
@Serializable | ||
data class StageInstanceUpdateRequest(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
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,39 @@ | ||
package dev.kord.rest.service | ||
|
||
import dev.kord.common.entity.DiscordStageInstance | ||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.rest.json.request.StageInstanceCreateRequest | ||
import dev.kord.rest.json.request.StageInstanceUpdateRequest | ||
import dev.kord.rest.request.RequestHandler | ||
import dev.kord.rest.route.Route | ||
|
||
class StageInstanceService(requestHandler: RequestHandler) : RestService(requestHandler) { | ||
suspend fun getStageInstance(channelId: Snowflake): DiscordStageInstance = call(Route.StageInstanceGet) { | ||
keys[Route.ChannelId] = channelId | ||
} | ||
|
||
suspend fun createStageInstance(request: StageInstanceCreateRequest): DiscordStageInstance = | ||
call(Route.StageInstancePost) { | ||
body(StageInstanceCreateRequest.serializer(), request) | ||
} | ||
|
||
suspend fun updateStageInstance(channelId: Snowflake, request: StageInstanceUpdateRequest): DiscordStageInstance = | ||
call(Route.StageInstancePost) { | ||
keys[Route.ChannelId] = channelId | ||
|
||
body(StageInstanceUpdateRequest.serializer(), request) | ||
} | ||
|
||
suspend fun deleteStageInstance(channelId: Snowflake): Unit = call(Route.StageInstanceDelete) { | ||
keys[Route.ChannelId] = channelId | ||
} | ||
} | ||
|
||
suspend fun StageInstanceService.createStageInstance(channelId: Snowflake, topic: String) = createStageInstance( | ||
StageInstanceCreateRequest(channelId, topic) | ||
) | ||
|
||
suspend fun StageInstanceService.updateStageInstance(channelId: Snowflake, topic: String) = updateStageInstance( | ||
channelId, | ||
StageInstanceUpdateRequest(topic) | ||
) |