Skip to content

Commit

Permalink
First attempt to build Kord with K2
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Nov 17, 2023
1 parent d7edcc5 commit 9f34aaa
Show file tree
Hide file tree
Showing 27 changed files with 1,594 additions and 1,570 deletions.
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ object Jvm {

fun KotlinCommonCompilerOptions.applyKordCompilerOptions() {
allWarningsAsErrors = true
progressiveMode = true
// there seems to be a problem for now with progressive mode
// progressiveMode = true
freeCompilerArgs.add("-Xexpect-actual-classes")
// TODO change individual Suppress annotations instead
freeCompilerArgs.add("-Xdont-warn-on-error-suppression")
}

fun KotlinSourceSet.applyKordOptIns() {
Expand Down
1,175 changes: 590 additions & 585 deletions common/api/common.api

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions common/src/commonMain/kotlin/entity/Interactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public sealed class Option {
ApplicationCommandOptionType.User -> CommandArgument.Serializer.deserialize(
json, jsonValue!!, name, type!!, focused
)
null, is ApplicationCommandOptionType.Unknown -> error("unknown ApplicationCommandOptionType $type")
is ApplicationCommandOptionType.Unknown -> error("unknown ApplicationCommandOptionType $type")
}
}

Expand Down Expand Up @@ -601,7 +601,7 @@ public sealed class CommandArgument<out T> : Option() {
is AutoCompleteArgument, is StringArgument -> encodeStringElement(
descriptor,
1,
value.value as String
value.value
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions common/src/nonJvmMain/kotlin/Class.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import dev.kord.common.annotation.KordInternal
import kotlin.reflect.KClass

/** @suppress */
@Suppress("ACTUAL_WITHOUT_EXPECT")
public actual typealias Class<T> = KClass<T>
public actual typealias Class<T> = ArrayDeque<T>

/** @suppress */
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
@KordInternal
public actual inline val <T : Any> KClass<T>.java: Class<T> inline get() = this
public actual inline val <T : Any> KClass<T>.java: Class<T>
inline get() = throw UnsupportedOperationException("'getDeclaringClass()' was never present on Kotlin/JS")
735 changes: 370 additions & 365 deletions core/api/core.api

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions core/src/commonMain/kotlin/Kord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ public class Kord(
* Logs in to the configured [Gateways][Gateway]. Suspends until [logout] or [shutdown] is called.
*/
public suspend inline fun login(builder: LoginBuilder.() -> Unit = {}) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
// contract {
// callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
// }
val loginBuilder = LoginBuilder().apply(builder)
gateway.start(resources.token) {
shard = DiscordShard(0, resources.shards.totalShards)
Expand Down Expand Up @@ -163,7 +163,7 @@ public class Kord(
public suspend inline fun updateApplicationRoleConnectionMetadataRecords(
builder: ApplicationRoleConnectionMetadataRecordsBuilder.() -> Unit,
): List<ApplicationRoleConnectionMetadata> {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
// contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
return rest.applicationRoleConnectionMetadata
.updateApplicationRoleConnectionMetadataRecords(selfId, builder)
.map { ApplicationRoleConnectionMetadata(data = it, kord = this) }
Expand Down Expand Up @@ -537,7 +537,7 @@ public class Kord(
builder: GlobalMultiApplicationCommandBuilder.() -> Unit,
): Flow<GlobalApplicationCommand> {

contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
// contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
val commands = rest.interaction.createGlobalApplicationCommands(resources.applicationId, builder)
return flow {
commands.forEach {
Expand Down Expand Up @@ -605,7 +605,7 @@ public class Kord(
guildId: Snowflake,
builder: GuildMultiApplicationCommandBuilder.() -> Unit,
): Flow<GuildApplicationCommand> {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
// contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }

val commands = rest.interaction.createGuildApplicationCommands(resources.applicationId, guildId, builder)

Expand Down
12 changes: 6 additions & 6 deletions core/src/commonMain/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import kotlin.contracts.contract
import kotlin.reflect.KClass

internal inline fun <T> catchNotFound(block: () -> T): T? {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
// contract {
// callsInPlace(block, InvocationKind.EXACTLY_ONCE)
// }
return try {
block()
} catch (exception: RestRequestException) {
Expand All @@ -42,9 +42,9 @@ internal inline fun <T> catchNotFound(block: () -> T): T? {
}

internal inline fun <T> catchDiscordError(vararg codes: JsonErrorCode, block: () -> T): T? {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
// contract {
// callsInPlace(block, InvocationKind.EXACTLY_ONCE)
// }
return try {
block()
} catch (exception: RestRequestException) {
Expand Down
12 changes: 6 additions & 6 deletions core/src/commonMain/kotlin/behavior/GuildBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public suspend inline fun GuildBehavior.createUserCommand(
public suspend inline fun GuildBehavior.createApplicationCommands(
builder: GuildMultiApplicationCommandBuilder.() -> Unit
): Flow<GuildApplicationCommand> {
contract { callsInPlace(builder, EXACTLY_ONCE) }
// contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.createGuildApplicationCommands(id, builder)
}

Expand Down Expand Up @@ -899,9 +899,9 @@ public suspend inline fun GuildBehavior.swapChannelPositions(builder: GuildChann
* @throws [RestRequestException] if something went wrong during the request.
*/
public suspend inline fun GuildBehavior.swapRolePositions(builder: RolePositionsModifyBuilder.() -> Unit): Flow<Role> {
contract {
callsInPlace(builder, EXACTLY_ONCE)
}
// contract {
// callsInPlace(builder, EXACTLY_ONCE)
// }
val response = kord.rest.guild.modifyGuildRolePosition(id, builder)
return response.asFlow().map { RoleData.from(id, it) }.map { Role(it, kord) }

Expand Down Expand Up @@ -933,7 +933,7 @@ public suspend inline fun GuildBehavior.ban(userId: Snowflake, builder: BanCreat
contract {
callsInPlace(builder, EXACTLY_ONCE)
}
kord.rest.guild.addGuildBan(guildId = id, userId = userId, builder = builder)
kord.rest.guild.addGuildBan(guildId = id, userId = userId, builder)
}

/**
Expand Down Expand Up @@ -1000,7 +1000,7 @@ public suspend inline fun GuildBehavior.editOnboarding(
* ```
*/
public inline fun GuildBehavior.getAuditLogEntries(builder: AuditLogGetRequestBuilder.() -> Unit = {}): Flow<AuditLogEntry> {
contract { callsInPlace(builder, EXACTLY_ONCE) }
// contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.with(rest).getAuditLogEntries(id, builder).map { AuditLogEntry(it, kord) }
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/commonMain/kotlin/behavior/MessageBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public suspend inline fun MessageBehavior.edit(builder: UserMessageModifyBuilder
}

val response =
kord.rest.channel.editMessage(channelId = channelId, messageId = id, builder = builder)
kord.rest.channel.editMessage(channelId = channelId, messageId = id, builder)
val data = MessageData.from(response)

return Message(data, kord)
Expand All @@ -276,9 +276,9 @@ public suspend inline fun MessageBehavior.edit(
threadId: Snowflake? = null,
builder: WebhookMessageModifyBuilder.() -> Unit
): Message {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
// contract {
// callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
// }
val response = kord.rest.webhook.editWebhookMessage(webhookId, token, messageId = id, threadId, builder)
val data = MessageData.from(response)
return Message(data, kord)
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/behavior/RoleBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public suspend inline fun RoleBehavior.edit(builder: RoleModifyBuilder.() -> Uni
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
val response = kord.rest.guild.modifyGuildRole(guildId = guildId, roleId = id, builder = builder)
val response = kord.rest.guild.modifyGuildRole(guildId = guildId, roleId = id, builder)
val data = RoleData.from(id, response)

return Role(data, kord)
Expand Down
12 changes: 6 additions & 6 deletions core/src/commonMain/kotlin/behavior/WebhookBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public suspend inline fun WebhookBehavior.execute(
threadId: Snowflake? = null,
builder: WebhookMessageCreateBuilder.() -> Unit,
): Message {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
// contract {
// callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
// }
val response = kord.rest.webhook.executeWebhook(id, token, wait = true, threadId, builder)!!
val data = MessageData.from(response)
return Message(data, kord)
Expand All @@ -184,8 +184,8 @@ public suspend inline fun WebhookBehavior.executeIgnored(
threadId: Snowflake? = null,
builder: WebhookMessageCreateBuilder.() -> Unit,
) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
// contract {
// callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
// }
kord.rest.webhook.executeWebhook(id, token, wait = false, threadId, builder)
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public suspend inline fun TopGuildChannelBehavior.editRolePermission(
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
kord.rest.channel.editRolePermission(channelId = id, roleId = roleId, builder = builder)
kord.rest.channel.editRolePermission(channelId = id, roleId = roleId, builder)
}

/**
Expand All @@ -143,5 +143,5 @@ public suspend inline fun TopGuildChannelBehavior.editMemberPermission(
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
kord.rest.channel.editMemberPermissions(channelId = id, memberId = memberId, builder = builder)
kord.rest.channel.editMemberPermissions(channelId = id, memberId = memberId, builder)
}
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
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/entity/Emoji.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class GuildEmoji(
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
kord.rest.emoji.modifyEmoji(guildId = guildId, emojiId = id, builder = builder)
kord.rest.emoji.modifyEmoji(guildId = guildId, emojiId = id, builder)
}

/**
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 9f34aaa

Please sign in to comment.