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 Nov 28, 2023
1 parent 1595b95 commit 56b708b
Show file tree
Hide file tree
Showing 37 changed files with 1,629 additions and 1,634 deletions.
1,188 changes: 598 additions & 590 deletions common/api/common.api

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions common/src/commonMain/kotlin/entity/DiscordUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,11 @@ public data class DiscordOptionallyMemberUser(
val member: Optional<DiscordGuildMember> = Optional.Missing(),
)

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DEPRECATION_ERROR")
@Suppress("DEPRECATION_ERROR")
@Deprecated(
"'UserFlags.UserFlagsBuilder' is deprecated, use 'UserFlags.Builder' instead.",
level = DeprecationLevel.HIDDEN,
)
@kotlin.internal.LowPriorityInOverloadResolution
public inline fun UserFlags(builder: UserFlags.UserFlagsBuilder.() -> Unit): UserFlags {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
return UserFlags.UserFlagsBuilder().apply(builder).flags()
Expand Down
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: 2 additions & 4 deletions common/src/commonMain/kotlin/entity/Permission.kt
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,11 @@ public class Permissions internal constructor(
return Builder(code.copy()).apply(builder).build()
}

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DEPRECATION_ERROR")
@Suppress("DEPRECATION_ERROR")
@Deprecated(
"'Permissions.PermissionsBuilder' is deprecated, use 'Permissions.Builder' instead.",
level = DeprecationLevel.HIDDEN,
)
@kotlin.internal.LowPriorityInOverloadResolution
public inline fun copy(block: PermissionsBuilder.() -> Unit): Permissions {
contract { callsInPlace(block, EXACTLY_ONCE) }
return PermissionsBuilder(code.copy()).apply(block).permissions()
Expand Down Expand Up @@ -764,12 +763,11 @@ public inline fun Permissions(builder: Permissions.Builder.() -> Unit = {}): Per
return Permissions.Builder().apply(builder).build()
}

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DEPRECATION_ERROR")
@Suppress("DEPRECATION_ERROR")
@Deprecated(
"'Permissions.PermissionsBuilder' is deprecated, use 'Permissions.Builder' instead.",
level = DeprecationLevel.HIDDEN,
)
@kotlin.internal.LowPriorityInOverloadResolution
public inline fun Permissions(block: Permissions.PermissionsBuilder.() -> Unit = {}): Permissions {
contract { callsInPlace(block, EXACTLY_ONCE) }
return Permissions.PermissionsBuilder(DiscordBitSet(0)).apply(block).permissions()
Expand Down
3 changes: 1 addition & 2 deletions common/src/commonMain/kotlin/entity/UserFlag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,11 @@ public class UserFlags internal constructor(
return Builder(code).apply(builder).build()
}

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "DEPRECATION_ERROR")
@Suppress("DEPRECATION_ERROR")
@Deprecated(
"'UserFlags.UserFlagsBuilder' is deprecated, use 'UserFlags.Builder' instead.",
level = DeprecationLevel.HIDDEN,
)
@kotlin.internal.LowPriorityInOverloadResolution
public inline fun copy(block: UserFlagsBuilder.() -> Unit): UserFlags {
contract { callsInPlace(block, EXACTLY_ONCE) }
return UserFlagsBuilder(code).apply(block).flags()
Expand Down
2 changes: 0 additions & 2 deletions common/src/jvmMain/kotlin/Class.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ import kotlin.jvm.java as getJavaClass
public actual typealias Class<T> = java.lang.Class<T>

/** @suppress */
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.InlineOnly
@KordInternal
public actual inline val <T : Any> KClass<T>.java: Class<T> inline get() = getJavaClass
8 changes: 3 additions & 5 deletions common/src/nonJvmMain/kotlin/Class.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ 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 @@ -525,7 +525,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 @@ -593,7 +593,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 @@ -294,9 +294,9 @@ public suspend inline fun MessageChannelBehavior.createMessage(builder: UserMess
* @throws [RestRequestException] if something went wrong during the request.
*/
public suspend inline fun MessageChannelBehavior.createEmbed(block: EmbedBuilder.() -> Unit): Message {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
// contract {
// callsInPlace(block, InvocationKind.EXACTLY_ONCE)
// }
return createMessage { embed(block) }
}

Expand All @@ -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 56b708b

Please sign in to comment.