-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add New webhook endpoints (discord/discord-api-docs#2243) Relates to #121 * Make EditWebhookMessageBuilder.embeds a list of builders * Remove webhookId from behavior * Remove inapropriate docs * Formatting * Fix some formatting * Fix some more formatting * Fix style issue in Route.kt * Add test
- Loading branch information
1 parent
ce7f0a1
commit 5eb7aa2
Showing
8 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
rest/src/main/kotlin/builder/webhook/EditWebhookMessageBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.kord.rest.builder.webhook | ||
|
||
import dev.kord.common.entity.AllowedMentions | ||
import dev.kord.common.entity.optional.Optional | ||
import dev.kord.common.entity.optional.delegate.delegate | ||
import dev.kord.rest.builder.RequestBuilder | ||
import dev.kord.rest.builder.message.EmbedBuilder | ||
import dev.kord.rest.json.request.WebhookEditMessageRequest | ||
import kotlin.contracts.ExperimentalContracts | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
class EditWebhookMessageBuilder : RequestBuilder<WebhookEditMessageRequest> { | ||
|
||
private var _content: Optional<String> = Optional.Missing() | ||
var content: String? by ::_content.delegate() | ||
|
||
var embeds: MutableList<EmbedBuilder> = mutableListOf() | ||
|
||
private var _allowedMentions: Optional<AllowedMentions> = Optional.Missing() | ||
var allowedMentions: AllowedMentions? by ::_allowedMentions.delegate() | ||
|
||
@OptIn(ExperimentalContracts::class) | ||
inline fun embed(builder: EmbedBuilder.() -> Unit) { | ||
contract { | ||
callsInPlace(builder, InvocationKind.EXACTLY_ONCE) | ||
} | ||
embeds.add(EmbedBuilder().apply(builder)) | ||
} | ||
|
||
override fun toRequest(): WebhookEditMessageRequest = WebhookEditMessageRequest( | ||
_content, Optional.missingOnEmpty(embeds.map(EmbedBuilder::toRequest)), _allowedMentions | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters