Skip to content

Commit

Permalink
Build Kord with K2
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Feb 13, 2024
1 parent 58a2ba0 commit 76324dc
Show file tree
Hide file tree
Showing 28 changed files with 1,570 additions and 1,570 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.gradle/
.idea/*
!.idea/icon.png
out/
.kotlin/

**/build/*
!**/build/generated/
Expand Down
1,180 changes: 590 additions & 590 deletions common/api/common.api

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/src/commonMain/kotlin/entity/Interactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public sealed class CommandArgument<out T> : Option() {
is AutoCompleteArgument, is StringArgument -> encodeStringElement(
descriptor,
1,
value.value as String
value.value
)
}
}
Expand Down
730 changes: 365 additions & 365 deletions core/api/core.api

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions core/src/commonMain/kotlin/Kord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class Kord(
/**
* Logs in to the configured [Gateways][Gateway]. Suspends until [logout] or [shutdown] is called.
*/
@Suppress("WRONG_INVOCATION_KIND") // because of https://youtrack.jetbrains.com/issue/KT-63414
public suspend inline fun login(builder: LoginBuilder.() -> Unit = {}) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
Expand Down Expand Up @@ -165,6 +166,7 @@ public class Kord(
*
* @throws RestRequestException if something went wrong during the request.
*/
@Suppress("WRONG_INVOCATION_KIND") // because of https://youtrack.jetbrains.com/issue/KT-63414
public suspend inline fun updateApplicationRoleConnectionMetadataRecords(
builder: ApplicationRoleConnectionMetadataRecordsBuilder.() -> Unit,
): List<ApplicationRoleConnectionMetadata> {
Expand Down Expand Up @@ -526,6 +528,7 @@ public class Kord(
}


@Suppress("WRONG_INVOCATION_KIND") // because of https://youtrack.jetbrains.com/issue/KT-63414
public suspend inline fun createGlobalApplicationCommands(
builder: GlobalMultiApplicationCommandBuilder.() -> Unit,
): Flow<GlobalApplicationCommand> {
Expand Down Expand Up @@ -594,6 +597,7 @@ public class Kord(
}


@Suppress("WRONG_INVOCATION_KIND") // because of https://youtrack.jetbrains.com/issue/KT-63414
public suspend inline fun createGuildApplicationCommands(
guildId: Snowflake,
builder: GuildMultiApplicationCommandBuilder.() -> Unit,
Expand Down
6 changes: 4 additions & 2 deletions core/src/commonMain/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import kotlin.contracts.contract
import kotlin.reflect.KClass

internal inline fun <T> catchNotFound(block: () -> T): T? {
// AT_MOST_ONCE, see https://youtrack.jetbrains.com/issue/KT-63414
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
return try {
block()
Expand All @@ -41,8 +42,9 @@ internal inline fun <T> catchNotFound(block: () -> T): T? {
}

internal inline fun <T> catchDiscordError(vararg codes: JsonErrorCode, block: () -> T): T? {
// AT_MOST_ONCE, see https://youtrack.jetbrains.com/issue/KT-63414
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
return try {
block()
Expand Down
2 changes: 2 additions & 0 deletions core/src/commonMain/kotlin/behavior/GuildBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ public suspend inline fun GuildBehavior.swapChannelPositions(builder: GuildChann
*
* @throws [RestRequestException] if something went wrong during the request.
*/
@Suppress("WRONG_INVOCATION_KIND") // because of https://youtrack.jetbrains.com/issue/KT-63414
public suspend inline fun GuildBehavior.swapRolePositions(builder: RolePositionsModifyBuilder.() -> Unit): Flow<Role> {
contract {
callsInPlace(builder, EXACTLY_ONCE)
Expand Down Expand Up @@ -999,6 +1000,7 @@ public suspend inline fun GuildBehavior.editOnboarding(
* println("user changed nickname from $old to $new")
* ```
*/
@Suppress("WRONG_INVOCATION_KIND") // because of https://youtrack.jetbrains.com/issue/KT-63414
public inline fun GuildBehavior.getAuditLogEntries(builder: AuditLogGetRequestBuilder.() -> Unit = {}): Flow<AuditLogEntry> {
contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.with(rest).getAuditLogEntries(id, builder).map { AuditLogEntry(it, kord) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ public suspend inline fun MessageChannelBehavior.createEmbed(block: EmbedBuilder
* @throws RestRequestException if something went wrong during a [type][MessageChannelBehavior.type] request.
*/
public suspend fun <T : MessageChannelBehavior, R> T.withTyping(block: suspend T.() -> R): R {
// see contract in `coroutineScope {}`
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }

type() // guarantees that the typing indicator is triggered before `block` is called
return coroutineScope {
val typingJob = launch {
Expand Down
1 change: 0 additions & 1 deletion core/src/commonMain/kotlin/builder/kord/KordBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public abstract class BaseKordBuilder internal constructor(public val token: Str
* ```
*/
public fun cache(builder: KordCacheBuilder.(resources: ClientResources) -> Unit) {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
val old = cacheBuilder
cacheBuilder = { resources: ClientResources ->
old(resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public fun OptionValue(value: CommandArgument<*>, resolvedObjects: ResolvedObjec
is CommandArgument.BooleanArgument -> BooleanOptionValue(value.value, focused)
is CommandArgument.IntegerArgument -> IntegerOptionValue(value.value, focused)
is CommandArgument.StringArgument, is CommandArgument.AutoCompleteArgument ->
StringOptionValue(value.value as String, focused)
StringOptionValue(value.value, focused)
is CommandArgument.ChannelArgument -> {
val channel = resolvedObjects?.channels.orEmpty()[value.value]
ChannelOptionValue(value.value, focused, channel)
Expand Down
Loading

0 comments on commit 76324dc

Please sign in to comment.