From 32d126e9979710f2e8e01e1d87d490a6ecfc78d6 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Mon, 1 Jul 2024 13:06:38 +0100 Subject: [PATCH] Add test command for autocomplete --- .../extensions/ArgumentTestExtension.kt | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/ArgumentTestExtension.kt b/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/ArgumentTestExtension.kt index 81c8c3cda5..6db266480d 100644 --- a/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/ArgumentTestExtension.kt +++ b/test-bot/src/main/kotlin/com/kotlindiscord/kord/extensions/testbot/extensions/ArgumentTestExtension.kt @@ -9,9 +9,11 @@ package com.kotlindiscord.kord.extensions.testbot.extensions import com.kotlindiscord.kord.extensions.commands.Arguments +import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.stringChoice import com.kotlindiscord.kord.extensions.commands.converters.impl.* import com.kotlindiscord.kord.extensions.extensions.Extension import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand +import com.kotlindiscord.kord.extensions.utils.suggestStringCollection import com.kotlindiscord.kord.extensions.utils.suggestStringMap import dev.kord.common.entity.ChannelType import dev.kord.common.entity.ForumTag @@ -110,6 +112,20 @@ public class ArgumentTestExtension : Extension() { } } } + + publicSlashCommand(::AutocompleteArguments) { + name = "autocomplete" + description = "Test auto-completion events" + + action { + respond { + content = buildString { + appendLine("**One:** ${arguments.one}") + appendLine("**Two:** ${arguments.two}") + } + } + } + } } public inner class TagArgs : Arguments() { @@ -192,4 +208,29 @@ public class ArgumentTestExtension : Extension() { description = "A custom or Unicode emoji" } } + + public inner class AutocompleteArguments : Arguments() { + override val parseForAutocomplete: Boolean = true + + public val one: String by stringChoice { + name = "one" + description = "Choice argument" + + choice("O", "o") + choice("T", "t") + choice("F", "f") + } + + public val two: String by string { + name = "two" + description = "Autocomplete argument" + + autoComplete { + suggestStringCollection( + listOf("one", "two", "three", "four") + .filter { it.contains(one.lowercase()) } + ) + } + } + } }