Skip to content

Commit

Permalink
commit #333
Browse files Browse the repository at this point in the history
  • Loading branch information
HopeBaron committed Jun 25, 2021
1 parent 68f8795 commit 4f1e5e3
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 15 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions common/src/main/kotlin/entity/Interactions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ sealed class ApplicationCommandOptionType(val type: Int) {
6 -> User
7 -> Channel
8 -> Role
9 -> Mentionable
else -> Unknown(type)
}
}
Expand Down
1 change: 1 addition & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -5786,6 +5786,7 @@ public final class dev/kord/core/entity/interaction/InteractionKt {
public static final fun channel (Ldev/kord/core/entity/interaction/OptionValue;)Ldev/kord/core/entity/channel/ResolvedChannel;
public static final fun int (Ldev/kord/core/entity/interaction/OptionValue;)I
public static final fun member (Ldev/kord/core/entity/interaction/OptionValue;)Ldev/kord/core/entity/Member;
public static final fun mentionable (Ldev/kord/core/entity/interaction/OptionValue;)Ldev/kord/core/entity/Entity;
public static final fun role (Ldev/kord/core/entity/interaction/OptionValue;)Ldev/kord/core/entity/Role;
public static final fun string (Ldev/kord/core/entity/interaction/OptionValue;)Ljava/lang/String;
public static final fun user (Ldev/kord/core/entity/interaction/OptionValue;)Ldev/kord/core/entity/User;
Expand Down
11 changes: 8 additions & 3 deletions core/src/main/kotlin/entity/interaction/Interaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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
}
26 changes: 16 additions & 10 deletions rest/api/rest.api
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ public abstract class dev/kord/rest/builder/interaction/BaseApplicationBuilder {
public final fun group (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun int (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun int$default (Ldev/kord/rest/builder/interaction/BaseApplicationBuilder;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun mentionable (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun mentionable$default (Ldev/kord/rest/builder/interaction/BaseApplicationBuilder;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun role (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun role$default (Ldev/kord/rest/builder/interaction/BaseApplicationBuilder;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public abstract fun setOptions (Ljava/util/List;)V
Expand Down Expand Up @@ -695,10 +697,10 @@ public final class dev/kord/rest/builder/interaction/EphemeralFollowupMessageCre
public fun getComponents ()Ljava/util/List;
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public final fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public final fun setTts (Ljava/lang/Boolean;)V
public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageCreateRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand All @@ -709,10 +711,10 @@ public final class dev/kord/rest/builder/interaction/EphemeralFollowupMessageMod
public fun getComponents ()Ljava/util/List;
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setComponents (Ljava/util/List;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public fun setEmbeds (Ljava/util/List;)V
public fun toRequest ()Ldev/kord/rest/json/request/FollowupMessageModifyRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand Down Expand Up @@ -748,9 +750,7 @@ public abstract interface class dev/kord/rest/builder/interaction/FollowupMessag
public abstract fun getComponents ()Ljava/util/List;
public abstract fun getContent ()Ljava/lang/String;
public abstract fun getEmbeds ()Ljava/util/List;
public abstract fun getTts ()Ljava/lang/Boolean;
public abstract fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public abstract fun setTts (Ljava/lang/Boolean;)V
}

public final class dev/kord/rest/builder/interaction/FollowupMessageBuildersKt {
Expand All @@ -771,6 +771,10 @@ public final class dev/kord/rest/builder/interaction/IntChoiceBuilder : dev/kord
public synthetic fun choice (Ljava/lang/String;Ljava/lang/Object;)V
}

public final class dev/kord/rest/builder/interaction/MentionableBuilder : dev/kord/rest/builder/interaction/OptionsBuilder {
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
}

public abstract class dev/kord/rest/builder/interaction/OptionsBuilder : dev/kord/rest/builder/RequestBuilder {
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ldev/kord/common/entity/ApplicationCommandOptionType;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getDefault ()Ljava/lang/Boolean;
Expand All @@ -794,10 +798,10 @@ public final class dev/kord/rest/builder/interaction/PublicFollowupMessageCreate
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public final fun getFiles ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public final fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public final fun setTts (Ljava/lang/Boolean;)V
public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageCreateRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand All @@ -811,10 +815,10 @@ public final class dev/kord/rest/builder/interaction/PublicFollowupMessageModify
public fun getContent ()Ljava/lang/String;
public fun getEmbeds ()Ljava/util/List;
public final fun getFiles ()Ljava/util/List;
public fun getTts ()Ljava/lang/Boolean;
public fun setAllowedMentions (Ldev/kord/rest/builder/message/AllowedMentionsBuilder;)V
public fun setComponents (Ljava/util/List;)V
public fun setContent (Ljava/lang/String;)V
public fun setTts (Ljava/lang/Boolean;)V
public fun setEmbeds (Ljava/util/List;)V
public fun toRequest ()Ldev/kord/rest/json/request/MultipartFollowupMessageModifyRequest;
public synthetic fun toRequest ()Ljava/lang/Object;
}
Expand Down Expand Up @@ -872,6 +876,8 @@ public final class dev/kord/rest/builder/interaction/SubCommandBuilder : dev/kor
public static synthetic fun channel$default (Ldev/kord/rest/builder/interaction/SubCommandBuilder;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun int (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun int$default (Ldev/kord/rest/builder/interaction/SubCommandBuilder;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun mentionable (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun mentionable$default (Ldev/kord/rest/builder/interaction/SubCommandBuilder;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun role (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun role$default (Ldev/kord/rest/builder/interaction/SubCommandBuilder;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun string (Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

}

}


Expand All @@ -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
)
Expand Down Expand Up @@ -154,7 +164,7 @@ class ApplicationCommandModifyBuilder : BaseApplicationBuilder(),
return ApplicationCommandModifyRequest(
_name,
_description,
_options.mapList { it.toRequest() },
_options.mapList { it.toRequest() },
_defaultPermission
)

Expand Down
13 changes: 13 additions & 0 deletions rest/src/main/kotlin/builder/interaction/OptionsBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
sealed class BaseCommandOptionBuilder(
Expand Down Expand Up @@ -169,6 +173,15 @@ class SubCommandBuilder(name: String, description: String) :
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))

}

}

@KordDsl
Expand Down

0 comments on commit 4f1e5e3

Please sign in to comment.