-
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.
* Fix collection in 1.6.0 * revamp message sticker model * Add sticker endpoints and services * Add core representation for Stickers * implement suppliers for stickers and cache * allow Stickers to be have a strategy * Introduce a GuildSticker with behavior * Fix compiler errors * Fix compiler errors, again * Fix modeling of description to packId
- Loading branch information
Showing
23 changed files
with
614 additions
and
241 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
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,57 @@ | ||
package dev.kord.core.behavior | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kord.core.Kord | ||
import dev.kord.core.cache.data.StickerData | ||
import dev.kord.core.entity.KordEntity | ||
import dev.kord.core.entity.Sticker | ||
import dev.kord.core.entity.Strategizable | ||
import dev.kord.core.supplier.EntitySupplier | ||
import dev.kord.core.supplier.EntitySupplyStrategy | ||
import dev.kord.rest.builder.guild.StickerModifyBuilder | ||
import kotlin.contracts.ExperimentalContracts | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
public interface StickerBehavior : KordEntity, Strategizable { | ||
|
||
public val guildId: Snowflake | ||
|
||
public suspend fun delete() { | ||
return kord.rest.sticker.deleteSticker(guildId, id) | ||
} | ||
|
||
public suspend fun asSticker(): Sticker = supplier.getSticker(id) | ||
|
||
public suspend fun asStickerOrNull(): Sticker? = supplier.getStickerOrNull(id) | ||
|
||
public suspend fun fetchSticker(): Sticker = supplier.getSticker(id) | ||
|
||
public suspend fun fetchStickerOrNull(): Sticker? = supplier.getStickerOrNull(id) | ||
|
||
} | ||
|
||
public fun StickerBehavior(guildId: Snowflake, id: Snowflake, kord: Kord, supplier: EntitySupplier): StickerBehavior = | ||
object : StickerBehavior { | ||
override val guildId: Snowflake | ||
get() = guildId | ||
override val id: Snowflake | ||
get() = id | ||
override val kord: Kord | ||
get() = kord | ||
|
||
override val supplier: EntitySupplier | ||
get() = supplier | ||
|
||
override fun withStrategy(strategy: EntitySupplyStrategy<*>): StickerBehavior = | ||
StickerBehavior(guildId, id, kord, strategy.supply(kord)) | ||
|
||
} | ||
|
||
@OptIn(ExperimentalContracts::class) | ||
public suspend inline fun StickerBehavior.edit(builder: StickerModifyBuilder.() -> Unit): Sticker { | ||
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } | ||
val response = kord.rest.sticker.modifyGuildSticker(guildId, id, builder) | ||
val data = StickerData.from(response) | ||
return Sticker(data, 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.