1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 00:03:48 +00:00

add additional functions in TelegramBotMiddlewareBuilder

This commit is contained in:
InsanusMokrassar 2024-10-15 13:46:25 +06:00
parent b5b7482c2f
commit 27416daeb8
2 changed files with 43 additions and 1 deletions

View File

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

View File

@ -13,6 +13,48 @@ class TelegramBotMiddlewareBuilder {
var onRequestResultAbsent: (suspend (request: Request<*>, 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 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
}
fun build(): TelegramBotMiddleware { fun build(): TelegramBotMiddleware {
return TelegramBotMiddleware( return TelegramBotMiddleware(