Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mentionable support #333

Merged
merged 4 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
}
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