-
Notifications
You must be signed in to change notification settings - Fork 81
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
- Loading branch information
1 parent
d17c312
commit 64c299d
Showing
8 changed files
with
499 additions
and
124 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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
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.EmbedRequest | ||
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<EmbedRequest> = 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).toRequest()) | ||
} | ||
|
||
override fun toRequest(): WebhookEditMessageRequest = WebhookEditMessageRequest( | ||
_content, Optional.missingOnEmpty(embeds), _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
Oops, something went wrong.