diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e895e42333..b1ddc2f1dc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 0.7.2 + +## Additions + +* Allow adding a mentionable argument to commands + +## Fixes + +* Mentionable arguments now correctly retrieve their entity. + # 0.7.1 ## Breaking diff --git a/core/src/main/kotlin/entity/interaction/Interaction.kt b/core/src/main/kotlin/entity/interaction/Interaction.kt index bd1424603fc..096d1784ddb 100644 --- a/core/src/main/kotlin/entity/interaction/Interaction.kt +++ b/core/src/main/kotlin/entity/interaction/Interaction.kt @@ -303,11 +303,11 @@ fun OptionValue(value: CommandArgument<*>, resolvedObjects: ResolvedObjects?): O is CommandArgument.MentionableArgument -> { val channel = resolvedObjects?.channels.orEmpty()[value.value] - val user = resolvedObjects?.channels.orEmpty()[value.value] + val user = resolvedObjects?.users.orEmpty()[value.value] val member = resolvedObjects?.members.orEmpty()[value.value] - val role = resolvedObjects?.members.orEmpty()[value.value] + val role = resolvedObjects?.roles.orEmpty()[value.value] - OptionValue.MentionableOptionValue((channel ?: user ?: member ?: role)!!) + OptionValue.MentionableOptionValue((channel ?: member ?: user ?: role)!!) } is CommandArgument.RoleArgument -> { @@ -459,3 +459,8 @@ fun OptionValue<*>.boolean() = value as Boolean @KordPreview fun OptionValue<*>.int() = value as Int + +@KordPreview +fun OptionValue<*>.mentionable(): Entity { + return value as Entity +} diff --git a/rest/src/main/kotlin/builder/interaction/ApplicationCommandBuilders.kt b/rest/src/main/kotlin/builder/interaction/ApplicationCommandBuilders.kt index a97c6345323..4764981f759 100644 --- a/rest/src/main/kotlin/builder/interaction/ApplicationCommandBuilders.kt +++ b/rest/src/main/kotlin/builder/interaction/ApplicationCommandBuilders.kt @@ -85,6 +85,15 @@ sealed class BaseApplicationBuilder { if (options == null) options = mutableListOf() options!!.add(ChannelBuilder(name, description).apply(builder)) } + + @OptIn(ExperimentalContracts::class) + inline fun mentionable(name: String, description: String, builder: MentionableBuilder.() -> Unit = {}) { + contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } + if (options == null) options = mutableListOf() + options!!.add(MentionableBuilder(name, description).apply(builder)) + + } + } @@ -102,7 +111,8 @@ class ApplicationCommandCreateBuilder( var defaultPermission: Boolean? by ::_defaultPermission.delegate() override fun toRequest(): ApplicationCommandCreateRequest { - return ApplicationCommandCreateRequest(name, + return ApplicationCommandCreateRequest( + name, description, _options.mapList { it.toRequest() }, _defaultPermission ) @@ -154,7 +164,7 @@ class ApplicationCommandModifyBuilder : BaseApplicationBuilder(), return ApplicationCommandModifyRequest( _name, _description, - _options.mapList { it.toRequest() }, + _options.mapList { it.toRequest() }, _defaultPermission ) diff --git a/rest/src/main/kotlin/builder/interaction/OptionsBuilder.kt b/rest/src/main/kotlin/builder/interaction/OptionsBuilder.kt index a0542b56fda..31efa281d17 100644 --- a/rest/src/main/kotlin/builder/interaction/OptionsBuilder.kt +++ b/rest/src/main/kotlin/builder/interaction/OptionsBuilder.kt @@ -101,6 +101,10 @@ class RoleBuilder(name: String, description: String) : class ChannelBuilder(name: String, description: String) : OptionsBuilder(name, description, ApplicationCommandOptionType.Channel) +@KordPreview +class MentionableBuilder(name: String, description: String) : + OptionsBuilder(name, description, ApplicationCommandOptionType.Mentionable) + @KordDsl @KordPreview class MentionableBuilder(name: String, description: String) :