1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-21 15:53:47 +00:00

Merge pull request #909 from InsanusMokrassar/18.2.2

18.2.2
This commit is contained in:
InsanusMokrassar 2024-10-21 18:26:54 +06:00 committed by GitHub
commit 482c375327
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 555 additions and 91 deletions

View File

@ -1,5 +1,17 @@
# TelegramBotAPI changelog
## 18.2.2
* `Version`:
* `Kotlin`: `2.0.20` -> `2.0.21`
* `MicroUtils`: `0.22.4` -> `0.22.7`
* `Core`:
* Fixes in blockquotes serializations
* Now `RawMessageEntity` is public. It is still under `Warning` annotation and is subject of changes
* `BehaviourBuilder`:
* Add `CommonMessageFilterExcludeCommand` to filter commands in messages
* Add `minus` operation for `SimpleFilter`s
## 18.2.1
* `Version`:

View File

@ -6,4 +6,4 @@ kotlin.incremental=true
kotlin.incremental.js=true
library_group=dev.inmo
library_version=18.2.1
library_version=18.2.2

View File

@ -1,6 +1,6 @@
[versions]
kotlin = "2.0.20"
kotlin = "2.0.21"
kotlin-serialization = "1.7.3"
kotlin-coroutines = "1.9.0"
@ -10,10 +10,10 @@ korlibs = "5.4.0"
uuid = "0.8.4"
ktor = "2.3.12"
ksp = "2.0.20-1.0.25"
ksp = "2.0.21-1.0.25"
kotlin-poet = "1.18.1"
microutils = "0.22.4"
microutils = "0.22.7"
kslog = "1.3.6"
versions = "0.51.0"

View File

@ -852,6 +852,15 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/filters/ChatMe
public static final fun getChatMemberUnsubscribedFilter ()Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
}
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/filters/CommonMessageFilterExcludeCommandKt {
public static final fun CommonMessageFilterExcludeCommand (Ljava/lang/String;Z)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static synthetic fun CommonMessageFilterExcludeCommand$default (Ljava/lang/String;ZILjava/lang/Object;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
}
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/filters/CommonMessageFilterIncludeTextKt {
public static final fun CommonMessageFilterIncludeText (Lkotlin/text/Regex;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
}
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/filters/MessageFilterByChatKt {
public static final fun getCallbackQueryFilterByUser ()Lkotlin/jvm/functions/Function4;
public static final fun getChatJoinRequestFilterByChat ()Lkotlin/jvm/functions/Function4;
@ -1488,9 +1497,11 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFi
public static final fun listAll (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static final fun listAny (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static final fun listNone (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static final fun minus (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static final fun not (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static final fun plus (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static final fun times (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
public static final fun unaryMinus (Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;
}
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SubcontextUpdatesFilterOperationsKt {

View File

@ -0,0 +1,30 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.CommonMessageFilter
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.not
import dev.inmo.tgbotapi.extensions.utils.textedContentOrNull
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
/**
* Use as initialFilter. Will exclude messages with [excludedCommand] if it is not null, if null - all messages with commands.
* If [textBeginOnly] set to false, all commands inside of message will be taken in attention.
*
* **It is supposed, that you will pass command name without `/` or `!`**
*
* @param excludedCommand Pass non-null value to search specific command or null (default) to search any command
* @param textBeginOnly Pass true (default) to check only start of message. Pass false to search in whole text of
* content
*/
fun CommonMessageFilterExcludeCommand(
excludedCommand: String? = null,
textBeginOnly: Boolean = true
): CommonMessageFilter<*> {
return !CommonMessageFilterIncludeText(
when {
excludedCommand == null -> BotCommandTextSource.CommandRegex
textBeginOnly -> Regex("^[/!]$excludedCommand(\\s|$)")
!textBeginOnly -> Regex("[/!]$excludedCommand(\\s|$)")
else -> error("Unreachable code has been reached. It is error and must not happen")
}
)
}

View File

@ -0,0 +1,15 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.CommonMessageFilter
import dev.inmo.tgbotapi.extensions.utils.textedContentOrNull
/**
* Includes messages only contains text with [textRegex]
*/
fun CommonMessageFilterIncludeText(
textRegex: Regex,
): CommonMessageFilter<*> {
return CommonMessageFilter {
it.content.textedContentOrNull() ?.text ?.contains(textRegex) == true
}
}

View File

@ -59,3 +59,14 @@ infix operator fun <T> SimpleFilter<T>?.plus(other: SimpleFilter<T>?): SimpleFil
operator fun <T> SimpleFilter<T>.not() = SimpleFilter<T> {
!this(it)
}
/**
* Works as [not]
*/
operator fun <T> SimpleFilter<T>.unaryMinus() = not()
/**
* Making +! operation. In fact that means that [other] will be inversed with [not] and that added to [this] via
* [plus]
*/
operator fun <T> SimpleFilter<T>?.minus(other: SimpleFilter<T>?): SimpleFilter<T> = this + (other ?.not())

View File

@ -312,37 +312,6 @@ public abstract interface class dev/inmo/tgbotapi/bot/ktor/KtorCallFactory {
public abstract fun makeCall (Lio/ktor/client/HttpClient;Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlinx/serialization/json/Json;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public abstract interface class dev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder {
public static final field Companion Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder$Companion;
public abstract fun onAfterCallFactoryMakeCall (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestException (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestResultAbsent (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestResultPresented (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestReturnResult (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder$Companion : dev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder {
public fun onAfterCallFactoryMakeCall (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestException (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultAbsent (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultPresented (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestReturnResult (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder$DefaultImpls {
public static fun onAfterCallFactoryMakeCall (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestException (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestResultAbsent (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestResultPresented (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestReturnResult (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutorBuilder {
public fun <init> (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;)V
public final fun build ()Ldev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor;
@ -351,15 +320,16 @@ public final class dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutorBuilder {
public final fun getExcludeDefaultFactories ()Z
public final fun getJsonFormatter ()Lkotlinx/serialization/json/Json;
public final fun getLogger ()Ldev/inmo/kslog/common/KSLog;
public final fun getPipelineStepsHolder ()Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;
public final fun getPipelineStepsHolder ()Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;
public final fun getRequestsLimiter ()Ldev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;
public final fun getTelegramAPIUrlsKeeper ()Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;
public final fun includeMiddlewares (Lkotlin/jvm/functions/Function1;)V
public final fun setCallsFactories (Ljava/util/List;)V
public final fun setClient (Lio/ktor/client/HttpClient;)V
public final fun setExcludeDefaultFactories (Z)V
public final fun setJsonFormatter (Lkotlinx/serialization/json/Json;)V
public final fun setLogger (Ldev/inmo/kslog/common/KSLog;)V
public final fun setPipelineStepsHolder (Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;)V
public final fun setPipelineStepsHolder (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;)V
public final fun setRequestsLimiter (Ldev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;)V
public final fun setTelegramAPIUrlsKeeper (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;)V
}
@ -374,8 +344,39 @@ public final class dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutorFactoriesKt {
}
public final class dev/inmo/tgbotapi/bot/ktor/KtorRequestsExecutorKt {
public static final fun KtorRequestsExecutor (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;Lio/ktor/client/HttpClient;Ljava/util/List;ZLdev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;Lkotlinx/serialization/json/Json;Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ldev/inmo/kslog/common/KSLog;)Ldev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor;
public static synthetic fun KtorRequestsExecutor$default (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;Lio/ktor/client/HttpClient;Ljava/util/List;ZLdev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;Lkotlinx/serialization/json/Json;Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;Ldev/inmo/kslog/common/KSLog;ILjava/lang/Object;)Ldev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor;
public static final fun KtorRequestsExecutor (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;Lio/ktor/client/HttpClient;Ljava/util/List;ZLdev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;Lkotlinx/serialization/json/Json;Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ldev/inmo/kslog/common/KSLog;)Ldev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor;
public static synthetic fun KtorRequestsExecutor$default (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;Lio/ktor/client/HttpClient;Ljava/util/List;ZLdev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;Lkotlinx/serialization/json/Json;Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ldev/inmo/kslog/common/KSLog;ILjava/lang/Object;)Ldev/inmo/tgbotapi/bot/ktor/base/DefaultKtorRequestsExecutor;
}
public abstract interface class dev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler {
public static final field Companion Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler$Companion;
public abstract fun onAfterCallFactoryMakeCall (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestException (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestResultAbsent (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestResultPresented (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onRequestReturnResult-3t6e044 (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler$Companion : dev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler {
public fun onAfterCallFactoryMakeCall (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestException (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultAbsent (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultPresented (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestReturnResult-3t6e044 (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler$DefaultImpls {
public static fun onAfterCallFactoryMakeCall (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestException (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestResultAbsent (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestResultPresented (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onRequestReturnResult-3t6e044 (Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public abstract class dev/inmo/tgbotapi/bot/ktor/base/AbstractRequestCallFactory : dev/inmo/tgbotapi/bot/ktor/KtorCallFactory {
@ -414,7 +415,7 @@ public final class dev/inmo/tgbotapi/bot/ktor/base/MultipartRequestCallFactory :
}
public final class dev/inmo/tgbotapi/bot/ktor/base/MultipleClientKtorRequestsExecutor : dev/inmo/tgbotapi/bot/BaseRequestsExecutor {
public fun <init> (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;Ljava/util/List;ZLdev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;Lkotlinx/serialization/json/Json;Ldev/inmo/tgbotapi/bot/ktor/KtorPipelineStepsHolder;ILdev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function0;)V
public fun <init> (Ldev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper;Ljava/util/List;ZLdev/inmo/tgbotapi/bot/settings/limiters/RequestLimiter;Lkotlinx/serialization/json/Json;Ldev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler;ILdev/inmo/kslog/common/KSLog;Lkotlin/jvm/functions/Function0;)V
public fun close ()V
public fun execute (Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
@ -425,6 +426,82 @@ public final class dev/inmo/tgbotapi/bot/ktor/base/SimpleRequestCallFactory : de
public synthetic fun <init> (Ldev/inmo/kslog/common/KSLog;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware : dev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler {
public static final field Companion Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware$Companion;
public fun <init> ()V
public fun <init> (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;)V
public synthetic fun <init> (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun onAfterCallFactoryMakeCall (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestException (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultAbsent (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultPresented (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestReturnResult-3t6e044 (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware$Companion {
public final fun build (Lkotlin/jvm/functions/Function1;)Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware;
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware$ResultAbsence : java/lang/Throwable {
public static final field INSTANCE Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware$ResultAbsence;
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewareBuilder {
public static final field Companion Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewareBuilder$Companion;
public fun <init> ()V
public final fun build ()Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware;
public final fun doOnAfterCallFactoryMakeCall (Lkotlin/jvm/functions/Function4;)V
public final fun doOnBeforeCallFactoryMakeCall (Lkotlin/jvm/functions/Function3;)V
public final fun doOnBeforeSearchCallFactory (Lkotlin/jvm/functions/Function3;)V
public final fun doOnRequestException (Lkotlin/jvm/functions/Function3;)V
public final fun doOnRequestResultAbsent (Lkotlin/jvm/functions/Function3;)V
public final fun doOnRequestResultPresented (Lkotlin/jvm/functions/Function5;)V
public final fun doOnRequestReturnResult (Lkotlin/jvm/functions/Function4;)V
public final fun getOnAfterCallFactoryMakeCall ()Lkotlin/jvm/functions/Function4;
public final fun getOnBeforeCallFactoryMakeCall ()Lkotlin/jvm/functions/Function3;
public final fun getOnBeforeSearchCallFactory ()Lkotlin/jvm/functions/Function3;
public final fun getOnRequestException ()Lkotlin/jvm/functions/Function3;
public final fun getOnRequestResultAbsent ()Lkotlin/jvm/functions/Function3;
public final fun getOnRequestResultPresented ()Lkotlin/jvm/functions/Function5;
public final fun getOnRequestReturnResult ()Lkotlin/jvm/functions/Function4;
public final fun setOnAfterCallFactoryMakeCall (Lkotlin/jvm/functions/Function4;)V
public final fun setOnBeforeCallFactoryMakeCall (Lkotlin/jvm/functions/Function3;)V
public final fun setOnBeforeSearchCallFactory (Lkotlin/jvm/functions/Function3;)V
public final fun setOnRequestException (Lkotlin/jvm/functions/Function3;)V
public final fun setOnRequestResultAbsent (Lkotlin/jvm/functions/Function3;)V
public final fun setOnRequestResultPresented (Lkotlin/jvm/functions/Function5;)V
public final fun setOnRequestReturnResult (Lkotlin/jvm/functions/Function4;)V
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewareBuilder$Companion {
public final fun from (Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware;Lkotlin/jvm/functions/Function1;)Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware;
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewaresPipelinesHandler : dev/inmo/tgbotapi/bot/ktor/TelegramBotPipelinesHandler {
public static final field Companion Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewaresPipelinesHandler$Companion;
public fun <init> (Ljava/util/List;)V
public fun onAfterCallFactoryMakeCall (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeCallFactoryMakeCall (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onBeforeSearchCallFactory (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestException (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/lang/Throwable;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultAbsent (Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestResultPresented (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ldev/inmo/tgbotapi/bot/ktor/KtorCallFactory;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onRequestReturnResult-3t6e044 (Ljava/lang/Object;Ldev/inmo/tgbotapi/requests/abstracts/Request;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewaresPipelinesHandler$Builder {
public fun <init> ()V
public final fun addMiddleware (Lkotlin/jvm/functions/Function1;)Z
public final fun build ()Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewaresPipelinesHandler;
public final fun getMiddlewares ()Ljava/util/List;
}
public final class dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewaresPipelinesHandler$Companion {
public final fun build (Lkotlin/jvm/functions/Function1;)Ldev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewaresPipelinesHandler;
}
public final class dev/inmo/tgbotapi/bot/multiserver/SimpleMultiServerRequestsExecutor : dev/inmo/tgbotapi/bot/RequestsExecutor {
public static final field Companion Ldev/inmo/tgbotapi/bot/multiserver/SimpleMultiServerRequestsExecutor$Companion;
public fun <init> (Ljava/util/List;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function0;)V
@ -20010,6 +20087,57 @@ public final class dev/inmo/tgbotapi/types/message/PrivateEventMessage : dev/inm
public fun toString ()Ljava/lang/String;
}
public final class dev/inmo/tgbotapi/types/message/RawMessageEntity {
public static final field Companion Ldev/inmo/tgbotapi/types/message/RawMessageEntity$Companion;
public synthetic fun <init> (Ljava/lang/String;IILjava/lang/String;Ldev/inmo/tgbotapi/types/chat/User;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ljava/lang/String;IILjava/lang/String;Ldev/inmo/tgbotapi/types/chat/User;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()I
public final fun component3 ()I
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ldev/inmo/tgbotapi/types/chat/User;
public final fun component6 ()Ljava/lang/String;
public final fun component7-GbmMWyQ ()Ljava/lang/String;
public final fun copy-SbQeJ6M (Ljava/lang/String;IILjava/lang/String;Ldev/inmo/tgbotapi/types/chat/User;Ljava/lang/String;Ljava/lang/String;)Ldev/inmo/tgbotapi/types/message/RawMessageEntity;
public static synthetic fun copy-SbQeJ6M$default (Ldev/inmo/tgbotapi/types/message/RawMessageEntity;Ljava/lang/String;IILjava/lang/String;Ldev/inmo/tgbotapi/types/chat/User;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/message/RawMessageEntity;
public fun equals (Ljava/lang/Object;)Z
public final fun getCustom_emoji_id-GbmMWyQ ()Ljava/lang/String;
public final fun getLanguage ()Ljava/lang/String;
public final fun getLength ()I
public final fun getOffset ()I
public final fun getPriority ()I
public final fun getType ()Ljava/lang/String;
public final fun getUrl ()Ljava/lang/String;
public final fun getUser ()Ldev/inmo/tgbotapi/types/chat/User;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
public synthetic class dev/inmo/tgbotapi/types/message/RawMessageEntity$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Ldev/inmo/tgbotapi/types/message/RawMessageEntity$$serializer;
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/message/RawMessageEntity;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/message/RawMessageEntity;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}
public final class dev/inmo/tgbotapi/types/message/RawMessageEntity$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}
public final class dev/inmo/tgbotapi/types/message/RawMessageEntityKt {
public static final fun asTextSource (Ldev/inmo/tgbotapi/types/message/RawMessageEntity;Ljava/lang/String;Ljava/util/List;)Ldev/inmo/tgbotapi/types/message/textsources/TextSource;
public static final fun asTextSources (Ljava/util/List;Ljava/lang/String;)Ljava/util/List;
public static final fun toRawMessageEntities (Ldev/inmo/tgbotapi/types/message/textsources/TextSource;I)Ljava/util/List;
public static final fun toRawMessageEntities (Ljava/util/List;)Ljava/util/List;
public static final fun toRawMessageEntities (Ljava/util/List;I)Ljava/util/List;
public static synthetic fun toRawMessageEntities$default (Ldev/inmo/tgbotapi/types/message/textsources/TextSource;IILjava/lang/Object;)Ljava/util/List;
public static synthetic fun toRawMessageEntities$default (Ljava/util/List;IILjava/lang/Object;)Ljava/util/List;
}
public final class dev/inmo/tgbotapi/types/message/UnconnectedFromChannelGroupContentMessageImpl : dev/inmo/tgbotapi/types/message/abstracts/UnconnectedFromChannelGroupContentMessage {
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/chat/PreviewGroupChat;Ldev/inmo/tgbotapi/types/chat/PreviewChannelChat;JDLdev/inmo/tgbotapi/types/message/ForwardInfo;Lkorlibs/time/DateTime;ZLdev/inmo/tgbotapi/types/message/abstracts/AccessibleMessage;Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;Ldev/inmo/tgbotapi/types/message/content/MessageContent;Ldev/inmo/tgbotapi/types/chat/CommonBot;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Ldev/inmo/tgbotapi/types/chat/PreviewGroupChat;Ldev/inmo/tgbotapi/types/chat/PreviewChannelChat;JDLdev/inmo/tgbotapi/types/message/MessageOrigin;Lkorlibs/time/DateTime;ZLdev/inmo/tgbotapi/types/ReplyInfo;Ldev/inmo/tgbotapi/types/buttons/InlineKeyboardMarkup;Ldev/inmo/tgbotapi/types/message/content/MessageContent;Ldev/inmo/tgbotapi/types/chat/CommonBot;Ljava/lang/String;Ljava/lang/String;ZLkotlin/jvm/internal/DefaultConstructorMarker;)V
@ -21771,6 +21899,7 @@ public synthetic class dev/inmo/tgbotapi/types/message/textsources/BotCommandTex
}
public final class dev/inmo/tgbotapi/types/message/textsources/BotCommandTextSource$Companion {
public final fun getCommandRegex ()Lkotlin/text/Regex;
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

View File

@ -24,7 +24,7 @@ expect class KtorRequestsExecutor internal constructor(
excludeDefaultFactories: Boolean,
requestsLimiter: RequestLimiter,
jsonFormatter: Json,
pipelineStepsHolder: KtorPipelineStepsHolder,
pipelineStepsHolder: TelegramBotPipelinesHandler,
logger: KSLog,
diff: Unit // just a diff property to know where constructor and where calling function with defaults
) : BaseRequestsExecutor {
@ -39,7 +39,7 @@ fun KtorRequestsExecutor(
excludeDefaultFactories: Boolean = false,
requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter,
jsonFormatter: Json = nonstrictJsonFormat,
pipelineStepsHolder: KtorPipelineStepsHolder = KtorPipelineStepsHolder,
pipelineStepsHolder: TelegramBotPipelinesHandler = TelegramBotPipelinesHandler,
logger: KSLog = DefaultKTgBotAPIKSLog,
) = KtorRequestsExecutor(
telegramAPIUrlsKeeper = telegramAPIUrlsKeeper,

View File

@ -1,9 +1,9 @@
package dev.inmo.tgbotapi.bot.ktor
import dev.inmo.kslog.common.KSLog
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.ktor.base.*
import dev.inmo.tgbotapi.bot.ktor.middlewares.TelegramBotMiddlewaresPipelinesHandler
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
import dev.inmo.tgbotapi.utils.*
@ -27,7 +27,11 @@ class KtorRequestsExecutorBuilder(
var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter
var jsonFormatter: Json = nonstrictJsonFormat
var logger: KSLog = DefaultKTgBotAPIKSLog
var pipelineStepsHolder: KtorPipelineStepsHolder = KtorPipelineStepsHolder
var pipelineStepsHolder: TelegramBotPipelinesHandler = TelegramBotPipelinesHandler
fun includeMiddlewares(block: TelegramBotMiddlewaresPipelinesHandler.Builder.() -> Unit) {
pipelineStepsHolder = TelegramBotMiddlewaresPipelinesHandler.build(block)
}
fun build() = KtorRequestsExecutor(
telegramAPIUrlsKeeper,

View File

@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.bot.ktor
import dev.inmo.tgbotapi.requests.abstracts.Request
interface KtorPipelineStepsHolder {
interface TelegramBotPipelinesHandler {
/**
* Will be called when any exception will happen due to the [request] handling. If returns value - that value
* will be returned from [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
@ -68,7 +68,10 @@ interface KtorPipelineStepsHolder {
result: Result<T>,
request: Request<T>,
callsFactories: List<KtorCallFactory>
): T = result.getOrThrow()
): Result<T> = result
companion object : KtorPipelineStepsHolder
companion object : TelegramBotPipelinesHandler
}
@Deprecated("Renamed", ReplaceWith("TelegramBotPipelinesHandler", "dev.inmo.tgbotapi.bot.ktor.TelegramBotPipelinesHandler"))
typealias KtorPipelineStepsHolder = TelegramBotPipelinesHandler

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.bot.ktor.base
import dev.inmo.kslog.common.*
import dev.inmo.micro_utils.coroutines.defaultSafelyExceptionHandler
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
import dev.inmo.tgbotapi.bot.exceptions.BotException
@ -9,15 +8,12 @@ import dev.inmo.tgbotapi.bot.exceptions.CommonBotException
import dev.inmo.tgbotapi.bot.exceptions.GetUpdatesConflict
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
import dev.inmo.tgbotapi.bot.ktor.KtorPipelineStepsHolder
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutor
import dev.inmo.tgbotapi.bot.ktor.TelegramBotPipelinesHandler
import dev.inmo.tgbotapi.bot.ktor.createTelegramBotDefaultKtorCallRequestsFactories
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.Response
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.statement.*
@ -30,7 +26,7 @@ class DefaultKtorRequestsExecutor internal constructor(
excludeDefaultFactories: Boolean,
private val requestsLimiter: RequestLimiter,
private val jsonFormatter: Json,
private val pipelineStepsHolder: KtorPipelineStepsHolder,
private val pipelineStepsHolder: TelegramBotPipelinesHandler,
private val logger: KSLog,
diff: Unit
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
@ -110,7 +106,7 @@ class DefaultKtorRequestsExecutor internal constructor(
}
}
} ?.let { Result.failure(it) } ?: it
pipelineStepsHolder.onRequestReturnResult(result, request, callsFactories).also {
pipelineStepsHolder.onRequestReturnResult(result, request, callsFactories).getOrThrow().also {
logger.v { "Result of handling $request: $it" }
}
}

View File

@ -4,13 +4,10 @@ import dev.inmo.kslog.common.KSLog
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
import dev.inmo.tgbotapi.bot.ktor.KtorPipelineStepsHolder
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutor
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
import dev.inmo.tgbotapi.bot.ktor.TelegramBotPipelinesHandler
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import io.ktor.client.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
@ -47,7 +44,7 @@ class MultipleClientKtorRequestsExecutor (
excludeDefaultFactories: Boolean,
requestsLimiter: RequestLimiter,
jsonFormatter: Json,
pipelineStepsHolder: KtorPipelineStepsHolder,
pipelineStepsHolder: TelegramBotPipelinesHandler,
requestExecutorsCount: Int,
logger: KSLog,
clientFactory: () -> HttpClient
@ -82,7 +79,7 @@ class MultipleClientKtorRequestsExecutor (
excludeDefaultFactories: Boolean,
requestsLimiter: RequestLimiter,
jsonFormatter: Json,
pipelineStepsHolder: KtorPipelineStepsHolder,
pipelineStepsHolder: TelegramBotPipelinesHandler,
logger: KSLog,
diff: Unit
) : this(

View File

@ -0,0 +1,83 @@
package dev.inmo.tgbotapi.bot.ktor.middlewares
import dev.inmo.micro_utils.common.Warning
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
import dev.inmo.tgbotapi.bot.ktor.TelegramBotPipelinesHandler
import dev.inmo.tgbotapi.requests.abstracts.Request
/**
* @param onRequestException Will be called when some exception happen during [Request] handling. Non-null result of
* lambda will be used as the result of request handling
* @param onBeforeSearchCallFactory Will be called when telegram bot starts to choose which [KtorCallFactory] will handle
* [Request]
* @param onBeforeCallFactoryMakeCall Will be called when telegram bot trying to use [KtorCallFactory] as potential
* handler for [Request]
* @param onAfterCallFactoryMakeCall Will be called when [KtorCallFactory] made call. Non-null result of
* lambda will be used as the result of request handling
* @param onRequestResultPresented Will be called when [KtorCallFactory] **or** [TelegramBotPipelinesHandler]/[TelegramBotMiddleware]
* returned non-null result. Non-null result of lambda will be used as the result of request handling
* @param onRequestResultAbsent Will be called when some there is no any result of [Request] handling. Non-null result of
* lambda will be used as the result of request handling
* @param onRequestReturnResult Latest lambda before result returning. Will be called after all previous stages.
* Non-null result of lambda will be used as the result of request handling
*/
@Warning("This API is experimental and subject of changes")
class TelegramBotMiddleware(
internal val onRequestException: (suspend (request: Request<*>, t: Throwable?) -> Any?)? = null,
internal val onBeforeSearchCallFactory: (suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Unit)? = null,
internal val onBeforeCallFactoryMakeCall: (suspend (request: Request<*>, potentialFactory: KtorCallFactory) -> Unit)? = null,
internal val onAfterCallFactoryMakeCall: (suspend (result: Any?, request: Request<*>, potentialFactory: KtorCallFactory) -> Any?)? = null,
internal val onRequestResultPresented: (suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List<KtorCallFactory>) -> Any?)? = null,
internal val onRequestResultAbsent: (suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Any?)? = null,
internal val onRequestReturnResult: (suspend (result: Result<*>, request: Request<*>, callsFactories: List<KtorCallFactory>) -> Result<Any?>?)? = null,
) : TelegramBotPipelinesHandler {
object ResultAbsence : Throwable()
override suspend fun <T : Any> onRequestException(request: Request<T>, t: Throwable): T? {
return onRequestException ?.invoke(request, t) as? T
}
override suspend fun onBeforeSearchCallFactory(request: Request<*>, callsFactories: List<KtorCallFactory>) {
onBeforeSearchCallFactory ?.invoke(request, callsFactories)
}
override suspend fun onBeforeCallFactoryMakeCall(request: Request<*>, potentialFactory: KtorCallFactory) {
onBeforeCallFactoryMakeCall ?.invoke(request, potentialFactory)
}
override suspend fun <T : Any> onAfterCallFactoryMakeCall(
result: T?,
request: Request<T>,
potentialFactory: KtorCallFactory
): T? {
return onAfterCallFactoryMakeCall ?.invoke(result, request, potentialFactory) as? T
}
override suspend fun <T : Any> onRequestResultPresented(
result: T,
request: Request<T>,
resultCallFactory: KtorCallFactory,
callsFactories: List<KtorCallFactory>
): T? {
return onRequestResultPresented ?.invoke(result, request, resultCallFactory, callsFactories) as? T
}
override suspend fun <T : Any> onRequestResultAbsent(
request: Request<T>,
callsFactories: List<KtorCallFactory>
): T? {
return onRequestResultAbsent ?.invoke(request, callsFactories) as? T
}
override suspend fun <T : Any> onRequestReturnResult(
result: Result<T>,
request: Request<T>,
callsFactories: List<KtorCallFactory>
): Result<T> {
return onRequestReturnResult ?.invoke(result, request, callsFactories) as? Result<T> ?: Result.failure(ResultAbsence)
}
companion object {
@Warning("This API is experimental and subject of changes")
fun build(block: TelegramBotMiddlewareBuilder.() -> Unit): TelegramBotMiddleware = TelegramBotMiddlewareBuilder().apply(block).build()
}
}

View File

@ -0,0 +1,89 @@
package dev.inmo.tgbotapi.bot.ktor.middlewares
import dev.inmo.micro_utils.common.Warning
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
import dev.inmo.tgbotapi.bot.ktor.TelegramBotPipelinesHandler
import dev.inmo.tgbotapi.requests.abstracts.Request
@Warning("This API is experimental and subject of changes")
class TelegramBotMiddlewareBuilder {
var onRequestException: (suspend (request: Request<*>, t: Throwable?) -> Any?)? = null
var onBeforeSearchCallFactory: (suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Unit)? = null
var onBeforeCallFactoryMakeCall: (suspend (request: Request<*>, potentialFactory: KtorCallFactory) -> Unit)? = null
var onAfterCallFactoryMakeCall: (suspend (result: Any?, request: Request<*>, potentialFactory: KtorCallFactory) -> Any?)? = null
var onRequestResultPresented: (suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List<KtorCallFactory>) -> Any?)? = null
var onRequestResultAbsent: (suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Any?)? = null
var onRequestReturnResult: (suspend (result: Result<*>, request: Request<*>, callsFactories: List<KtorCallFactory>) -> Result<Any?>?)? = null
/**
* Useful way to set [onRequestException]
*/
fun doOnRequestException(block: suspend (request: Request<*>, t: Throwable?) -> Any?) {
onRequestException = block
}
/**
* Useful way to set [onBeforeSearchCallFactory]
*/
fun doOnBeforeSearchCallFactory(block: suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Unit) {
onBeforeSearchCallFactory = block
}
/**
* Useful way to set [onBeforeCallFactoryMakeCall]
*/
fun doOnBeforeCallFactoryMakeCall(block: suspend (request: Request<*>, potentialFactory: KtorCallFactory) -> Unit) {
onBeforeCallFactoryMakeCall = block
}
/**
* Useful way to set [onAfterCallFactoryMakeCall]
*/
fun doOnAfterCallFactoryMakeCall(block: suspend (result: Any?, request: Request<*>, potentialFactory: KtorCallFactory) -> Any?) {
onAfterCallFactoryMakeCall = block
}
/**
* Useful way to set [onRequestResultPresented]
*/
fun doOnRequestResultPresented(block: suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List<KtorCallFactory>) -> Any?) {
onRequestResultPresented = block
}
/**
* Useful way to set [onRequestResultAbsent]
*/
fun doOnRequestResultAbsent(block: suspend (request: Request<*>, callsFactories: List<KtorCallFactory>) -> Any?) {
onRequestResultAbsent = block
}
/**
* Useful way to set [onRequestReturnResult]
*/
fun doOnRequestReturnResult(block: suspend (result: Result<*>, request: Request<*>, callsFactories: List<KtorCallFactory>) -> Result<Any?>?) {
onRequestReturnResult = block
}
@Warning("This API is experimental and subject of changes")
fun build(): TelegramBotMiddleware {
return TelegramBotMiddleware(
onRequestException = onRequestException,
onBeforeSearchCallFactory = onBeforeSearchCallFactory,
onBeforeCallFactoryMakeCall = onBeforeCallFactoryMakeCall,
onAfterCallFactoryMakeCall = onAfterCallFactoryMakeCall,
onRequestResultPresented = onRequestResultPresented,
onRequestResultAbsent = onRequestResultAbsent,
onRequestReturnResult = onRequestReturnResult
)
}
companion object {
@Warning("This API is experimental and subject of changes")
fun from(middleware: TelegramBotMiddleware, additionalSetup: TelegramBotMiddlewareBuilder.() -> Unit): TelegramBotMiddleware {
return TelegramBotMiddlewareBuilder().apply {
onRequestException = middleware.onRequestException
onBeforeSearchCallFactory = middleware.onBeforeSearchCallFactory
onBeforeCallFactoryMakeCall = middleware.onBeforeCallFactoryMakeCall
onAfterCallFactoryMakeCall = middleware.onAfterCallFactoryMakeCall
onRequestResultPresented = middleware.onRequestResultPresented
onRequestResultAbsent = middleware.onRequestResultAbsent
onRequestReturnResult = middleware.onRequestReturnResult
additionalSetup()
}.build()
}
}
}

View File

@ -0,0 +1,92 @@
package dev.inmo.tgbotapi.bot.ktor.middlewares
import dev.inmo.micro_utils.common.Warning
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory
import dev.inmo.tgbotapi.bot.ktor.TelegramBotPipelinesHandler
import dev.inmo.tgbotapi.requests.abstracts.Request
@Warning("This API is experimental and subject of changes")
class TelegramBotMiddlewaresPipelinesHandler(
private val middlewares: List<TelegramBotMiddleware>
) : TelegramBotPipelinesHandler {
override suspend fun <T : Any> onRequestException(request: Request<T>, t: Throwable): T? {
return middlewares.firstNotNullOfOrNull {
it.onRequestException(request, t)
} ?: super.onRequestException(request, t)
}
override suspend fun onBeforeSearchCallFactory(request: Request<*>, callsFactories: List<KtorCallFactory>) {
middlewares.forEach {
it.onBeforeSearchCallFactory(request, callsFactories)
}
}
override suspend fun onBeforeCallFactoryMakeCall(request: Request<*>, potentialFactory: KtorCallFactory) {
middlewares.forEach {
it.onBeforeCallFactoryMakeCall(request, potentialFactory)
}
}
override suspend fun <T : Any> onAfterCallFactoryMakeCall(
result: T?,
request: Request<T>,
potentialFactory: KtorCallFactory
): T? {
return middlewares.firstNotNullOfOrNull {
it.onAfterCallFactoryMakeCall(result, request, potentialFactory)
} ?: super.onAfterCallFactoryMakeCall(result, request, potentialFactory)
}
override suspend fun <T : Any> onRequestResultPresented(
result: T,
request: Request<T>,
resultCallFactory: KtorCallFactory,
callsFactories: List<KtorCallFactory>
): T? {
return middlewares.firstNotNullOfOrNull {
it.onRequestResultPresented(result, request, resultCallFactory, callsFactories)
} ?: super.onRequestResultPresented(result, request, resultCallFactory, callsFactories)
}
override suspend fun <T : Any> onRequestResultAbsent(
request: Request<T>,
callsFactories: List<KtorCallFactory>
): T? {
return middlewares.firstNotNullOfOrNull {
it.onRequestResultAbsent(request, callsFactories)
} ?: super.onRequestResultAbsent(request, callsFactories)
}
override suspend fun <T : Any> onRequestReturnResult(
result: Result<T>,
request: Request<T>,
callsFactories: List<KtorCallFactory>
): Result<T> {
return middlewares.firstNotNullOfOrNull {
it.onRequestReturnResult(result, request, callsFactories).takeIf {
it.onFailure { return@takeIf it !is TelegramBotMiddleware.ResultAbsence }
true
}
} ?: super.onRequestReturnResult(result, request, callsFactories)
}
@Warning("This API is experimental and subject of changes")
class Builder {
val middlewares = mutableListOf<TelegramBotMiddleware>()
@Warning("This API is experimental and subject of changes")
fun addMiddleware(block: TelegramBotMiddlewareBuilder.() -> Unit) = middlewares.add(
TelegramBotMiddleware.build(block)
)
@Warning("This API is experimental and subject of changes")
fun build(): TelegramBotMiddlewaresPipelinesHandler = TelegramBotMiddlewaresPipelinesHandler(
middlewares.toList()
)
}
companion object {
@Warning("This API is experimental and subject of changes")
fun build(block: Builder.() -> Unit) = Builder().apply(block).build()
}
}

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types.message
import dev.inmo.micro_utils.common.Warning
import dev.inmo.micro_utils.serialization.mapper.MapperSerializer
import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.chat.User
@ -9,7 +10,8 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
@Serializable
internal data class RawMessageEntity(
@Warning("This thing is subject of changes. Library do not guarantee stability of this class")
data class RawMessageEntity(
val type: String,
val offset: Int,
val length: Int,
@ -49,7 +51,8 @@ internal data class RawMessageEntity(
}
}
internal fun RawMessageEntity.asTextSource(
@Warning("This thing is subject of changes. Library do not guarantee stability of this extension")
fun RawMessageEntity.asTextSource(
source: String,
subParts: List<Pair<Int, TextSource>>
): TextSource {
@ -92,6 +95,7 @@ private inline operator fun <T : Comparable<T>> ClosedRange<T>.contains(other: C
return start <= other.start && endInclusive >= other.endInclusive
}
@Warning("This thing is subject of changes. Library do not guarantee stability of this extension")
internal fun List<Pair<Int, TextSource>>.fillWithRegulars(source: String): TextSourcesList {
var index = 0
val result = mutableListOf<TextSource>()
@ -174,7 +178,8 @@ private fun createTextSources(
return resultList
}
internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEntity> {
@Warning("This thing is subject of changes. Library do not guarantee stability of this extension")
fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEntity> {
val source = source
val length = source.length
return listOfNotNull(
@ -208,7 +213,8 @@ internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEn
}
internal fun TextSourcesList.toRawMessageEntities(preOffset: Int = 0): List<RawMessageEntity> {
@Warning("This thing is subject of changes. Library do not guarantee stability of this extension")
fun TextSourcesList.toRawMessageEntities(preOffset: Int = 0): List<RawMessageEntity> {
var i = preOffset
return flatMap { textSource ->
textSource.toRawMessageEntities(i).also {
@ -217,9 +223,12 @@ internal fun TextSourcesList.toRawMessageEntities(preOffset: Int = 0): List<RawM
}
}
internal fun TextSourcesList.toRawMessageEntities(): List<RawMessageEntity> = toRawMessageEntities(0)
@Warning("This thing is subject of changes. Library do not guarantee stability of this extension")
fun TextSourcesList.toRawMessageEntities(): List<RawMessageEntity> = toRawMessageEntities(0)
internal fun RawMessageEntities.asTextSources(sourceString: String): TextSourcesList =
@Warning("This thing is subject of changes. Library do not guarantee stability of this extension")
fun RawMessageEntities.asTextSources(sourceString: String): TextSourcesList =
createTextSources(sourceString, this).fillWithRegulars(sourceString)
internal typealias RawMessageEntities = List<RawMessageEntity>
@Warning("This thing is subject of changes. Library do not guarantee stability of this typealias")
typealias RawMessageEntities = List<RawMessageEntity>

View File

@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable
private val commandRegex = Regex("[/!][^@\\s]*")
/**
* @see botCommand
*/
@ -17,7 +15,7 @@ data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstru
override val source: String
) : TextSource {
val command: String by lazy {
commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!"
CommandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!"
}
val username: Username? by lazy {
Username(usernameRegex.find(source) ?.value ?: return@lazy null)
@ -26,6 +24,10 @@ data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstru
override val markdown: String by lazy { source.commandMarkdown() }
override val markdownV2: String by lazy { source.commandMarkdownV2() }
override val html: String by lazy { source.commandHTML() }
companion object {
val CommandRegex = Regex("[/!][^@\\s]*")
}
}
/**

View File

@ -7,27 +7,6 @@ import kotlinx.serialization.encoding.CompositeEncoder
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
//private val baseSerializers: Map<String, KSerializer<out TextSource>> = mapOf(
// "regular" to RegularTextSource.serializer(),
// "text_link" to TextLinkTextSource.serializer(),
// "code" to CodeTextSource.serializer(),
// "url" to URLTextSource.serializer(),
// "pre" to PreTextSource.serializer(),
// "bot_command" to BotCommandTextSource.serializer(),
// "strikethrough" to StrikethroughTextSource.serializer(),
// "italic" to ItalicTextSource.serializer(),
// "bold" to BoldTextSource.serializer(),
// "email" to EMailTextSource.serializer(),
// "underline" to UnderlineTextSource.serializer(),
// "mention" to MentionTextSource.serializer(),
// "phone_number" to PhoneNumberTextSource.serializer(),
// "text_mention" to TextMentionTextSource.serializer(),
// "hashtag" to HashTagTextSource.serializer(),
// "cashtag" to CashTagTextSource.serializer(),
// "spoiler" to SpoilerTextSource.serializer(),
// "custom_emoji" to CustomEmojiTextSource.serializer(),
//)
object TextSourceSerializer : TypedSerializer<TextSource>(TextSource::class, emptyMap()) {
private val baseSerializers: Map<String, KSerializer<out TextSource>> by lazy {
mapOf(
@ -49,6 +28,8 @@ object TextSourceSerializer : TypedSerializer<TextSource>(TextSource::class, emp
"cashtag" to CashTagTextSource.serializer(),
"spoiler" to SpoilerTextSource.serializer(),
"custom_emoji" to CustomEmojiTextSource.serializer(),
"blockquote" to BlockquoteTextSource.serializer(),
"expandable_blockquote" to ExpandableBlockquoteTextSource.serializer(),
).also {
it.forEach { (k, s) ->
include(k, s)