1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-12-30 09:59:18 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
b1931900e7 Update BotCommandTextSource.kt 2022-08-25 02:11:04 +06:00
fab3af48d6 Update WaitCommandsMessages.kt 2022-08-25 02:04:19 +06:00
8d7563b6e4 Update WaitCommandsMessages.kt 2022-08-25 02:02:45 +06:00
2 changed files with 5 additions and 4 deletions

View File

@@ -40,7 +40,7 @@ suspend fun BehaviourContext.waitCommandMessage(
) = waitCommandMessage(Regex(command), initRequest, errorFactory)
fun Flow<CommonMessage<TextContent>>.requireCommandAtStart() = filter {
(it.content.textSources.firstOrNull() as? BotCommandTextSource) != null
it.content.textSources.firstOrNull() is BotCommandTextSource
}
/**
@@ -61,7 +61,7 @@ fun Flow<CommonMessage<TextContent>>.requireSingleCommand() = filter {
}
}
true
count == 1
}
/**

View File

@@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.message.textsources
import dev.inmo.tgbotapi.types.usernameRegex
import dev.inmo.tgbotapi.types.Username
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable
@@ -17,8 +18,8 @@ data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstru
val command: String by lazy {
commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!"
}
val username: String? by lazy {
usernameRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol "@"
val username: Username? by lazy {
Username(usernameRegex.find(source) ?.value ?: return@lazy null)
}
override val markdown: String by lazy { source.commandMarkdown() }