mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
add generation of class casts
This commit is contained in:
parent
d8f6429385
commit
a18eda3db6
@ -7,6 +7,7 @@ buildscript {
|
||||
|
||||
dependencies {
|
||||
classpath libs.kotlin.gradle.plugin
|
||||
classpath libs.kotlin.ksp.plugin
|
||||
classpath libs.kotlin.serialization.plugin
|
||||
classpath libs.kotlin.dokka.plugin
|
||||
classpath libs.github.release.plugin
|
||||
|
@ -10,6 +10,9 @@ korlibs = "3.0.0"
|
||||
uuid = "0.5.0"
|
||||
ktor = "2.0.3"
|
||||
|
||||
ksp = "1.7.10-1.0.6"
|
||||
kotlin-poet = "1.12.0"
|
||||
|
||||
microutils = "0.12.0"
|
||||
|
||||
github-release-plugin = "2.4.1"
|
||||
@ -45,14 +48,21 @@ microutils-languageCodes = { module = "dev.inmo:micro_utils.language_codes", ver
|
||||
microutils-ktor-common = { module = "dev.inmo:micro_utils.ktor.common", version.ref = "microutils" }
|
||||
microutils-fsm-common = { module = "dev.inmo:micro_utils.fsm.common", version.ref = "microutils" }
|
||||
|
||||
# ksp dependencies
|
||||
|
||||
kotlin-poet = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlin-poet" }
|
||||
ksp = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
|
||||
|
||||
# buildscript classpaths
|
||||
|
||||
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||
kotlin-ksp-plugin = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" }
|
||||
kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
|
||||
kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "kotlin" }
|
||||
github-release-plugin = { module = "com.github.breadmoirai:github-release", version.ref = "github-release-plugin" }
|
||||
|
||||
[plugins]
|
||||
|
||||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
||||
|
@ -12,6 +12,8 @@ pluginManagement {
|
||||
}
|
||||
|
||||
include ":tgbotapi.core"
|
||||
include ":tgbotapi.ksp:processor"
|
||||
include ":tgbotapi.ksp:lib"
|
||||
include ":tgbotapi.api"
|
||||
include ":tgbotapi.utils"
|
||||
include ":tgbotapi.behaviour_builder"
|
||||
|
@ -4,7 +4,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.callbackQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@ -22,7 +22,7 @@ suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.asCallbackQueryUpdate() ?.data as O).let(::listOfNotNull)
|
||||
(it.callbackQueryUpdateOrNull() ?.data as O).let(::listOfNotNull)
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChatJoinRequestUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.chatJoinRequestUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@ -20,7 +20,7 @@ suspend inline fun <reified O> BehaviourContext.internalWaitChatJoinRequests(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.asChatJoinRequestUpdate() ?.data as? O).let(::listOfNotNull)
|
||||
(it.chatJoinRequestUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,14 +1,12 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChosenInlineResultUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.chosenInlineResultUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias ChosenInlineResultMapper<T> = suspend T.() -> T?
|
||||
|
||||
@ -20,7 +18,7 @@ suspend inline fun <reified O> BehaviourContext.waitChosenInlineResults(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.asChosenInlineResultUpdate() ?.data as? O).let(::listOfNotNull)
|
||||
(it.chosenInlineResultUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitChosenInlineResult(
|
||||
|
@ -4,7 +4,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asCommonMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
|
@ -4,7 +4,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asCommonMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
@ -32,7 +32,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
|
||||
) {
|
||||
val messages = when (it) {
|
||||
is BaseEditMessageUpdate -> {
|
||||
val commonMessage = it.data.asCommonMessage() ?: return@expectFlow emptyList()
|
||||
val commonMessage = it.data.commonMessageOrNull() ?: return@expectFlow emptyList()
|
||||
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
||||
listOf(commonMessage)
|
||||
} else {
|
||||
|
@ -27,7 +27,7 @@ suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEvents(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>() ?.chatEvent.let(::listOfNotNull)
|
||||
it.baseSentMessageUpdateOrNull() ?.data ?.chatEventMessageOrNull() ?.withEvent<O>() ?.chatEvent.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitChannelEvents(
|
||||
|
@ -25,7 +25,7 @@ suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEventsMessages(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>().let(::listOfNotNull)
|
||||
it.baseSentMessageUpdateOrNull() ?.data ?.chatEventMessageOrNull() ?.withEvent<O>().let(::listOfNotNull)
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitChannelEventsMessages(
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.inlineQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@ -20,7 +20,7 @@ suspend inline fun <reified O : InlineQuery> BehaviourContext.waitInlineQueries(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.asInlineQueryUpdate() ?.data as? O).let(::listOfNotNull)
|
||||
(it.inlineQueryUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitAnyInlineQuery(
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
@ -20,7 +20,7 @@ suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGr
|
||||
initRequest: Request<*>? = null,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||
): Flow<List<MediaGroupMessage<T>>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update ->
|
||||
update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup ->
|
||||
update.sentMediaGroupUpdateOrNull() ?.data ?.let { mediaGroup ->
|
||||
val mapped = mediaGroup.mapNotNull { it.withContent<T>() }
|
||||
listOf(
|
||||
mapped
|
||||
|
@ -2,8 +2,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPassportMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.messageUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.passportMessageOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.PassportMessage
|
||||
import dev.inmo.tgbotapi.types.passport.PassportData
|
||||
@ -23,7 +23,7 @@ suspend inline fun <reified O : EncryptedPassportElement> BehaviourContext.waitP
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
it.asMessageUpdate() ?.data ?.asPassportMessage() ?.passportData ?.data ?.filterIsInstance<O>() ?: emptyList()
|
||||
it.messageUpdateOrNull() ?.data ?.passportMessageOrNull() ?.passportData ?.data ?.filterIsInstance<O>() ?: emptyList()
|
||||
}
|
||||
|
||||
suspend fun BehaviourContext.waitAnyPassportMessages(
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollAnswerUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.pollAnswerUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@ -19,5 +19,5 @@ suspend fun BehaviourContext.waitPollAnswers(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
it.asPollAnswerUpdate() ?.data.let(::listOfNotNull)
|
||||
it.pollAnswerUpdateOrNull() ?.data.let(::listOfNotNull)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.pollUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@ -20,7 +20,7 @@ suspend inline fun <reified O : Poll> BehaviourContext.waitPolls(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.asPollUpdate() ?.data as? O).let(::listOfNotNull)
|
||||
(it.pollUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.preCheckoutQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@ -19,5 +19,5 @@ suspend fun BehaviourContext.waitPreCheckoutQueries(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
it.asPreCheckoutQueryUpdate() ?.data.let(::listOfNotNull)
|
||||
it.preCheckoutQueryUpdateOrNull() ?.data.let(::listOfNotNull)
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.shippingQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias ShippingQueryMapper = suspend ShippingQuery.() -> ShippingQuery?
|
||||
|
||||
@ -17,5 +15,5 @@ suspend fun BehaviourContext.waitShippingQueries(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.asShippingQueryUpdate() ?.data).let(::listOfNotNull)
|
||||
(it.shippingQueryUpdateOrNull() ?.data).let(::listOfNotNull)
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilte
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.callbackQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import kotlinx.coroutines.Job
|
||||
@ -20,7 +20,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : CallbackQuery> B
|
||||
markerFactory: MarkerFactory<in T, Any> = ByUserCallbackQueryMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asCallbackQueryUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
(it.callbackQueryUpdateOrNull() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ChatJoinRequestFil
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatJoinRequestMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChatJoinRequestUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.chatJoinRequestUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -29,5 +29,5 @@ suspend fun <BC : BehaviourContext> BC.onChatJoinRequest(
|
||||
markerFactory: MarkerFactory<in ChatJoinRequest, Any> = ByChatChatJoinRequestMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatJoinRequest>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asChatJoinRequestUpdate() ?.data) ?.let(::listOfNotNull)
|
||||
(it.chatJoinRequestUpdateOrNull() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserIdChosenInlineResultMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChosenInlineResultUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.chosenInlineResultUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -16,7 +16,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : ChosenInlineResu
|
||||
markerFactory: MarkerFactory<in T, Any> = ByUserIdChosenInlineResultMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asChosenInlineResultUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
(it.chosenInlineResultUpdateOrNull() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByCha
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
|
||||
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
@ -35,7 +35,7 @@ internal suspend fun <BC : BehaviourContext> BC.commandUncounted(
|
||||
true
|
||||
}
|
||||
sizeRequirement && textSources.any {
|
||||
commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false)
|
||||
commandRegex.matches(it.botCommandTextSourceOrNull() ?.command ?: return@any false)
|
||||
}
|
||||
}.let {
|
||||
initialFilter ?.times(it) ?: it
|
||||
|
@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByCha
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
|
||||
import dev.inmo.tgbotapi.extensions.utils.botCommandTextSourceOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||
@ -33,7 +33,7 @@ suspend fun <BC : BehaviourContext> BC.unhandledCommand(
|
||||
true
|
||||
}
|
||||
sizeRequirement && textSources.any {
|
||||
val command = it.asBotCommandTextSource() ?.command ?: return@any false
|
||||
val command = it.botCommandTextSourceOrNull() ?.command ?: return@any false
|
||||
!triggersHolder.handleableCommandsHolder.isHandled(command)
|
||||
}
|
||||
}.let {
|
||||
|
@ -20,7 +20,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilte
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asEditMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.editMessageUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
@ -41,7 +41,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent>
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
when (it) {
|
||||
is BaseEditMessageUpdate -> (it.asEditMessageUpdate() ?.data ?.withContent<T>())
|
||||
is BaseEditMessageUpdate -> (it.editMessageUpdateOrNull() ?.data ?.withContent<T>())
|
||||
else -> null
|
||||
} ?.let(::listOfNotNull)
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByCha
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.chatEventMessageOrNull
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
@ -24,7 +24,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : ChatEvent> BC.on
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<T>>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.takeIf { it.chatEvent is T } as? ChatEventMessage<T>) ?.let(::listOfNotNull)
|
||||
(it.baseSentMessageUpdateOrNull() ?.data ?.chatEventMessageOrNull() ?.takeIf { it.chatEvent is T } as? ChatEventMessage<T>) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.InlineQueryFilterB
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserInlineQueryMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.inlineQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -15,7 +15,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : InlineQuery> BC.
|
||||
markerFactory: MarkerFactory<in T, Any> = ByUserInlineQueryMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asInlineQueryUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
(it.inlineQueryUpdateOrNull() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessagesFilterByCh
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
@ -20,7 +20,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MediaGroupConten
|
||||
markerFactory: MarkerFactory<in List<MediaGroupMessage<T>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<T>>>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asSentMediaGroupUpdate() ?.data ?.takeIf { messages ->
|
||||
(it.sentMediaGroupUpdateOrNull() ?.data ?.takeIf { messages ->
|
||||
messages.all { message ->
|
||||
message.content is T
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByCha
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPassportMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.messageUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.passportMessageOrNull
|
||||
import dev.inmo.tgbotapi.types.message.PassportMessage
|
||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
@ -17,7 +17,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : EncryptedPasspor
|
||||
markerFactory: MarkerFactory<in PassportMessage, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PassportMessage>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asMessageUpdate() ?.data ?.asPassportMessage() ?.takeIf { it.passportData.data.any { it is T } }) ?.let(::listOfNotNull)
|
||||
(it.messageUpdateOrNull() ?.data ?.passportMessageOrNull() ?.takeIf { it.passportData.data.any { it is T } }) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByIdPollAnswerMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollAnswerUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.pollAnswerUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -16,7 +16,7 @@ internal suspend inline fun <BC : BehaviourContext> BC.onPollAnswered(
|
||||
markerFactory: MarkerFactory<in PollAnswer, Any> = ByIdPollAnswerMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PollAnswer>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asPollAnswerUpdate() ?.data) ?.let(::listOfNotNull)
|
||||
(it.pollAnswerUpdateOrNull() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByIdPollMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.pollUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -16,7 +16,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : Poll> BC.onPollU
|
||||
markerFactory: MarkerFactory<in T, Any> = ByIdPollMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asPollUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
||||
(it.pollUpdateOrNull() ?.data as? T) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.PreCheckoutQueryFi
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserPreCheckoutQueryMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.preCheckoutQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -31,5 +31,5 @@ suspend fun <BC : BehaviourContext> BC.onPreCheckoutQuery(
|
||||
markerFactory: MarkerFactory<in PreCheckoutQuery, Any> = ByUserPreCheckoutQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PreCheckoutQuery>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asPreCheckoutQueryUpdate() ?.data) ?.let(::listOfNotNull)
|
||||
(it.preCheckoutQueryUpdateOrNull() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.ShippingQueryFilte
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserShippingQueryMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.shippingQueryUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -31,5 +31,5 @@ suspend fun <BC : BehaviourContext> BC.onShippingQuery(
|
||||
markerFactory: MarkerFactory<in ShippingQuery, Any> = ByUserShippingQueryMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ShippingQuery>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
(it.asShippingQueryUpdate() ?.data) ?.let(::listOfNotNull)
|
||||
(it.shippingQueryUpdateOrNull() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.google.devtools.ksp"
|
||||
}
|
||||
|
||||
project.description = "Core part of tgbotapi with all (and only) required functionality for working with Telegram Bot API"
|
||||
@ -28,6 +29,8 @@ kotlin {
|
||||
api libs.microutils.languageCodes
|
||||
|
||||
api libs.ktor.client.core
|
||||
|
||||
api project(":tgbotapi.ksp:lib")
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
@ -46,12 +49,15 @@ kotlin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// targets.all {
|
||||
// compilations.all {
|
||||
// kotlinOptions {
|
||||
// freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", "-Xopt-in=kotlin.RequiresOptIn"]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("kspCommonMainMetadata", project(":tgbotapi.ksp:processor"))
|
||||
add("kspJvm", project(":tgbotapi.ksp:processor"))
|
||||
}
|
||||
|
||||
ksp {
|
||||
arg("cctargetPackage", "dev.inmo.tgbotapi.extensions.utils")
|
||||
arg("ccoutputFileName", "NewClassCasts")
|
||||
arg("ccoutputFolder", project(":tgbotapi.utils").file("src/commonMain/kotlin").absolutePath)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currencied
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Priced
|
||||
|
||||
@ClassCastsIncluded
|
||||
interface CommonSendInvoiceData : Titled, Currencied, Priced {
|
||||
val description: String
|
||||
val payload: String
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
|
||||
/**
|
||||
@ -7,6 +8,7 @@ import dev.inmo.tgbotapi.types.chat.User
|
||||
*
|
||||
* @see FromUser
|
||||
*/
|
||||
@ClassCastsIncluded
|
||||
interface WithUser {
|
||||
val user: User
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.serializers.InlineQueryResultSerializer
|
||||
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(InlineQueryResultSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
interface InlineQueryResult {
|
||||
val type: String
|
||||
val id: InlineQueryIdentifier
|
||||
|
@ -1,7 +1,9 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContentSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(InputMessageContentSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface InputMessageContent
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.actions
|
||||
|
||||
import dev.inmo.micro_utils.common.Warning
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
@ -13,6 +14,7 @@ import kotlinx.serialization.encoding.Encoder
|
||||
* Use BotAction objects realisations to notify user about bot actions
|
||||
*/
|
||||
@Serializable(BotActionSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface BotAction {
|
||||
val actionName: String
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.games.CallbackGame
|
||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||
@ -11,6 +12,7 @@ import kotlinx.serialization.json.*
|
||||
* https://core.telegram.org/bots/api#inlinekeyboardbutton for more info
|
||||
*/
|
||||
@Serializable(InlineKeyboardButtonSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface InlineKeyboardButton {
|
||||
val text: String
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.buttons
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(KeyboardMarkupSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface KeyboardMarkup
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.chat
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -43,6 +44,7 @@ sealed interface AbleToAddInAttachmentMenuChat : Chat {
|
||||
}
|
||||
|
||||
@Serializable(PreviewChatSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface Chat {
|
||||
val id: ChatId
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.dice
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.serialization.KSerializer
|
||||
@ -9,6 +10,7 @@ import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(DiceAnimationTypeSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface DiceAnimationType {
|
||||
val emoji: String
|
||||
val valueLimits: IntRange
|
||||
|
@ -1,11 +1,13 @@
|
||||
package dev.inmo.tgbotapi.types.files
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.FileUniqueId
|
||||
|
||||
/**
|
||||
* Declare common part of media files in Telegram. Note: it is not representation of JVM `File` type
|
||||
*/
|
||||
@ClassCastsIncluded
|
||||
sealed interface TelegramMediaFile {
|
||||
val fileId: FileId
|
||||
val fileUniqueId: FileUniqueId
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.location
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.*
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||
import kotlinx.serialization.*
|
||||
@ -18,6 +19,7 @@ import kotlinx.serialization.json.JsonObject
|
||||
* @see dev.inmo.tgbotapi.extensions.utils.asLiveLocation
|
||||
*/
|
||||
@Serializable(LocationSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface Location : Locationed, HorizontallyAccured
|
||||
|
||||
@Serializable
|
||||
|
@ -1,9 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types.media
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.requests.abstracts.InputFile
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(TelegramMediaSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface TelegramMedia {
|
||||
val type: String
|
||||
val file: InputFile
|
||||
|
@ -4,6 +4,9 @@ import dev.inmo.tgbotapi.abstracts.WithUser
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
|
||||
|
||||
data class LeftChatMember(
|
||||
data class LeftChatMemberEvent(
|
||||
override val user: User
|
||||
) : PublicChatEvent, WithUser
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("dev.inmo.tgbotapi.types.message.ChatEvents", "LeftChatMemberEvent"))
|
||||
typealias LeftChatMember = LeftChatMemberEvent
|
||||
|
@ -1,3 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
|
||||
@ClassCastsIncluded
|
||||
interface ChatEvent
|
||||
|
@ -1,10 +1,12 @@
|
||||
package dev.inmo.tgbotapi.types.message
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
|
||||
@ClassCastsIncluded
|
||||
sealed interface ForwardInfo {
|
||||
abstract val dateOfOriginal: TelegramDate
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||
import dev.inmo.tgbotapi.types.chat.Chat
|
||||
import dev.inmo.tgbotapi.types.message.RawMessage
|
||||
@ -9,6 +10,7 @@ import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@ClassCastsIncluded
|
||||
interface Message {
|
||||
val messageId: MessageIdentifier
|
||||
val chat: Chat
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.message.content
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||
@ -108,6 +109,7 @@ sealed interface MediaContent: MessageContent {
|
||||
fun asTelegramMedia(): TelegramMedia
|
||||
}
|
||||
|
||||
@ClassCastsIncluded
|
||||
sealed interface ResendableContent {
|
||||
fun createResend(
|
||||
chatId: ChatIdentifier,
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.message.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.captionLength
|
||||
import dev.inmo.tgbotapi.types.textLength
|
||||
import kotlinx.serialization.Serializable
|
||||
@ -10,6 +11,7 @@ typealias TextSourcesList = List<TextSource>
|
||||
typealias MutableTextSourcesList = MutableList<TextSource>
|
||||
|
||||
@Serializable(TextSourceSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface TextSource {
|
||||
val markdown: String
|
||||
val markdownV2: String
|
||||
|
@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.types.passport
|
||||
import dev.inmo.micro_utils.crypto.MD5
|
||||
import dev.inmo.micro_utils.crypto.md5
|
||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.passport.encrypted.type
|
||||
@ -18,6 +19,7 @@ import kotlinx.serialization.json.*
|
||||
val ByteArray.passportFileHash: MD5
|
||||
get() = md5()
|
||||
|
||||
@ClassCastsIncluded
|
||||
@Serializable(PassportElementErrorSerializer::class)
|
||||
sealed class PassportElementError {
|
||||
abstract val source: String
|
||||
|
@ -1,7 +1,9 @@
|
||||
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
||||
|
||||
@ClassCastsIncluded
|
||||
interface SecureValue {
|
||||
val credentials: List<EndDataCredentials>
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.passport.encrypted.abstracts
|
||||
|
||||
import dev.inmo.micro_utils.crypto.SourceBytes
|
||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
@ -9,6 +10,7 @@ import kotlinx.serialization.json.JsonObject
|
||||
typealias PassportElementHash = SourceBytes
|
||||
|
||||
@Serializable(EncryptedElementSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
interface EncryptedPassportElement {
|
||||
val hash: PassportElementHash
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.polls
|
||||
import com.soywiz.klock.DateTime
|
||||
import com.soywiz.klock.TimeSpan
|
||||
import dev.inmo.tgbotapi.abstracts.TextedInput
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.*
|
||||
import dev.inmo.tgbotapi.types.message.RawMessageEntity
|
||||
@ -16,6 +17,7 @@ import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
@ClassCastsIncluded
|
||||
sealed interface ScheduledCloseInfo {
|
||||
val closeDateTime: DateTime
|
||||
}
|
||||
@ -45,6 +47,7 @@ val LongSeconds.asExactScheduledCloseInfo
|
||||
)
|
||||
|
||||
@Serializable(PollSerializer::class)
|
||||
@ClassCastsIncluded
|
||||
sealed interface Poll {
|
||||
val id: PollIdentifier
|
||||
val question: String
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.update.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import dev.inmo.tgbotapi.types.UpdateIdentifier
|
||||
import dev.inmo.tgbotapi.types.update.RawUpdate
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@ -10,6 +11,7 @@ import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@ClassCastsIncluded
|
||||
interface Update {
|
||||
val updateId: UpdateIdentifier
|
||||
val data: Any
|
||||
|
@ -0,0 +1,3 @@
|
||||
package dev.inmo.tgbotapi.utils.internal
|
||||
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
8
tgbotapi.ksp/lib/build.gradle
Normal file
8
tgbotapi.ksp/lib/build.gradle
Normal file
@ -0,0 +1,8 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
}
|
||||
|
||||
project.description = "Class Casts generator KSP library to include into your library"
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
apply from: "$publishGradlePath"
|
@ -0,0 +1,5 @@
|
||||
package dev.inmo.tgbotapi.ksp.lib
|
||||
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class ClassCastsIncluded
|
13
tgbotapi.ksp/processor/build.gradle
Normal file
13
tgbotapi.ksp/processor/build.gradle
Normal file
@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.jvm"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation libs.kotlin.poet
|
||||
implementation libs.ksp
|
||||
implementation project(":tgbotapi.ksp:lib")
|
||||
}
|
103
tgbotapi.ksp/processor/src/main/kotlin/ClassCastsFiller.kt
Normal file
103
tgbotapi.ksp/processor/src/main/kotlin/ClassCastsFiller.kt
Normal file
@ -0,0 +1,103 @@
|
||||
package dev.inmo.tgbotapi.ksp.processor
|
||||
|
||||
import com.google.devtools.ksp.symbol.*
|
||||
import com.squareup.kotlinpoet.*
|
||||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
|
||||
import com.squareup.kotlinpoet.ksp.*
|
||||
|
||||
private fun FileSpec.Builder.addTopLevelImport(className: ClassName) {
|
||||
className.topLevelClassName().let {
|
||||
addImport(it.packageName, it.simpleNames)
|
||||
}
|
||||
}
|
||||
|
||||
private fun FileSpec.Builder.createTypeDefinition(ksClassDeclaration: KSClassDeclaration): TypeName {
|
||||
val className = ksClassDeclaration.toClassName()
|
||||
return if (ksClassDeclaration.typeParameters.isNotEmpty()) {
|
||||
className.parameterizedBy(
|
||||
ksClassDeclaration.typeParameters.map {
|
||||
it.bounds.first().resolve().also {
|
||||
val typeClassName = it.toClassName()
|
||||
addTopLevelImport(typeClassName)
|
||||
}.toTypeName()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
className
|
||||
}
|
||||
}
|
||||
|
||||
fun FileSpec.Builder.fill(
|
||||
sourceKSClassDeclaration: KSClassDeclaration,
|
||||
subtypesMap: Map<KSClassDeclaration, Set<KSClassDeclaration>>,
|
||||
targetClassDeclaration: KSClassDeclaration = sourceKSClassDeclaration
|
||||
) {
|
||||
if (sourceKSClassDeclaration == targetClassDeclaration) {
|
||||
subtypesMap[sourceKSClassDeclaration] ?.forEach {
|
||||
fill(sourceKSClassDeclaration, subtypesMap, it)
|
||||
}
|
||||
} else {
|
||||
val sourceClassName = sourceKSClassDeclaration.toClassName()
|
||||
val targetClassClassName = targetClassDeclaration.toClassName()
|
||||
val targetClassTypeDefinition = createTypeDefinition(targetClassDeclaration)
|
||||
val simpleName = targetClassDeclaration.simpleName.asString()
|
||||
val withFirstLowerCase = simpleName.replaceFirstChar { it.lowercase() }
|
||||
val castedOrNullName = "${withFirstLowerCase}OrNull"
|
||||
|
||||
addTopLevelImport(targetClassClassName)
|
||||
addFunction(
|
||||
FunSpec.builder(castedOrNullName).apply {
|
||||
receiver(sourceClassName)
|
||||
addCode(
|
||||
"return this as? %L",
|
||||
targetClassTypeDefinition
|
||||
)
|
||||
returns(targetClassTypeDefinition.copy(nullable = true))
|
||||
addModifiers(KModifier.INLINE)
|
||||
}.build()
|
||||
)
|
||||
addFunction(
|
||||
FunSpec.builder("${withFirstLowerCase}OrThrow").apply {
|
||||
receiver(sourceClassName)
|
||||
addCode(
|
||||
"return this as %L",
|
||||
targetClassTypeDefinition
|
||||
)
|
||||
returns(targetClassTypeDefinition)
|
||||
addModifiers(KModifier.INLINE)
|
||||
}.build()
|
||||
)
|
||||
addFunction(
|
||||
FunSpec.builder("if$simpleName").apply {
|
||||
val genericType = TypeVariableName("T", null)
|
||||
addTypeVariable(genericType)
|
||||
receiver(sourceClassName)
|
||||
addParameter(
|
||||
"block",
|
||||
LambdaTypeName.get(
|
||||
null,
|
||||
targetClassTypeDefinition,
|
||||
returnType = genericType
|
||||
)
|
||||
)
|
||||
addCode(
|
||||
"return ${castedOrNullName}() ?.let(block)",
|
||||
targetClassTypeDefinition
|
||||
)
|
||||
returns(genericType.copy(nullable = true))
|
||||
addModifiers(KModifier.INLINE)
|
||||
}.build()
|
||||
)
|
||||
|
||||
subtypesMap[targetClassDeclaration] ?.let {
|
||||
if (it.count { it.classKind == ClassKind.CLASS } > 1) {
|
||||
it
|
||||
} else {
|
||||
it.filter { it.classKind != ClassKind.CLASS }
|
||||
}
|
||||
} ?.forEach {
|
||||
fill(sourceKSClassDeclaration, subtypesMap, it)
|
||||
fill(targetClassDeclaration, subtypesMap, it)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package dev.inmo.tgbotapi.ksp.processor
|
||||
|
||||
import com.google.devtools.ksp.getAllSuperTypes
|
||||
import com.google.devtools.ksp.processing.*
|
||||
import com.google.devtools.ksp.symbol.KSAnnotated
|
||||
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
||||
import com.squareup.kotlinpoet.FileSpec
|
||||
import com.squareup.kotlinpoet.ksp.writeTo
|
||||
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||
import java.io.File
|
||||
|
||||
class TelegramBotAPISymbolProcessor(
|
||||
private val codeGenerator: CodeGenerator,
|
||||
private val targetPackage: String = "",
|
||||
private val outputFile: String = "Output",
|
||||
private val outputFolder: String? = null
|
||||
) : SymbolProcessor {
|
||||
override fun process(resolver: Resolver): List<KSAnnotated> {
|
||||
val classes = resolver.getSymbolsWithAnnotation(ClassCastsIncluded::class.qualifiedName!!).filterIsInstance<KSClassDeclaration>()
|
||||
val classesSubtypes = mutableMapOf<KSClassDeclaration, MutableSet<KSClassDeclaration>>()
|
||||
|
||||
resolver.getAllFiles().forEach {
|
||||
it.declarations.forEach { potentialSubtype ->
|
||||
if (potentialSubtype is KSClassDeclaration) {
|
||||
val allSupertypes = potentialSubtype.getAllSuperTypes().map { it.declaration }
|
||||
classes.forEach {
|
||||
if (it in allSupertypes) {
|
||||
classesSubtypes.getOrPut(it) { mutableSetOf() }.add(potentialSubtype)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fun fillWithSealeds(source: KSClassDeclaration, current: KSClassDeclaration = source) {
|
||||
current.getSealedSubclasses().forEach {
|
||||
classesSubtypes.getOrPut(source) { mutableSetOf() }.add(it)
|
||||
fillWithSealeds(source, it)
|
||||
}
|
||||
}
|
||||
classes.forEach { fillWithSealeds(it) }
|
||||
|
||||
val fileSpec = FileSpec.builder(
|
||||
targetPackage,
|
||||
outputFile
|
||||
).apply {
|
||||
classes.forEach {
|
||||
fill(
|
||||
it,
|
||||
classesSubtypes.toMap()
|
||||
)
|
||||
}
|
||||
}.build()
|
||||
runCatching {
|
||||
outputFolder ?.also {
|
||||
File(it).apply {
|
||||
delete()
|
||||
runCatching { mkdirs() }
|
||||
fileSpec.writeTo(this)
|
||||
}
|
||||
} ?: fileSpec.writeTo(codeGenerator, false)
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package dev.inmo.tgbotapi.ksp.processor
|
||||
|
||||
import com.google.devtools.ksp.processing.*
|
||||
|
||||
class TelegramBotAPISymbolProcessorProvider : SymbolProcessorProvider {
|
||||
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
|
||||
return TelegramBotAPISymbolProcessor(
|
||||
environment.codeGenerator,
|
||||
environment.options["cctargetPackage"] ?: "",
|
||||
environment.options["ccoutputFileName"] ?: "Output",
|
||||
environment.options["ccoutputFolder"],
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
dev.inmo.tgbotapi.ksp.processor.TelegramBotAPISymbolProcessorProvider
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user