a little bit refactor hasCommands

This commit is contained in:
InsanusMokrassar 2022-10-30 20:10:12 +06:00
parent 7471da4ff0
commit 777a58ce9a
1 changed files with 5 additions and 3 deletions

View File

@ -1,8 +1,9 @@
package dev.inmo.tgbotapi.extensions.utils.updates
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
/**
* A predicate to test whether a message contains any commands in its body.
@ -20,8 +21,9 @@ import dev.inmo.tgbotapi.types.message.content.TextContent
* @return true if this [CommonMessage] contains any commands. False otherwise.
* @see hasNoCommands
*/
fun CommonMessage<*>.hasCommands(): Boolean =
(this.content as? TextContent)?.textSources?.any { it.botCommandTextSourceOrNull() != null } ?: false
fun CommonMessage<*>.hasCommands(): Boolean = withContentOrNull<TextContent>() ?.content ?.textSources ?.any {
it is BotCommandTextSource
} ?: false
/**
* A predicate to test whether a message contains any commands in its body.