1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-02 22:59:48 +00:00

add overloads for containsCommand

This commit is contained in:
2025-08-11 15:28:21 +06:00
parent 08c885de2f
commit 2182e44bc2
2 changed files with 9 additions and 3 deletions

View File

@@ -1610,6 +1610,8 @@ public abstract interface class dev/inmo/tgbotapi/extensions/behaviour_builder/u
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiverKt { public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/DefaultCustomBehaviourContextAndTypeReceiverKt {
public static final fun botInfo (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun botInfo (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun containsCommand (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun containsCommand (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlin/text/Regex;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun containsCommand (Ljava/util/List;Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun containsCommand (Ljava/util/List;Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun containsCommand (Ljava/util/List;Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlin/text/Regex;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun containsCommand (Ljava/util/List;Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlin/text/Regex;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun optionallyWithDefaultReceiver (Lkotlin/jvm/functions/Function3;ZLdev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextData;)Lkotlin/jvm/functions/Function3; public static final fun optionallyWithDefaultReceiver (Lkotlin/jvm/functions/Function3;ZLdev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextData;)Lkotlin/jvm/functions/Function3;

View File

@@ -31,24 +31,28 @@ suspend fun BehaviourContext.botInfo(): ExtendedBot? {
} }
} }
context(textSources: TextSourcesList, bc: BehaviourContext) suspend fun BehaviourContext.containsCommand(commandRegex: Regex, textSources: TextSourcesList) = textSources.any {
suspend fun containsCommand(commandRegex: Regex) = textSources.any {
val command = it.botCommandTextSourceOrNull() ?.takeIf { val command = it.botCommandTextSourceOrNull() ?.takeIf {
commandRegex.matches(it.command) commandRegex.matches(it.command)
} ?: return@any false } ?: return@any false
if (command.username == null) { if (command.username == null) {
return@any true return@any true
} }
val botInfo = bc.botInfo() val botInfo = botInfo()
if (botInfo == null || command.username == botInfo.username) { if (botInfo == null || command.username == botInfo.username) {
return@any true return@any true
} }
false false
} }
context(textSources: TextSourcesList, bc: BehaviourContext)
suspend fun containsCommand(commandRegex: Regex) = bc.containsCommand(commandRegex, textSources)
context(textSources: TextSourcesList, bc: BehaviourContext) context(textSources: TextSourcesList, bc: BehaviourContext)
suspend fun containsCommand(command: String) = containsCommand(Regex(command)) suspend fun containsCommand(command: String) = containsCommand(Regex(command))
suspend fun BehaviourContext.containsCommand(command: String, textSources: TextSourcesList) = containsCommand(Regex(command), textSources)
@Warning("It is internal API and can be changed without notes") @Warning("It is internal API and can be changed without notes")
fun <BC : BehaviourContext, R, U : Update> CustomBehaviourContextAndTypeReceiver<BC, R, U>.withDefaultReceiver( fun <BC : BehaviourContext, R, U : Update> CustomBehaviourContextAndTypeReceiver<BC, R, U>.withDefaultReceiver(
data: BehaviourContextData data: BehaviourContextData