ValidationContext

class ValidationContext<out T>(val converter: Converter<*, *, *, *>, val value: T, val context: CommandContext, locale: Locale) : CheckContext<Event>

Class representing the context for an argument validator. This allows the storage of validation steps and a message for the user.

Constructors

Link copied to clipboard
constructor(converter: Converter<*, *, *, *>, value: T, context: CommandContext, locale: Locale)

Properties

Link copied to clipboard

Command context that triggered this validation

Link copied to clipboard
val converter: Converter<*, *, *, *>
Link copied to clipboard

Translation key to use for the error response message, if not the default.

Link copied to clipboard
val event: Event

Event of type T

Link copied to clipboard

Locale for the current check context

Link copied to clipboard

Human-readable message for the user, if any.

Link copied to clipboard

Whether this check has passed.

Link copied to clipboard
val value: T

Value of type T

Functions

Link copied to clipboard
suspend fun CheckContext<*>.anyGuild()

Check asserting an Event was fired within a guild.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.channelAbove(builder: suspend (T) -> GuildChannelBehavior)

Check asserting that the channel an Event fired in is above the given channel in the channel list.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.channelBelow(builder: suspend (T) -> GuildChannelBehavior)

Check asserting that the channel an Event fired in is below the given channel in the channel list.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.channelHigherThan(id: Snowflake)

Check asserting that the channel an Event fired in is above the given channel in the channel list.

Link copied to clipboard
suspend fun CheckContext<*>.channelIsNsfw()

Check asserting that the channel an Event fired in is marked as NSFW.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.channelLowerThan(id: Snowflake)

Check asserting that the channel an Event fired in is below the given channel in the channel list.

Link copied to clipboard

Check asserting that the channel an Event fired in is marked as NSFW, or is in an NSFW guild.

Link copied to clipboard
suspend fun CheckContext<*>.channelType(vararg channelTypes: ChannelType)

Check asserting that the channel an Event fired in is of a given set of types.

Link copied to clipboard
fun fail(message: Key? = null)
fun fail(message: String)

Mark this check as having failed, optionally providing a message for the user.

Link copied to clipboard
suspend fun failIf(message: Key? = null, callback: suspend () -> Boolean): Boolean
suspend fun failIf(message: String, callback: suspend () -> Boolean): Boolean

If callback returns true, mark this check as having failed, optionally providing a message for the user.

fun failIf(value: Boolean, message: Key? = null): Boolean
fun failIf(value: Boolean, message: String): Boolean

If value is true, mark this check as having failed, optionally providing a message for the user.

Link copied to clipboard
suspend fun failIfNot(message: Key? = null, callback: suspend () -> Boolean): Boolean
suspend fun failIfNot(message: String, callback: suspend () -> Boolean): Boolean

If callback returns false, mark this check as having failed, optionally providing a message for the user.

fun failIfNot(value: Boolean, message: Key? = null): Boolean
fun failIfNot(value: Boolean, message: String): Boolean

If value is false, mark this check as having failed, optionally providing a message for the user.

Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
open override fun getMessageKey(): Key?

Get a pre-translation Key representing the current check failure message, if the check has failed, and a message was set.

Link copied to clipboard

Get the translated check failure message, if the check has failed and a message was set.

Link copied to clipboard
suspend fun CheckContext<*>.guildNsfwLevelHigher(level: NsfwLevel)

Check asserting an Event was fired within a guild with a NSFW level higher than the provided one..

Link copied to clipboard
suspend fun CheckContext<*>.guildNsfwLevelHigherOrEqual(level: NsfwLevel)

Check asserting an Event was fired within a guild with a NSFW level higher than or equal to the provided one..

Link copied to clipboard
suspend fun CheckContext<*>.guildNsfwLevelLower(level: NsfwLevel)

Check asserting an Event was fired within a guild with a NSFW level lower than the provided one..

Link copied to clipboard
suspend fun CheckContext<*>.guildNsfwLevelLowerOrEqual(level: NsfwLevel)

Check asserting an Event was fired within a guild with a NSFW level lower than or equal to the provided one..

Link copied to clipboard
suspend fun CheckContext<*>.hasGuildNsfwLevel(level: NsfwLevel)

Check asserting an Event was fired within a guild with the given NSFW level.

Link copied to clipboard
suspend fun CheckContext<*>.hasPermission(perm: Permission)

Check asserting that the user an Event fired for has a given permission, or the Administrator permission.

Link copied to clipboard
suspend fun CheckContext<*>.hasPermissions(perms: Permissions)

Check asserting that the user an Event fired for has the given permissions set, or the Administrator permission.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.hasRole(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.hasRole(builder: suspend (T) -> RoleBehavior)

Check asserting that the user an Event fired for has a given role.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.inCategory(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.inCategory(builder: suspend (T) -> CategoryBehavior)

Check asserting that an Event fired within a given channel category.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.inChannel(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.inChannel(builder: suspend (T) -> ChannelBehavior)

Check asserting that an Event fired within a given channel.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.inGuild(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.inGuild(builder: suspend (T) -> GuildBehavior)

Check asserting that the guild an Event fired for is in a specific guild.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.inTopChannel(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.inTopChannel(builder: suspend (T) -> ChannelBehavior)

Check asserting that an Event fired within a given channel. If the event fired within a thread, it checks the thread's parent channel instead.

Link copied to clipboard
suspend fun CheckContext<*>.isBot()

Check asserting the user for an Event is a bot. Will fail if the event doesn't concern a user.

Link copied to clipboard
suspend fun CheckContext<*>.isBotAdmin()

For bots owned by a team, check asserting the user for an Event is one of the bot's admins.

Link copied to clipboard
suspend fun CheckContext<*>.isBotOwner()

For bots with single owners, check asserting the user for an Event is the bot's owner.

Link copied to clipboard
suspend fun CheckContext<*>.isInThread()

Check asserting that the event was triggered within a thread.

Link copied to clipboard
suspend fun CheckContext<*>.isNotBot()

Check asserting the user for an Event is not a bot. Will pass if the event doesn't concern a user.

Link copied to clipboard
suspend fun CheckContext<*>.isNotBotAdmin()

For bots owned by a team, check asserting the user for an Event is not one of the bot's admins.

Link copied to clipboard
suspend fun CheckContext<*>.isNotBotOwner()

For bots with single owners, check asserting the user for an Event is not the bot's owner.

Link copied to clipboard
suspend fun CheckContext<*>.isNotInThread()

Check asserting that the event was not triggered within a thread, including events that don't concern any specific channel.

Link copied to clipboard
suspend fun CheckContext<*>.noGuild()

Check asserting an Event was not fired within a guild.

Link copied to clipboard

Check asserting that the channel an Event fired in is not marked as NSFW.

Link copied to clipboard

Check asserting that the channel an Event fired in is not marked as NSFW, and is not in an NSFW guild.

Link copied to clipboard
suspend fun CheckContext<*>.notChannelType(vararg channelTypes: ChannelType)

Check asserting that the channel an Event fired in is not of a given set of types.

Link copied to clipboard
suspend fun CheckContext<*>.notHasGuildNsfwLevel(level: NsfwLevel)

Check asserting an Event was fired within a guild without the given NSFW level.

Link copied to clipboard
suspend fun CheckContext<*>.notHasPermission(perm: Permission)

Check asserting that the user an Event fired for does not have a given permission or the Administrator permission.

Link copied to clipboard
suspend fun CheckContext<*>.notHasPermissions(perms: Permissions)

Check asserting that the user an Event fired for does not have the given permissions set or the Administrator permission.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.notHasRole(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.notHasRole(builder: suspend (T) -> RoleBehavior)

Check asserting that the user an Event fired for does not have a given role.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.notInCategory(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.notInCategory(builder: suspend (T) -> CategoryBehavior)

Check asserting that an Event did not fire within a given channel category.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.notInChannel(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.notInChannel(builder: suspend (T) -> ChannelBehavior)

Check asserting that an Event did not fire within a given channel.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.notInGuild(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.notInGuild(builder: suspend (T) -> GuildBehavior)

Check asserting that the guild an Event fired for is not in a specific guild.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.notInTopChannel(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.notInTopChannel(builder: suspend (T) -> ChannelBehavior)

Check asserting that an Event did not fire within a given channel. If the event fired within a thread, it checks the thread's parent channel instead.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.or(body: Check<T>)

Convenience function allowing you to pass this check context, if the checks provided in the body pass – even if the check context is failing.

Link copied to clipboard
fun pass()

Mark this check as having passed successfully.

Link copied to clipboard
fun passIf(value: Boolean): Boolean

If value is true, mark this check as having passed.

suspend fun passIf(callback: suspend () -> Boolean): Boolean

If callback returns true, mark this check as having passed.

Link copied to clipboard

If value is true, mark this check as having passed.

suspend fun passIfNot(callback: suspend () -> Boolean): Boolean

If callback returns true, mark this check as having passed.

Link copied to clipboard

Silence the current check by removing any message it may have set.

Link copied to clipboard

If this validator has failed, throw a DiscordRelayedException with the translated message, if any.

Link copied to clipboard

If this check has failed and a message is set, throw a DiscordRelayedException with the translated message.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.topRoleEqual(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.topRoleEqual(builder: suspend (T) -> RoleBehavior)

Check asserting that the top role for the user an Event fired for is equal to a given role.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.topRoleHigher(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.topRoleHigher(builder: suspend (T) -> RoleBehavior)

Check asserting that the top role for the user an Event fired for is higher than a given role.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.topRoleHigherOrEqual(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.topRoleHigherOrEqual(builder: suspend (T) -> RoleBehavior)

Check asserting that the top role for the user an Event fired for is higher than or equal to a given

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.topRoleLower(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.topRoleLower(builder: suspend (T) -> RoleBehavior)

Check asserting that the top role for the user an Event fired for is lower than a given role.

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.topRoleLowerOrEqual(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.topRoleLowerOrEqual(builder: suspend (T) -> RoleBehavior)

Check asserting that the top role for the user an Event fired for is lower than or equal to a given

Link copied to clipboard
suspend fun <T : Event> CheckContext<T>.topRoleNotEqual(id: Snowflake)
suspend fun <T : Event> CheckContext<T>.topRoleNotEqual(builder: suspend (T) -> RoleBehavior)

Check asserting that the top role for the user an Event fired for is not equal to a given role.

Link copied to clipboard
inline fun <T : Any> Boolean.whenFalse(body: () -> T?): T?

Call the given block if the Boolean receiver is false.

Link copied to clipboard
inline fun <T : Any> Boolean.whenTrue(body: () -> T?): T?

Call the given block if the Boolean receiver is true.