Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.7.1 #332

Merged
merged 45 commits into from
Jun 23, 2021
Merged

0.7.1 #332

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2252fda
Ci tests improvement (#264)
HopeBaron Apr 20, 2021
1a5f8bb
allow running dokkaHtml on push
HopeBaron Apr 20, 2021
3a12255
Implement voice stage channel (#239)
HopeBaron Apr 26, 2021
3389506
Fix CI triggers
HopeBaron Apr 26, 2021
69f463e
Add "Competing" activity type (Fix #270) (#272)
DRSchlaubi May 2, 2021
fb7a8f0
Make Updatestatus activities not-null (#274)
BartArys May 3, 2021
2bbf1ed
Fix memory issues related to Permission combining (#277)
BartArys May 6, 2021
0f24d9b
Update deprecated message (#280)
NoahH99 May 12, 2021
0b50de6
Expose the creation of application commands behavior (#281)
HopeBaron May 12, 2021
36dc03e
Fix GuildUpdate core handling (#284)
HopeBaron May 13, 2021
90a654b
Sealed message types (#282)
HopeBaron May 14, 2021
a623bb4
Add buttons to Activity (#287)
DRSchlaubi May 14, 2021
9b7a198
Add missing fields to Guild (#288)
DRSchlaubi May 14, 2021
2fc41ee
Add Message.applicationId (#289)
DRSchlaubi May 14, 2021
b77f326
Message interaction (#283)
HopeBaron May 15, 2021
60ab212
Implement Stage instances (#291)
DRSchlaubi May 15, 2021
6ed1921
Fix return type of channel in VoiceState (#295)
HopeBaron May 15, 2021
ca05ba7
Fix MessageInteraction#user id
BartArys May 28, 2021
94eea76
Add missing session start limit field (#306)
Jun 2, 2021
d959f28
Update to Kotlin 1.5 (#299)
BartArys Jun 2, 2021
8530f36
Filter out non-guilds when fetching rest guilds (#301)
BartArys Jun 4, 2021
68cc104
close InputStreams used for attachments (#309)
Moire9 Jun 8, 2021
3ff87ee
Ephemeral embed support (#296)
HopeBaron Jun 12, 2021
447ba66
Interaction create improvements (#294)
HopeBaron Jun 12, 2021
1d24fa8
Improve slash command API and add support for components (#310)
BartArys Jun 12, 2021
666b32a
interaction code cleanup (#312)
HopeBaron Jun 13, 2021
e558455
Make serialization of Snowflake consistent (#316)
BartArys Jun 14, 2021
173d0c1
Add missing components (#318)
HopeBaron Jun 16, 2021
4ab2732
Guild nsfw level (#320)
HopeBaron Jun 16, 2021
de058f3
Add non-builder editMessage overload (#323)
bosukas Jun 17, 2021
43fd515
Fix followups method signiture (#321)
HopeBaron Jun 18, 2021
c221e37
Improve live entity life cycle (#315)
HopeBaron Jun 18, 2021
bc357a4
0.7.0: Update Readme/Changelog (#314)
HopeBaron Jun 18, 2021
a9abe7b
Add components to webhook builders (#324)
BartArys Jun 18, 2021
f5ac613
update readme
HopeBaron Jun 18, 2021
ed38057
api dump
HopeBaron Jun 18, 2021
2c56afe
Merge branch 'master' into 0.7.x
HopeBaron Jun 18, 2021
6fe114d
clean rebuilt api files
HopeBaron Jun 18, 2021
f568174
Merge branch 'master' into 0.7.x
HopeBaron Jun 18, 2021
7557ae4
Allow properties in message edits to be empty/null (#327)
BartArys Jun 20, 2021
f1a63fd
api dump
HopeBaron Jun 20, 2021
adc89f5
Fixes/fix followup nullability (#330)
BartArys Jun 22, 2021
68f8795
Fix components in interactions (#331)
BartArys Jun 22, 2021
478cfd1
api dump
HopeBaron Jun 23, 2021
b40a067
Merge remote-tracking branch 'origin/master' into 0.7.x
HopeBaron Jun 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@
* `MessageModifyBuilder`
* `EditWebhookMessageBuilder`
* `InteractionResponseModifyRequest`
* `FollowupMessageBuilder`
* `PublicFollowupMessageModifyBuilder`
* `EphemeralFollowupMessageModifyBuilder`
* `PublicFollowupMessageCreateBuilder`
* `EphemeralFollowupMessageCreateBuilder`
* `FollowupMessageModifyRequest`
* `ComponentInteraction`

## Changes

* Message-related builders have been changed to accept `null` (for non-collections) and "empty list" (for collections)
when editing a message. This makes it possible to remove fields from a message without providing a substitution.
* `FollowupMessageBuilder` no longer has the `tts` field, since it does not apply to all its subclasses.

## Fixes

* `ActionRowComponent` properly returns its children.
* `ComponentInteraction#button` is now nullable as its documentation implies.

# 0.7.0

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/kotlin/cache/data/ComponentData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.kord.common.entity.DiscordComponent
import dev.kord.common.entity.DiscordPartialEmoji
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.mapList
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -23,15 +24,16 @@ data class ComponentData(

companion object {

fun from(entity: DiscordComponent) = with(entity) {
fun from(entity: DiscordComponent): ComponentData = with(entity) {
ComponentData(
type,
style,
label,
emoji,
customId,
url,
disabled
disabled,
components.mapList { from(it) }
)
}

Expand Down
20 changes: 9 additions & 11 deletions core/src/main/kotlin/entity/interaction/Interaction.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.kord.core.entity.interaction

import dev.kord.common.annotation.KordPreview
import dev.kord.common.entity.*
import dev.kord.common.entity.CommandArgument
import dev.kord.common.entity.InteractionType
import dev.kord.common.entity.Permissions
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.optional.*
import dev.kord.core.Kord
import dev.kord.core.KordObject
Expand All @@ -11,25 +14,18 @@ import dev.kord.core.behavior.MemberBehavior
import dev.kord.core.behavior.UserBehavior
import dev.kord.core.behavior.channel.GuildMessageChannelBehavior
import dev.kord.core.behavior.interaction.ComponentInteractionBehavior
import dev.kord.core.behavior.interaction.EphemeralInteractionResponseBehavior
import dev.kord.core.behavior.interaction.InteractionBehavior
import dev.kord.core.behavior.interaction.PublicInteractionResponseBehavior
import dev.kord.core.cache.data.ApplicationInteractionData
import dev.kord.core.cache.data.InteractionData
import dev.kord.core.cache.data.ResolvedObjectsData
import dev.kord.core.entity.*
import dev.kord.core.entity.channel.DmChannel
import dev.kord.core.entity.channel.ResolvedChannel
import dev.kord.core.entity.component.ActionRowComponent
import dev.kord.core.entity.component.ButtonComponent
import dev.kord.core.entity.component.Component
import dev.kord.core.supplier.EntitySupplier
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.rest.builder.interaction.UpdateMessageInteractionResponseCreateBuilder
import dev.kord.rest.json.request.InteractionApplicationCommandCallbackData
import dev.kord.rest.json.request.InteractionResponseCreateRequest
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
* An instance of [Interaction] (https://discord.com/developers/docs/interactions/slash-commands#interaction)
Expand Down Expand Up @@ -385,9 +381,11 @@ class ComponentInteraction(
*
* @see Component
*/
val component: ButtonComponent
val component: ButtonComponent?
get() = message?.components.orEmpty()
.filterIsInstance<ButtonComponent>().first { it.customId == componentId }
.filterIsInstance<ActionRowComponent>()
.flatMap { it.buttons }
.firstOrNull { it.customId == componentId }


override fun withStrategy(strategy: EntitySupplyStrategy<*>): ComponentInteraction = ComponentInteraction(
Expand Down
18 changes: 8 additions & 10 deletions rest/api/rest.api
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,10 @@ public final class dev/kord/rest/builder/interaction/EphemeralFollowupMessageCre
public fun getComponents ()Ljava/util/List;
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public final fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public final fun setTts (Ljava/lang/Boolean;)V
public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageCreateRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand All @@ -709,10 +709,10 @@ public final class dev/kord/rest/builder/interaction/EphemeralFollowupMessageMod
public fun getComponents ()Ljava/util/List;
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setComponents (Ljava/util/List;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public fun setEmbeds (Ljava/util/List;)V
public fun toRequest ()Ldev/kord/rest/json/request/FollowupMessageModifyRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand Down Expand Up @@ -748,9 +748,7 @@ public abstract interface class dev/kord/rest/builder/interaction/FollowupMessag
public abstract fun getComponents ()Ljava/util/List;
public abstract fun getContent ()Ljava/lang/String;
public abstract fun getEmbeds ()Ljava/util/List;
public abstract fun getTts ()Ljava/lang/Boolean;
public abstract fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public abstract fun setTts (Ljava/lang/Boolean;)V
}

public final class dev/kord/rest/builder/interaction/FollowupMessageBuildersKt {
Expand Down Expand Up @@ -794,10 +792,10 @@ public final class dev/kord/rest/builder/interaction/PublicFollowupMessageCreate
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public final fun getFiles ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public final fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public final fun setTts (Ljava/lang/Boolean;)V
public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageCreateRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand All @@ -811,10 +809,10 @@ public final class dev/kord/rest/builder/interaction/PublicFollowupMessageModify
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public final fun getFiles ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setComponents (Ljava/util/List;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public fun setEmbeds (Ljava/util/List;)V
public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageModifyRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand Down
99 changes: 68 additions & 31 deletions rest/src/main/kotlin/builder/interaction/FollowupMessageBuilders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.delegate.delegate
import dev.kord.common.entity.optional.map
import dev.kord.common.entity.optional.mapList
import dev.kord.rest.builder.RequestBuilder
import dev.kord.rest.builder.component.ActionRowBuilder
import dev.kord.rest.builder.component.MessageComponentBuilder
import dev.kord.rest.builder.message.AllowedMentionsBuilder
import dev.kord.rest.builder.message.EmbedBuilder
import dev.kord.rest.json.request.*
import dev.kord.rest.json.request.FollowupMessageCreateRequest
import dev.kord.rest.json.request.FollowupMessageModifyRequest
import dev.kord.rest.json.request.MultipartFollowupMessageCreateRequest
import dev.kord.rest.json.request.MultipartFollowupMessageModifyRequest
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.InputStream
Expand All @@ -24,13 +28,11 @@ import kotlin.contracts.contract
@KordPreview
sealed interface FollowupMessageBuilder<T> : RequestBuilder<T> {

var tts: Boolean?

var allowedMentions: AllowedMentionsBuilder?

val embeds: MutableList<EmbedBuilder>
val embeds: MutableList<EmbedBuilder>?

val components: MutableList<MessageComponentBuilder>
val components: MutableList<MessageComponentBuilder>?

val content: String?

Expand All @@ -42,13 +44,52 @@ inline fun <T> FollowupMessageBuilder<T>.actionRow(builder: ActionRowBuilder.()
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}

components.add(ActionRowBuilder().apply(builder))
when (this) {
is EphemeralFollowupMessageCreateBuilder -> {
components.add(ActionRowBuilder().apply(builder))
}

is EphemeralFollowupMessageModifyBuilder -> {
components = (components ?: mutableListOf()).also {
it.add(ActionRowBuilder().apply(builder))
}
}

is PublicFollowupMessageCreateBuilder -> {
components.add(ActionRowBuilder().apply(builder))
}

is PublicFollowupMessageModifyBuilder -> {
components = (components ?: mutableListOf()).also {
it.add(ActionRowBuilder().apply(builder))
}
}
}

}
@KordPreview
@OptIn(ExperimentalContracts::class)
inline fun <T> FollowupMessageBuilder<T>.embed(builder: EmbedBuilder.() -> Unit) {
contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) }
embeds += EmbedBuilder().apply(builder)

when(this){
is EphemeralFollowupMessageCreateBuilder -> {
embeds.add(EmbedBuilder().apply(builder))
}
is EphemeralFollowupMessageModifyBuilder -> {
embeds = (embeds ?: mutableListOf()).also {
it.add(EmbedBuilder().apply(builder))
}
}
is PublicFollowupMessageCreateBuilder -> {
embeds.add(EmbedBuilder().apply(builder))
}
is PublicFollowupMessageModifyBuilder -> {
embeds = (embeds ?: mutableListOf()).also {
it.add(EmbedBuilder().apply(builder))
}
}
}
}

/**
Expand All @@ -69,22 +110,19 @@ inline fun <T> FollowupMessageBuilder<T>.allowedMentions(block: AllowedMentionsB
@KordDsl
class PublicFollowupMessageModifyBuilder :
FollowupMessageBuilder<MultipartFollowupMessageModifyRequest> {
private var _content: Optional<String> = Optional.Missing()
private var _content: Optional<String?> = Optional.Missing()
override var content: String? by ::_content.delegate()

override val embeds: MutableList<EmbedBuilder> = mutableListOf()

private var _tts: OptionalBoolean = OptionalBoolean.Missing
override var tts: Boolean? by ::_tts.delegate()
private var _embeds: Optional<MutableList<EmbedBuilder>> = Optional.Missing()
override var embeds: MutableList<EmbedBuilder>? by ::_embeds.delegate()

val files: MutableList<Pair<String, InputStream>> = mutableListOf()


private var _allowedMentions: Optional<AllowedMentionsBuilder> = Optional.Missing()
private var _allowedMentions: Optional<AllowedMentionsBuilder?> = Optional.Missing()
override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate()

override val components: MutableList<MessageComponentBuilder> = mutableListOf()

private var _components: Optional<MutableList<MessageComponentBuilder>> = Optional.Missing()
override var components: MutableList<MessageComponentBuilder>? by ::_components.delegate()

fun addFile(name: String, content: InputStream) {
files += name to content
Expand All @@ -93,13 +131,14 @@ class PublicFollowupMessageModifyBuilder :
suspend fun addFile(path: Path) = withContext(Dispatchers.IO) {
addFile(path.fileName.toString(), Files.newInputStream(path))
}

override fun toRequest(): MultipartFollowupMessageModifyRequest {
return MultipartFollowupMessageModifyRequest(
FollowupMessageModifyRequest(
_content,
Optional.missingOnEmpty(embeds.map(EmbedBuilder::toRequest)),
_embeds.mapList { it.toRequest() },
_allowedMentions.map { it.build() },
Optional.missingOnEmpty(components.map(MessageComponentBuilder::build))
_components.mapList { it.build() },
),
files
)
Expand All @@ -111,24 +150,24 @@ class PublicFollowupMessageModifyBuilder :
@KordDsl
class EphemeralFollowupMessageModifyBuilder :
FollowupMessageBuilder<FollowupMessageModifyRequest> {
private var _content: Optional<String> = Optional.Missing()
private var _content: Optional<String?> = Optional.Missing()
override var content: String? by ::_content.delegate()

private var _tts: OptionalBoolean = OptionalBoolean.Missing
override var tts: Boolean? by ::_tts.delegate()

override val embeds: MutableList<EmbedBuilder> = mutableListOf()
private var _embeds: Optional<MutableList<EmbedBuilder>> = Optional.Missing()
override var embeds: MutableList<EmbedBuilder>? by ::_embeds.delegate()

private var _allowedMentions: Optional<AllowedMentionsBuilder> = Optional.Missing()
override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate()

override val components: MutableList<MessageComponentBuilder> = mutableListOf()
private var _components: Optional<MutableList<MessageComponentBuilder>> = Optional.Missing()
override var components: MutableList<MessageComponentBuilder>? by ::_components.delegate()

override fun toRequest(): FollowupMessageModifyRequest {
return FollowupMessageModifyRequest(
content = _content,
allowedMentions = _allowedMentions.map { it.build() },
components = Optional.missingOnEmpty(components.map(MessageComponentBuilder::build))
embeds = _embeds.mapList { it.toRequest() },
components = _components.mapList { it.build() }
)
}
}
Expand All @@ -141,20 +180,18 @@ class PublicFollowupMessageCreateBuilder : FollowupMessageBuilder<MultipartFollo
private var _content: Optional<String> = Optional.Missing()
override var content: String? by ::_content.delegate()


private var _tts: OptionalBoolean = OptionalBoolean.Missing
override var tts: Boolean? by ::_tts.delegate()
var tts: Boolean? by ::_tts.delegate()

private var _allowedMentions: Optional<AllowedMentionsBuilder> = Optional.Missing()
override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate()

val files: MutableList<Pair<String, InputStream>> = mutableListOf()

override val embeds: MutableList<EmbedBuilder> = mutableListOf()

override val components: MutableList<MessageComponentBuilder> = mutableListOf()



override fun toRequest(): MultipartFollowupMessageCreateRequest =
MultipartFollowupMessageCreateRequest(
FollowupMessageCreateRequest(
Expand All @@ -178,7 +215,7 @@ class EphemeralFollowupMessageCreateBuilder : FollowupMessageBuilder<MultipartFo
override var content: String? by ::_content.delegate()

private var _tts: OptionalBoolean = OptionalBoolean.Missing
override var tts: Boolean? by ::_tts.delegate()
var tts: Boolean? by ::_tts.delegate()

private var _allowedMentions: Optional<AllowedMentionsBuilder> = Optional.Missing()
override var allowedMentions: AllowedMentionsBuilder? by ::_allowedMentions.delegate()
Expand All @@ -200,4 +237,4 @@ class EphemeralFollowupMessageCreateBuilder : FollowupMessageBuilder<MultipartFo
)


}
}
8 changes: 4 additions & 4 deletions rest/src/main/kotlin/json/request/InteractionsRequests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ class FollowupMessageCreateRequest(
@Serializable
@KordPreview
data class FollowupMessageModifyRequest(
val content: Optional<String> = Optional.Missing(),
val embeds: Optional<List<EmbedRequest>> = Optional.Missing(),
val content: Optional<String?> = Optional.Missing(),
val embeds: Optional<List<EmbedRequest>?> = Optional.Missing(),
@SerialName("allowed_mentions")
val allowedMentions: Optional<AllowedMentions> = Optional.Missing(),
val components: Optional<List<DiscordComponent>> = Optional.Missing()
val allowedMentions: Optional<AllowedMentions?> = Optional.Missing(),
val components: Optional<List<DiscordComponent>?> = Optional.Missing()
)

@KordPreview
Expand Down