-
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.
- Loading branch information
1 parent
cb36f95
commit 441754d
Showing
9 changed files
with
295 additions
and
35 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
73 changes: 73 additions & 0 deletions
73
core/src/main/kotlin/behavior/interaction/AutoCompleteInteractionBehavior.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,73 @@ | ||
package dev.kord.core.behavior.interaction | ||
|
||
import dev.kord.common.entity.Choice | ||
import dev.kord.common.entity.DiscordAutoComplete | ||
import dev.kord.rest.builder.interaction.IntChoiceBuilder | ||
import dev.kord.rest.builder.interaction.NumberChoiceBuilder | ||
import dev.kord.rest.builder.interaction.StringChoiceBuilder | ||
import kotlin.contracts.ExperimentalContracts | ||
import kotlin.contracts.InvocationKind | ||
import kotlin.contracts.contract | ||
|
||
/** | ||
* Behavior of an AutoComplete interaction. | ||
* | ||
* @see respondNumber | ||
* @see respondString | ||
* @see respondInt | ||
* @see respond | ||
*/ | ||
public interface AutoCompleteInteractionBehavior : InteractionBehavior | ||
|
||
/** | ||
* Responds with the int choices specified by [builder]. | ||
* | ||
* @see IntChoiceBuilder | ||
*/ | ||
@OptIn(ExperimentalContracts::class) | ||
public suspend inline fun AutoCompleteInteractionBehavior.respondInt(builder: IntChoiceBuilder.() -> Unit) { | ||
contract { | ||
callsInPlace(builder, InvocationKind.EXACTLY_ONCE) | ||
} | ||
|
||
kord.rest.interaction.createIntAutoCompleteInteractionResponse(id, token, builder) | ||
} | ||
|
||
/** | ||
* Responds with the number choices specified by [builder]. | ||
* | ||
* @see NumberChoiceBuilder | ||
*/ | ||
@OptIn(ExperimentalContracts::class) | ||
public suspend inline fun AutoCompleteInteractionBehavior.respondNumber(builder: NumberChoiceBuilder.() -> Unit) { | ||
contract { | ||
callsInPlace(builder, InvocationKind.EXACTLY_ONCE) | ||
} | ||
|
||
kord.rest.interaction.createNumberAutoCompleteInteractionResponse(id, token, builder) | ||
} | ||
|
||
/** | ||
* Responds with the string choices specified by [builder]. | ||
* | ||
* @see StringChoiceBuilder | ||
*/ | ||
@OptIn(ExperimentalContracts::class) | ||
public suspend inline fun AutoCompleteInteractionBehavior.respondString(builder: StringChoiceBuilder.() -> Unit) { | ||
contract { | ||
callsInPlace(builder, InvocationKind.EXACTLY_ONCE) | ||
} | ||
|
||
kord.rest.interaction.createStringAutoCompleteInteractionResponse(id, token, builder) | ||
} | ||
|
||
/** | ||
* Responds with [choices] to this auto-complete request. | ||
*/ | ||
public suspend inline fun <reified T> AutoCompleteInteractionBehavior.respond(choices: List<Choice<T>>) { | ||
kord.rest.interaction.createAutoCompleteInteractionResponse( | ||
id, | ||
token, | ||
DiscordAutoComplete(choices) | ||
) | ||
} |
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
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.