1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-16 13:49:26 +00:00

jvmApiDump

This commit is contained in:
2024-10-21 18:07:09 +06:00
parent 1f6ddd97e3
commit 2953005e6d
4 changed files with 64 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
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
@@ -20,6 +21,7 @@ import dev.inmo.tgbotapi.requests.abstracts.Request
* @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,
@@ -75,6 +77,7 @@ class TelegramBotMiddleware(
}
companion object {
@Warning("This API is experimental and subject of changes")
fun build(block: TelegramBotMiddlewareBuilder.() -> Unit): TelegramBotMiddleware = TelegramBotMiddlewareBuilder().apply(block).build()
}
}

View File

@@ -1,9 +1,11 @@
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
@@ -56,6 +58,7 @@ class TelegramBotMiddlewareBuilder {
onRequestReturnResult = block
}
@Warning("This API is experimental and subject of changes")
fun build(): TelegramBotMiddleware {
return TelegramBotMiddleware(
onRequestException = onRequestException,
@@ -69,6 +72,7 @@ class TelegramBotMiddlewareBuilder {
}
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

View File

@@ -1,9 +1,11 @@
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 {
@@ -68,19 +70,23 @@ class TelegramBotMiddlewaresPipelinesHandler(
} ?: 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()
}
}