Skip to content

Commit

Permalink
Merge pull request #813 from Lukellmann/cleanup
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
DRSchlaubi authored Apr 14, 2023
2 parents 57b186c + 3d65640 commit 607c9b8
Show file tree
Hide file tree
Showing 33 changed files with 86 additions and 107 deletions.
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Documentation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import java.net.URL

fun AbstractDokkaLeafTask.applyKordDokkaOptions() {

moduleName = "kord-${project.name}"

failOnWarning = true

dokkaSourceSets.configureEach {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ publishing {
licenses {
license {
name = "MIT"
url = "http://opensource.org/licenses/MIT"
url = "https://opensource.org/licenses/MIT"
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/commonMain/kotlin/entity/AuditLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public data class AuditLogChange<T>(
val key: AuditLogChangeKey<T>,
) {

internal class Serializer<T>(val ser: KSerializer<T>) : KSerializer<AuditLogChange<T>> {
internal class Serializer<T>(private val ser: KSerializer<T>) : KSerializer<AuditLogChange<T>> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("Kord.AuditLogChange", ser.descriptor) {
element<JsonElement>("new_value")
element<JsonElement>("old_value")
Expand Down
7 changes: 4 additions & 3 deletions common/src/commonMain/kotlin/entity/DiscordComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ public sealed class DiscordComponent {
override fun selectDeserializer(element: JsonElement): KSerializer<out DiscordComponent> {
val componentType = element.jsonObject["type"]?.jsonPrimitive?.intOrNull ?: error("Missing component type ID!")

return when (componentType) {
ComponentType.TextInput.value -> DiscordTextInputComponent.serializer()
else -> DiscordChatComponent.serializer()
return if (componentType == ComponentType.TextInput.value) {
DiscordTextInputComponent.serializer()
} else {
DiscordChatComponent.serializer()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class OptionalBooleanTest {
}

@Serializable
private class ValueOptionalEntity(@Suppress("unused") val value: OptionalBoolean = OptionalBoolean.Missing)
private class ValueOptionalEntity(val value: OptionalBoolean = OptionalBoolean.Missing)

@Test
@JsName("test3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class OptionalIntTest {
}

@Serializable
class ValueOptionalEntity(@Suppress("unused") val value: OptionalInt = OptionalInt.Missing)
class ValueOptionalEntity(val value: OptionalInt = OptionalInt.Missing)

@Test
@JsName("test3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class OptionalLongTest {


@Serializable
class NullOptionalEntity(@Suppress("unused") val value: OptionalLong = OptionalLong.Missing)
class NullOptionalEntity(val value: OptionalLong = OptionalLong.Missing)

@Test
@JsName("test2")
Expand All @@ -42,7 +42,7 @@ internal class OptionalLongTest {


@Serializable
class ValueOptionalEntity(@Suppress("unused") val value: OptionalLong = OptionalLong.Missing)
class ValueOptionalEntity(val value: OptionalLong = OptionalLong.Missing)

@Test
@JsName("test3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class OptionalSnowflakeTest {


@Serializable
class NullOptionalEntity(@Suppress("unused") val value: OptionalSnowflake = OptionalSnowflake.Missing)
class NullOptionalEntity(val value: OptionalSnowflake = OptionalSnowflake.Missing)

@Test
@JsName("test2")
Expand All @@ -43,7 +43,7 @@ internal class OptionalSnowflakeTest {


@Serializable
class ValueOptionalEntity(@Suppress("unused") val value: OptionalSnowflake = OptionalSnowflake.Missing)
class ValueOptionalEntity(val value: OptionalSnowflake = OptionalSnowflake.Missing)

@Test
@JsName("test3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ private val parser = Json {

object FakeGateway : Gateway {

val deferred = CompletableDeferred<Unit>()
private val deferred = CompletableDeferred<Unit>()

override val events: SharedFlow<Event> = MutableSharedFlow<Event>()
override val events: SharedFlow<Event> = MutableSharedFlow()

override val ping: StateFlow<Duration?> = MutableStateFlow(null)

Expand All @@ -66,7 +66,7 @@ object FakeGateway : Gateway {
override val coroutineContext: CoroutineContext = SupervisorJob() + EmptyCoroutineContext
}

class CrashingHandler(val client: HttpClient, override val token: String) : RequestHandler {
class CrashingHandler(private val client: HttpClient, override val token: String) : RequestHandler {
override suspend fun <B : Any, R> handle(request: Request<B, R>): R {
if (request.route != Route.CurrentUserGet) throw IllegalStateException("shouldn't do a request")
val response = client.request {
Expand Down
3 changes: 1 addition & 2 deletions core/src/commonMain/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import kotlinx.datetime.Instant
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.reflect.KClass
import kotlinx.coroutines.flow.firstOrNull as coroutinesFirstOrNull

internal inline fun <T> catchNotFound(block: () -> T): T? {
contract {
Expand Down Expand Up @@ -66,7 +65,7 @@ internal fun <T : Comparable<T>> Flow<T>.sorted(): Flow<T> = flow {
* The flow's collection is cancelled when a match is found.
*/
internal suspend inline fun <T : Any> Flow<T>.any(crossinline predicate: suspend (T) -> Boolean): Boolean =
coroutinesFirstOrNull { predicate(it) } != null
firstOrNull { predicate(it) } != null

/**
* The non-terminal operator that returns a new flow that will emit values of the second [flow] only after the first
Expand Down
39 changes: 19 additions & 20 deletions core/src/commonMain/kotlin/behavior/GuildBehavior.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.*
import kotlinx.coroutines.flow.*
import kotlinx.datetime.Instant
import kotlin.contracts.InvocationKind
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract

Expand Down Expand Up @@ -695,7 +694,7 @@ public suspend inline fun GuildBehavior.createChatInputCommand(
description: String,
builder: ChatInputCreateBuilder.() -> Unit = {},
): GuildChatInputCommand {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.createGuildChatInputCommand(id, name, description, builder)
}

Expand All @@ -704,7 +703,7 @@ public suspend inline fun GuildBehavior.createMessageCommand(
name: String,
builder: MessageCommandCreateBuilder.() -> Unit = {},
): GuildMessageCommand {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.createGuildMessageCommand(id, name, builder)
}

Expand All @@ -713,15 +712,15 @@ public suspend inline fun GuildBehavior.createUserCommand(
name: String,
builder: UserCommandCreateBuilder.() -> Unit = {},
): GuildUserCommand {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.createGuildUserCommand(id, name, builder)
}


public suspend inline fun GuildBehavior.createApplicationCommands(
builder: GuildMultiApplicationCommandBuilder.() -> Unit
): Flow<GuildApplicationCommand> {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.createGuildApplicationCommands(id, builder)
}

Expand All @@ -734,7 +733,7 @@ public suspend inline fun GuildBehavior.createApplicationCommands(
*/
public suspend inline fun GuildBehavior.edit(builder: GuildModifyBuilder.() -> Unit): Guild {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
val response = kord.rest.guild.modifyGuild(id, builder)
val data = GuildData.from(response)
Expand All @@ -748,7 +747,7 @@ public suspend inline fun GuildBehavior.createEmoji(
builder: EmojiCreateBuilder.() -> Unit = {}
): GuildEmoji {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
val discordEmoji = kord.rest.emoji.createEmoji(guildId = id, name, image, builder)
return GuildEmoji(EmojiData.from(guildId = id, id = discordEmoji.id!!, discordEmoji), kord)
Expand All @@ -767,7 +766,7 @@ public suspend inline fun GuildBehavior.createTextChannel(
builder: TextChannelCreateBuilder.() -> Unit = {}
): TextChannel {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
val response = kord.rest.guild.createTextChannel(id, name, builder)
val data = ChannelData.from(response)
Expand All @@ -779,7 +778,7 @@ public suspend inline fun GuildBehavior.createForumChannel(
name: String,
builder: ForumChannelCreateBuilder.() -> Unit = {}
): ForumChannel {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
val response = kord.rest.guild.createForumChannel(id, name, builder)
val data = ChannelData.from(response)
return Channel.from(data, kord) as ForumChannel
Expand All @@ -797,7 +796,7 @@ public suspend inline fun GuildBehavior.createVoiceChannel(
builder: VoiceChannelCreateBuilder.() -> Unit = {}
): VoiceChannel {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
val response = kord.rest.guild.createVoiceChannel(id, name, builder)
val data = ChannelData.from(response)
Expand All @@ -817,7 +816,7 @@ public suspend inline fun GuildBehavior.createNewsChannel(
builder: NewsChannelCreateBuilder.() -> Unit = {}
): NewsChannel {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
val response = kord.rest.guild.createNewsChannel(id, name, builder)
val data = ChannelData.from(response)
Expand All @@ -838,7 +837,7 @@ public suspend inline fun GuildBehavior.createCategory(
builder: CategoryCreateBuilder.() -> Unit = {}
): Category {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
val response = kord.rest.guild.createCategory(id, name, builder)
val data = ChannelData.from(response)
Expand All @@ -853,7 +852,7 @@ public suspend inline fun GuildBehavior.createCategory(
*/
public suspend inline fun GuildBehavior.swapChannelPositions(builder: GuildChannelPositionModifyBuilder.() -> Unit) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
kord.rest.guild.modifyGuildChannelPosition(id, builder)
}
Expand All @@ -870,7 +869,7 @@ public suspend inline fun GuildBehavior.swapChannelPositions(builder: GuildChann
*/
public suspend inline fun GuildBehavior.swapRolePositions(builder: RolePositionsModifyBuilder.() -> Unit): Flow<Role> {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
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 All @@ -886,7 +885,7 @@ public suspend inline fun GuildBehavior.swapRolePositions(builder: RolePositions
*/
public suspend inline fun GuildBehavior.createRole(builder: RoleCreateBuilder.() -> Unit = {}): Role {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
val response = kord.rest.guild.createGuildRole(id, builder)
val data = RoleData.from(id, response)
Expand All @@ -901,7 +900,7 @@ public suspend inline fun GuildBehavior.createRole(builder: RoleCreateBuilder.()
*/
public suspend inline fun GuildBehavior.ban(userId: Snowflake, builder: BanCreateBuilder.() -> Unit) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
callsInPlace(builder, EXACTLY_ONCE)
}
kord.rest.guild.addGuildBan(guildId = id, userId = userId, builder = builder)
}
Expand Down Expand Up @@ -935,7 +934,7 @@ public suspend inline fun <reified T : GuildChannel> GuildBehavior.getChannelOfO
}

public suspend inline fun GuildBehavior.editWidget(builder: GuildWidgetModifyBuilder.() -> Unit): GuildWidget {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
return GuildWidget(GuildWidgetData.from(kord.rest.guild.modifyGuildWidget(id, builder)), id, kord)
}

Expand All @@ -955,7 +954,7 @@ public suspend inline fun GuildBehavior.editWidget(builder: GuildWidgetModifyBui
* ```
*/
public inline fun GuildBehavior.getAuditLogEntries(builder: AuditLogGetRequestBuilder.() -> Unit = {}): Flow<AuditLogEntry> {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
return kord.with(rest).getAuditLogEntries(id, builder).map { AuditLogEntry(it, kord) }
}

Expand All @@ -978,7 +977,7 @@ public inline fun GuildBehavior.getAuditLogEntries(builder: AuditLogGetRequestBu
*/
@PrivilegedIntent
public inline fun GuildBehavior.requestMembers(builder: RequestGuildMembersBuilder.() -> Unit = { requestAllMembers() }): Flow<MembersChunkEvent> {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }
val request = RequestGuildMembersBuilder(id).apply(builder).toRequest()
return requestMembers(request)
}
Expand All @@ -993,7 +992,7 @@ public suspend fun GuildBehavior.createScheduledEvent(
entityType: ScheduledEntityType,
builder: ScheduledEventCreateBuilder.() -> Unit
): GuildScheduledEvent {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
contract { callsInPlace(builder, EXACTLY_ONCE) }

val event = kord.rest.guild.createScheduledEvent(id, name, privacyLevel, scheduledStartTime, entityType, builder)
val data = GuildScheduledEventData.from(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public class ApplicationCommandGroupData(
public val subCommands: List<ApplicationCommandSubcommandData>
)

@Suppress("FunctionName")
public fun ApplicationCommandGroupData(data: ApplicationCommandOptionData): ApplicationCommandGroupData {
return ApplicationCommandGroupData(
data.name,
Expand Down Expand Up @@ -139,7 +138,6 @@ public data class ApplicationCommandParameterData(
)


@Suppress("FunctionName")
public fun ApplicationCommandParameterData(data: ApplicationCommandOptionData): ApplicationCommandParameterData {
return ApplicationCommandParameterData(
data.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public open class SelectMenuComponent
)
public constructor(override val data: ComponentData) : Component {

@Suppress("DEPRECATION", "INAPPLICABLE_JVM_NAME")
@Suppress("INAPPLICABLE_JVM_NAME")
@Deprecated("Binary compatibility", level = DeprecationLevel.HIDDEN)
@get:JvmName("getType")
public open val type0: ComponentType.SelectMenu get() = ComponentType.SelectMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.kord.cache.api.DataCache
import dev.kord.cache.api.put
import dev.kord.cache.api.putAll
import dev.kord.cache.api.query
import dev.kord.common.entity.DiscordGuild
import dev.kord.common.entity.optional.optionalSnowflake
import dev.kord.common.entity.optional.orEmpty
import dev.kord.core.Kord
Expand All @@ -19,7 +20,6 @@ import dev.kord.gateway.*
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.singleOrNull
import kotlinx.coroutines.flow.toSet
import dev.kord.common.entity.DiscordGuild as GatewayGuild
import dev.kord.core.event.Event as CoreEvent

internal class GuildEventHandler : BaseGatewayEventHandler() {
Expand Down Expand Up @@ -55,7 +55,7 @@ internal class GuildEventHandler : BaseGatewayEventHandler() {
else -> null
}

private suspend fun GatewayGuild.cache(cache: DataCache) {
private suspend fun DiscordGuild.cache(cache: DataCache) {
for (member in members.orEmpty()) {
cache.put(MemberData.from(member.user.value!!.id, id, member))
cache.put(UserData.from(member.user.value!!))
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonTest/kotlin/live/AbstractLiveEntityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class AbstractLiveEntityTest<LIVE : AbstractLiveKordEntity> {
override suspend fun stop() {}
}

class CounterAtomicLatch() {
class CounterAtomicLatch {
private val channel = Channel<Unit>()

private val received = atomic(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.kord.core.behavior.channel
import dev.kord.core.equality.ChannelEqualityTest
import dev.kord.core.mockKord

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
internal class ChannelBehaviorTest : ChannelEqualityTest<ChannelBehavior> by ChannelEqualityTest({ id ->
val kord = mockKord()
ChannelBehavior(id = id, kord = kord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.kord.core.behavior.channel
import dev.kord.core.equality.ChannelEqualityTest
import dev.kord.core.mockKord

@Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
internal class MessageChannelBehaviorTest : ChannelEqualityTest<MessageChannelBehavior> by ChannelEqualityTest({ id ->
val kord = mockKord()
MessageChannelBehavior(id = id, kord = kord)
Expand Down
4 changes: 1 addition & 3 deletions core/src/jvmTest/kotlin/entity/channel/CategoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ import dev.kord.core.mockKord
internal class CategoryTest : GuildChannelEqualityTest<Category> by GuildChannelEqualityTest ({ id, guildId ->
val kord = mockKord()
Category(ChannelData(id, guildId = guildId.optionalSnowflake(), type = ChannelType.GuildCategory), kord)
}) {

}
})
Loading

0 comments on commit 607c9b8

Please sign in to comment.