Skip to content

Commit

Permalink
Add test command for autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Jul 1, 2024
1 parent 3abf50d commit 32d126e
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()) }
)
}
}
}
}

0 comments on commit 32d126e

Please sign in to comment.