Skip to content

Commit

Permalink
Merge branch '0.8.x' into forums
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Nov 26, 2022
2 parents eb214ea + 9da6b51 commit d22f886
Show file tree
Hide file tree
Showing 56 changed files with 305 additions and 98 deletions.
16 changes: 16 additions & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,22 @@ public final class dev/kord/common/entity/Choice$IntChoice : dev/kord/common/ent
public fun toString ()Ljava/lang/String;
}

public final class dev/kord/common/entity/Choice$IntegerChoice : dev/kord/common/entity/Choice {
public fun <init> (Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;J)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ldev/kord/common/entity/optional/Optional;
public final fun component3 ()J
public final fun copy (Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;J)Ldev/kord/common/entity/Choice$IntegerChoice;
public static synthetic fun copy$default (Ldev/kord/common/entity/Choice$IntegerChoice;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;JILjava/lang/Object;)Ldev/kord/common/entity/Choice$IntegerChoice;
public fun equals (Ljava/lang/Object;)Z
public fun getName ()Ljava/lang/String;
public fun getNameLocalizations ()Ldev/kord/common/entity/optional/Optional;
public fun getValue ()Ljava/lang/Long;
public synthetic fun getValue ()Ljava/lang/Object;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/kord/common/entity/Choice$NumberChoice : dev/kord/common/entity/Choice {
public fun <init> (Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;D)V
public final fun component1 ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ public sealed class GuildFeature(
*/
public object PreviewEnabled : GuildFeature("PREVIEW_ENABLED")

/**
* Guild has access to create private threads
*/
public object PrivateThreads : GuildFeature("PRIVATE_THREADS")

/**
* Guild is able to set role icons.
*/
Expand Down Expand Up @@ -183,6 +178,12 @@ public sealed class GuildFeature(
)
public object Commerce : GuildFeature("COMMERCE")

/**
* Guild has access to create private threads
*/
@Deprecated(message = "Creating a private thread no longer requires the server to be boosted.")
public object PrivateThreads : GuildFeature("PRIVATE_THREADS")

/**
* Guild has access to the seven day archive time for threads.
*
Expand Down Expand Up @@ -233,7 +234,7 @@ public sealed class GuildFeature(
"NEWS" -> News
"PARTNERED" -> Partnered
"PREVIEW_ENABLED" -> PreviewEnabled
"PRIVATE_THREADS" -> PrivateThreads
"PRIVATE_THREADS" -> @Suppress("DEPRECATION") PrivateThreads
"ROLE_ICONS" -> RoleIcons
"SEVEN_DAY_THREAD_ARCHIVE" -> @Suppress("DEPRECATION_ERROR") SevenDayThreadArchive
"THREE_DAY_THREAD_ARCHIVE" -> @Suppress("DEPRECATION_ERROR") ThreeDayThreadArchive
Expand Down Expand Up @@ -270,7 +271,7 @@ public sealed class GuildFeature(
News,
Partnered,
PreviewEnabled,
PrivateThreads,
@Suppress("DEPRECATION") PrivateThreads,
RoleIcons,
@Suppress("DEPRECATION_ERROR") SevenDayThreadArchive,
@Suppress("DEPRECATION_ERROR") ThreeDayThreadArchive,
Expand Down
7 changes: 6 additions & 1 deletion common/src/main/kotlin/entity/DiscordGuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
"PreviewEnabled", stringValue = "PREVIEW_ENABLED",
kDoc = "Guild can be previewed before joining via Membership Screening or the directory.",
),
Entry("PrivateThreads", stringValue = "PRIVATE_THREADS", kDoc = "Guild has access to create private threads"),
Entry("RoleIcons", stringValue = "ROLE_ICONS", kDoc = "Guild is able to set role icons."),
Entry(
"TicketedEventsEnabled", stringValue = "TICKETED_EVENTS_ENABLED",
Expand All @@ -142,6 +141,11 @@
" for more information.",
deprecationLevel = HIDDEN,
),
Entry(
"PrivateThreads", stringValue = "PRIVATE_THREADS", kDoc = "Guild has access to create private threads",
deprecationMessage = "Creating a private thread no longer requires the server to be boosted.",
deprecationLevel = WARNING,
),
Entry(
"SevenDayThreadArchive", stringValue = "SEVEN_DAY_THREAD_ARCHIVE",
kDoc = "Guild has access to the seven day archive time for threads.\n\n@suppress",
Expand Down Expand Up @@ -176,6 +180,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.DeprecationLevel.HIDDEN
import kotlin.DeprecationLevel.WARNING

/**
* A partial representation of a [DiscordGuild] that may be [unavailable].
Expand Down
44 changes: 39 additions & 5 deletions common/src/main/kotlin/entity/Interactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*
import kotlin.DeprecationLevel.HIDDEN
import kotlin.DeprecationLevel.WARNING

@Serializable
public data class DiscordApplicationCommand(
Expand Down Expand Up @@ -171,12 +172,24 @@ public sealed class Choice<out T> {
public abstract val nameLocalizations: Optional<Map<Locale, String>?>
public abstract val value: T

public data class IntChoice(
@Deprecated("Renamed to 'IntegerChoice'.", level = WARNING)
public data class IntChoice
@Deprecated(
"Renamed to 'IntegerChoice'.",
ReplaceWith("IntegerChoice(name, nameLocalizations, value)", "dev.kord.common.entity.Choice.IntegerChoice"),
level = WARNING,
) public constructor(
override val name: String,
override val nameLocalizations: Optional<Map<Locale, String>?>,
override val value: Long
) : Choice<Long>()

public data class IntegerChoice(
override val name: String,
override val nameLocalizations: Optional<Map<Locale, String>?>,
override val value: Long,
) : Choice<Long>()

public data class NumberChoice(
override val name: String,
override val nameLocalizations: Optional<Map<Locale, String>?>,
Expand Down Expand Up @@ -216,7 +229,7 @@ public sealed class Choice<out T> {

when {
value.isString -> StringChoice(name, nameLocalizations, value.content)
else -> value.longOrNull?.let { IntChoice(name, nameLocalizations, it) }
else -> value.longOrNull?.let { IntegerChoice(name, nameLocalizations, it) }
?: value.doubleOrNull?.let { NumberChoice(name, nameLocalizations, it) }
?: throw SerializationException("Illegal choice value: $value")
}
Expand All @@ -227,7 +240,8 @@ public sealed class Choice<out T> {
encodeStringElement(descriptor, 0, value.name)

when (value) {
is IntChoice -> encodeLongElement(descriptor, 1, value.value)
is @Suppress("DEPRECATION") IntChoice -> encodeLongElement(descriptor, 1, value.value)
is IntegerChoice -> encodeLongElement(descriptor, 1, value.value)
is NumberChoice -> encodeDoubleElement(descriptor, 1, value.value)
is StringChoice -> encodeStringElement(descriptor, 1, value.value)
}
Expand Down Expand Up @@ -393,7 +407,7 @@ public sealed class Option {
ApplicationCommandOptionType.User -> CommandArgument.Serializer.deserialize(
json, jsonValue!!, name, type!!, focused
)
else -> error("unknown ApplicationCommandOptionType $type")
null, is ApplicationCommandOptionType.Unknown -> error("unknown ApplicationCommandOptionType $type")
}
}

Expand Down Expand Up @@ -681,23 +695,43 @@ public data class CommandGroup(
get() = ApplicationCommandOptionType.SubCommandGroup
}

@Deprecated(
"Use an is-check or cast instead.",
ReplaceWith("(this as CommandArgument.IntegerArgument).value", "dev.kord.common.entity.CommandArgument"),
level = WARNING,
)
public fun CommandArgument<*>.int(): Long {
return value as? Long ?: error("$value wasn't an int.")
}


@Deprecated(
"This function calls value.toString() which might be unexpected. Use an explicit value.toString() instead.",
ReplaceWith("this.value.toString()"),
level = WARNING,
)
public fun CommandArgument<*>.string(): String {
return value.toString()
}


@Deprecated(
"Use an is-check or cast instead.",
ReplaceWith("(this as CommandArgument.BooleanArgument).value", "dev.kord.common.entity.CommandArgument"),
level = WARNING,
)
public fun CommandArgument<*>.boolean(): Boolean {
return value as? Boolean ?: error("$value wasn't a Boolean.")
}


@Deprecated(
"This function calls value.toString() which might be unexpected. Use an explicit value.toString() instead.",
ReplaceWith("Snowflake(this.value.toString())", "dev.kord.common.entity.Snowflake"),
level = WARNING,
)
public fun CommandArgument<*>.snowflake(): Snowflake {
val id = string().toULongOrNull() ?: error("$value wasn't a Snowflake")
val id = value.toString().toULongOrNull() ?: error("$value wasn't a Snowflake")
return Snowflake(id)
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/kotlin/entity/optional/Optional.kt
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,5 @@ public fun <T : Any?> T?.optional(): Optional<T?> = Optional(this)

public fun Optional<Boolean>.toPrimitive(): OptionalBoolean = when (this) {
is Value -> OptionalBoolean.Value(value)
else -> OptionalBoolean.Missing
is Missing, is Null<*> -> OptionalBoolean.Missing
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public fun <V : Any> KMutableProperty0<Optional<V>>.delegate(): ReadWritePropert
override fun getValue(thisRef: Any?, property: KProperty<*>): V? {
return when (val optional = this@delegate.get()) {
is Optional.Value -> optional.value
else -> null
is Optional.Missing, is Optional.Null<*> -> null
}
}
}
Expand All @@ -36,7 +36,7 @@ public fun <V : Any> KMutableProperty0<Optional<List<V>>>.delegateList(): ReadWr
override fun getValue(thisRef: Any?, property: KProperty<*>): List<V> {
return when (val optional = this@delegateList.get()) {
is Optional.Value -> optional.value
else -> emptyList()
is Optional.Missing, is Optional.Null<*> -> emptyList()
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions common/src/test/kotlin/json/InteractionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class InteractionTest {
val subCommand = group.options.orEmpty().first()
subCommand.name shouldBe "groupsubcommand"
val arg = subCommand.options.orEmpty().first()
arg.type shouldBe ApplicationCommandOptionType.Integer
arg.name shouldBe "testint"
arg.int() shouldBe 1
arg.string() shouldBe "1"
arg.value shouldBe 1L
appPermissions shouldBe Permissions("2147483647")
}
}
Expand All @@ -63,9 +63,9 @@ class InteractionTest {
subCommand as SubCommand
subCommand.name shouldBe "subcommand"
val arg = subCommand.options.orEmpty().first()
arg.type shouldBe ApplicationCommandOptionType.Integer
arg.name shouldBe "testint"
arg.int() shouldBe 1
arg.string() shouldBe "1"
arg.value shouldBe 1L
appPermissions shouldBe Permissions("2147483647")
}
}
Expand All @@ -88,9 +88,9 @@ class InteractionTest {
val arg = data.options.orEmpty().first()
assert(arg is CommandArgument<*>)
arg as CommandArgument<*>
arg.type shouldBe ApplicationCommandOptionType.Integer
arg.name shouldBe "testint"
arg.int() shouldBe 1
arg.string() shouldBe "1"
arg.value shouldBe 1L
appPermissions shouldBe Permissions("2147483647")
}
}
Expand Down
1 change: 1 addition & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,7 @@ public final class dev/kord/core/behavior/interaction/AutoCompleteInteractionBeh

public final class dev/kord/core/behavior/interaction/AutoCompleteInteractionBehaviorKt {
public static final fun suggestInt (Ldev/kord/core/behavior/interaction/AutoCompleteInteractionBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun suggestInteger (Ldev/kord/core/behavior/interaction/AutoCompleteInteractionBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun suggestNumber (Ldev/kord/core/behavior/interaction/AutoCompleteInteractionBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun suggestString (Ldev/kord/core/behavior/interaction/AutoCompleteInteractionBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.interaction.IntegerOptionBuilder
import dev.kord.rest.builder.interaction.NumberOptionBuilder
import dev.kord.rest.builder.interaction.StringChoiceBuilder
import kotlin.DeprecationLevel.WARNING
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
* The behavior of an [AutoCompleteInteraction].
*
* @see suggestString
* @see suggestInt
* @see suggestInteger
* @see suggestNumber
* @see suggest
*/
Expand All @@ -23,14 +24,24 @@ public interface AutoCompleteInteractionBehavior : DataInteractionBehavior {
override fun withStrategy(strategy: EntitySupplyStrategy<*>): AutoCompleteInteractionBehavior
}

@Deprecated(
"Renamed to 'suggestInteger'.",
ReplaceWith("this.suggestInteger { builder() }", "dev.kord.core.behavior.interaction.suggestInteger"),
level = WARNING,
)
public suspend inline fun AutoCompleteInteractionBehavior.suggestInt(builder: IntegerOptionBuilder.() -> Unit) {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
suggestInteger(builder)
}

/**
* Responds to the interaction with the int choices specified by [builder].
* Responds to the interaction with the integer choices specified by [builder].
*
* The provided choices are only suggestions and the user can provide any other input as well.
*
* @see IntegerOptionBuilder
*/
public suspend inline fun AutoCompleteInteractionBehavior.suggestInt(builder: IntegerOptionBuilder.() -> Unit) {
public suspend inline fun AutoCompleteInteractionBehavior.suggestInteger(builder: IntegerOptionBuilder.() -> Unit) {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal suspend inline fun InteractionResponseBehavior.editOriginalResponseWith
val public = when (this) {
is PublicInteractionResponseBehavior -> true
is EphemeralInteractionResponseBehavior -> false
else -> error(
is FollowupPermittingInteractionResponseBehavior -> error(
"This function can't be called on an InteractionResponseBehavior that implements neither " +
"PublicInteractionResponseBehavior nor EphemeralInteractionResponseBehavior."
)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/entity/channel/Channel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public interface Channel : ChannelBehavior {
PublicNewsThread -> NewsChannelThread(data, kord)
PrivateThread, PublicGuildThread -> TextChannelThread(data, kord)

else -> {
GuildDirectory, is Unknown -> {
if (data.threadMetadata.value == null) Channel(data, kord, strategy.supply(kord))
else ThreadChannel(data, kord, strategy.supply(kord))
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/entity/component/SelectMenuComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public constructor(override val data: ComponentData) : Component {
),
level = DeprecationLevel.WARNING,
)
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
public val options: List<SelectOption> get() = _options

@Suppress("PropertyName")
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/kotlin/entity/interaction/Interaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ public sealed interface Interaction : InteractionBehavior {
data: InteractionData,
kord: Kord,
strategy: EntitySupplyStrategy<*> = kord.resources.defaultStrategy
): Interaction {
return when {
data.type is InteractionType.Component -> ComponentInteraction(data, kord, strategy.supply(kord))
data.type is InteractionType.AutoComplete -> AutoCompleteInteraction(data, kord, strategy.supply(kord))
data.type is InteractionType.ModalSubmit -> ModalSubmitInteraction(data, kord, strategy.supply(kord))
data.guildId !is OptionalSnowflake.Missing -> GuildApplicationCommandInteraction(
data,
kord,
strategy.supply(kord)
)
else -> GlobalApplicationCommandInteraction(data, kord, strategy.supply(kord))
): Interaction = when (val type = data.type) {
InteractionType.Component -> ComponentInteraction(data, kord, strategy.supply(kord))
InteractionType.AutoComplete -> AutoCompleteInteraction(data, kord, strategy.supply(kord))
InteractionType.ModalSubmit -> ModalSubmitInteraction(data, kord, strategy.supply(kord))
InteractionType.ApplicationCommand -> {
if (data.guildId !is OptionalSnowflake.Missing) {
GuildApplicationCommandInteraction(data, kord, strategy.supply(kord))
} else {
GlobalApplicationCommandInteraction(data, kord, strategy.supply(kord))
}
}
InteractionType.Ping, is InteractionType.Unknown -> error("Unsupported interaction type: $type")
}
}
}
6 changes: 3 additions & 3 deletions core/src/test/kotlin/rest/RestTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import dev.kord.core.entity.channel.TextChannel
import dev.kord.core.entity.channel.TopGuildMessageChannel
import dev.kord.rest.Image
import dev.kord.rest.builder.interaction.group
import dev.kord.rest.builder.interaction.int
import dev.kord.rest.builder.interaction.integer
import dev.kord.rest.builder.interaction.subCommand
import io.ktor.client.request.forms.*
import io.ktor.util.cio.*
Expand Down Expand Up @@ -443,15 +443,15 @@ class RestServiceTest {
val command = kord.createGlobalChatInputCommand("test", "automated test") {
group("test-group", "automated test") {
subCommand("test-sub-command", "automated test") {
int("integer", "test choice") {
integer("integer", "test choice") {
choice("one", 1)
choice("two", 2)
}
}
}

subCommand("test-sub-command", "automated test") {
int("integer", "test choice")
integer("integer", "test choice")
}
}

Expand Down
Loading

0 comments on commit d22f886

Please sign in to comment.