mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
commit
e831ca143e
28
CHANGELOG.md
28
CHANGELOG.md
@ -1,5 +1,33 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 3.0.0
|
||||||
|
|
||||||
|
**ALL OLD DEPRECATIONS HAVE BEEN REMOVED**
|
||||||
|
|
||||||
|
**`copyMessage` HAVE CHANGED THEIR SIGNATURE BY SWAPPING FROM AND TO CHAT IDS**
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Kotlin`: `1.6.21` -> `1.7.10`
|
||||||
|
* `Serialization`: `1.3.3` -> `1.4.0-RC`
|
||||||
|
* `Korlibs`: `2.7.0` -> `3.0.0`
|
||||||
|
* `UUID`: `0.4.1` -> `0.5.0`
|
||||||
|
* `MicroUtils`: `0.11.13` -> `0.12.0`
|
||||||
|
* `Core`:
|
||||||
|
* Interface `ReplyMakrup` has been renamed to `WithReplyMarkup` to correspond its purpose
|
||||||
|
* Data class `LeftChatMember` has been renamed to `LeftChatMemberEvent` to avoid type ambiguite with the other `LeftChatMember`
|
||||||
|
* `ForwardInfo` hierarchy has been fully reworked:
|
||||||
|
* `AnonymousForwardInfo` -> `ForwardInfo.ByAnonymous`
|
||||||
|
* `UserForwardInfo` -> `ForwardInfo.ByUser`
|
||||||
|
* `ForwardFromPublicChatInfo` -> `ForwardInfo.PublicChat`
|
||||||
|
* `ForwardFromChannelInfo` -> `ForwardInfo.PublicChat.FromChannel`
|
||||||
|
* `ForwardFromSupergroupInfo` -> `ForwardInfo.PublicChat.FromSupergroup`
|
||||||
|
* `ForwardInfo.PublicChat.SentByChannel` ___has been created___
|
||||||
|
* `API`:
|
||||||
|
* Add new `Flow`-based live locations API
|
||||||
|
* Add `sendLocation` for sending live locations
|
||||||
|
* `Utils`:
|
||||||
|
* **BREAKING CHANGES** Now all new classcasts (like `Chat.ifPrivateChat` etc.) have been rewritten to be generated with `ksp` and `kotlin poet`
|
||||||
|
|
||||||
## 2.2.2
|
## 2.2.2
|
||||||
|
|
||||||
* `Utils`:
|
* `Utils`:
|
||||||
|
16
README.md
16
README.md
@ -1,9 +1,17 @@
|
|||||||
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.1-blue)](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.1-blue)](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
||||||
|
|
||||||
| [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue&logo=google-sheets)](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) [![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue&logo=telegram)](https://t.me/InMoTelegramBotAPI) |
|
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue&logo=bookstack)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|
||||||
|:---:|
|
|:---:|:---:|
|
||||||
| [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue&logo=bookstack)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|
| Useful repos | [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) |
|
||||||
| [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/InMoTelegramBotAPI) |
|
| Misc | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue&logo=google-sheets)](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) |
|
||||||
|
|
||||||
|
<!--- [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/InMoTelegramBotAPI) --->
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://t.me/InMoTelegramBotAPI">
|
||||||
|
<img src="./resources/tg_channel_qr.jpg">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
Hello! This is a set of libraries for working with Telegram Bot API.
|
Hello! This is a set of libraries for working with Telegram Bot API.
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ buildscript {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath libs.kotlin.gradle.plugin
|
classpath libs.kotlin.gradle.plugin
|
||||||
|
classpath libs.kotlin.ksp.plugin
|
||||||
classpath libs.kotlin.serialization.plugin
|
classpath libs.kotlin.serialization.plugin
|
||||||
classpath libs.kotlin.dokka.plugin
|
classpath libs.kotlin.dokka.plugin
|
||||||
classpath libs.github.release.plugin
|
classpath libs.github.release.plugin
|
||||||
|
@ -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=2.2.2
|
library_version=3.0.0
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kotlin = "1.6.21"
|
kotlin = "1.7.10"
|
||||||
kotlin-serialization = "1.3.3"
|
kotlin-serialization = "1.4.0-RC"
|
||||||
kotlin-coroutines = "1.6.4"
|
kotlin-coroutines = "1.6.4"
|
||||||
kotlin-gradle-plugin = "7.0.4"
|
|
||||||
|
|
||||||
javax-activation = "1.1.1"
|
javax-activation = "1.1.1"
|
||||||
|
|
||||||
korlibs = "2.7.0"
|
korlibs = "3.0.0"
|
||||||
uuid = "0.4.1"
|
uuid = "0.5.0"
|
||||||
ktor = "2.0.3"
|
ktor = "2.0.3"
|
||||||
|
|
||||||
microutils = "0.11.13"
|
ksp = "1.7.10-1.0.6"
|
||||||
|
kotlin-poet = "1.12.0"
|
||||||
|
|
||||||
|
microutils = "0.12.0"
|
||||||
|
|
||||||
github-release-plugin = "2.4.1"
|
github-release-plugin = "2.4.1"
|
||||||
|
|
||||||
@ -46,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-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" }
|
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
|
# buildscript classpaths
|
||||||
|
|
||||||
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
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-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
|
||||||
kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", 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" }
|
github-release-plugin = { module = "com.github.breadmoirai:github-release", version.ref = "github-release-plugin" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
|
|
||||||
|
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||||
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
||||||
|
@ -12,6 +12,8 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
include ":tgbotapi.core"
|
include ":tgbotapi.core"
|
||||||
|
include ":tgbotapi.ksp:processor"
|
||||||
|
include ":tgbotapi.ksp:lib"
|
||||||
include ":tgbotapi.api"
|
include ":tgbotapi.api"
|
||||||
include ":tgbotapi.utils"
|
include ":tgbotapi.utils"
|
||||||
include ":tgbotapi.behaviour_builder"
|
include ":tgbotapi.behaviour_builder"
|
||||||
|
@ -0,0 +1,151 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
||||||
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.edit.location.live.editLiveLocation
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.sendLiveLocation
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
|
import dev.inmo.tgbotapi.types.location.LiveLocation
|
||||||
|
import dev.inmo.tgbotapi.types.location.Location
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlin.js.JsName
|
||||||
|
import kotlin.jvm.JvmName
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class EditLiveLocationInfo(
|
||||||
|
override val latitude: Double,
|
||||||
|
override val longitude: Double,
|
||||||
|
override val horizontalAccuracy: Meters? = null,
|
||||||
|
override val heading: Degrees? = null,
|
||||||
|
override val proximityAlertRadius: Meters? = null,
|
||||||
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||||
|
) : Locationed, HorizontallyAccured, ProximityAlertable, Headed, WithReplyMarkup
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will [sendLiveLocation] with the first [EditLiveLocationInfo] data and update than. Each [liveTimeMillis] passing,
|
||||||
|
* the message will be sent again and new edits will be applied to the new message
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.handleLiveLocation(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
locationsFlow: Flow<EditLiveLocationInfo>,
|
||||||
|
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null
|
||||||
|
) {
|
||||||
|
var currentLiveLocationMessage: ContentMessage<LocationContent>? = null
|
||||||
|
val updateMessageJob = CoroutineScope(currentCoroutineContext().LinkedSupervisorJob()).launchSafelyWithoutExceptions(start = CoroutineStart.LAZY) {
|
||||||
|
while (isActive) {
|
||||||
|
delay(liveTimeMillis)
|
||||||
|
// Remove previous location message info to resend live location message
|
||||||
|
currentLiveLocationMessage = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
locationsFlow.collect {
|
||||||
|
val capturedLiveLocationMessage = currentLiveLocationMessage
|
||||||
|
if (capturedLiveLocationMessage == null) {
|
||||||
|
updateMessageJob.start()
|
||||||
|
currentLiveLocationMessage = sendLiveLocation(
|
||||||
|
chatId,
|
||||||
|
it.latitude,
|
||||||
|
it.longitude,
|
||||||
|
ceil(liveTimeMillis.toDouble() / 1000).toInt(),
|
||||||
|
it.horizontalAccuracy,
|
||||||
|
it.heading,
|
||||||
|
it.proximityAlertRadius,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
it.replyMarkup
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
editLiveLocation(
|
||||||
|
capturedLiveLocationMessage,
|
||||||
|
it.latitude,
|
||||||
|
it.longitude,
|
||||||
|
it.horizontalAccuracy,
|
||||||
|
it.heading,
|
||||||
|
it.proximityAlertRadius,
|
||||||
|
it.replyMarkup
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will apply [Flow.map] to the [locationsFlow] to create [EditLiveLocationInfo] and pass the result flow to the
|
||||||
|
* [handleLiveLocation] with [Flow] typed by [EditLiveLocationInfo]
|
||||||
|
*/
|
||||||
|
@JvmName("handleLiveLocationWithLocation")
|
||||||
|
@JsName("handleLiveLocationWithLocation")
|
||||||
|
suspend fun TelegramBot.handleLiveLocation(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
locationsFlow: Flow<Location>,
|
||||||
|
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null
|
||||||
|
) {
|
||||||
|
handleLiveLocation(
|
||||||
|
chatId,
|
||||||
|
locationsFlow.map {
|
||||||
|
EditLiveLocationInfo(
|
||||||
|
it.latitude,
|
||||||
|
it.longitude,
|
||||||
|
it.horizontalAccuracy,
|
||||||
|
(it as? LiveLocation) ?.heading,
|
||||||
|
(it as? LiveLocation) ?.proximityAlertRadius,
|
||||||
|
(it as? WithReplyMarkup) ?.replyMarkup as? InlineKeyboardMarkup
|
||||||
|
)
|
||||||
|
},
|
||||||
|
liveTimeMillis,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will apply [Flow.map] to the [locationsFlow] to create [EditLiveLocationInfo] and pass the result flow to the
|
||||||
|
* [handleLiveLocation] with [Flow] typed by [EditLiveLocationInfo]
|
||||||
|
*/
|
||||||
|
@JvmName("handleLiveLocationWithLatLong")
|
||||||
|
@JsName("handleLiveLocationWithLatLong")
|
||||||
|
suspend fun TelegramBot.handleLiveLocation(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
locationsFlow: Flow<Pair<Double, Double>>,
|
||||||
|
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null
|
||||||
|
) {
|
||||||
|
handleLiveLocation(
|
||||||
|
chatId,
|
||||||
|
locationsFlow.map { (lat, long) ->
|
||||||
|
EditLiveLocationInfo(
|
||||||
|
lat,
|
||||||
|
long
|
||||||
|
)
|
||||||
|
},
|
||||||
|
liveTimeMillis,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply
|
||||||
|
)
|
||||||
|
}
|
@ -229,3 +229,224 @@ suspend inline fun TelegramBot.copyMessage(
|
|||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = copyMessage(message.chat, message.messageId, toChat, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
) = copyMessage(message.chat, message.messageId, toChat, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChatId: ChatIdentifier,
|
||||||
|
fromChatId: ChatIdentifier,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
text: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = execute(
|
||||||
|
CopyMessage(
|
||||||
|
fromChatId,
|
||||||
|
messageId,
|
||||||
|
toChatId,
|
||||||
|
text,
|
||||||
|
parseMode,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChatId: ChatIdentifier,
|
||||||
|
fromChat: Chat,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
text: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = copyMessage(
|
||||||
|
toChatId,
|
||||||
|
fromChat.id,
|
||||||
|
messageId,
|
||||||
|
text,
|
||||||
|
parseMode,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChat: Chat,
|
||||||
|
fromChatId: ChatIdentifier,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
text: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = copyMessage(
|
||||||
|
toChat.id,
|
||||||
|
fromChatId,
|
||||||
|
messageId,
|
||||||
|
text,
|
||||||
|
parseMode,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChat: Chat,
|
||||||
|
fromChat: Chat,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
text: String? = null,
|
||||||
|
parseMode: ParseMode? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = copyMessage(
|
||||||
|
toChat.id,
|
||||||
|
fromChat.id,
|
||||||
|
messageId,
|
||||||
|
text,
|
||||||
|
parseMode,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChatId: ChatIdentifier,
|
||||||
|
fromChatId: ChatIdentifier,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
entities: TextSourcesList,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = execute(
|
||||||
|
CopyMessage(
|
||||||
|
fromChatId,
|
||||||
|
messageId,
|
||||||
|
toChatId,
|
||||||
|
entities,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChatId: ChatIdentifier,
|
||||||
|
fromChat: Chat,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
entities: TextSourcesList,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = copyMessage(
|
||||||
|
toChatId,
|
||||||
|
fromChat.id,
|
||||||
|
messageId,
|
||||||
|
entities,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChat: Chat,
|
||||||
|
fromChatId: ChatIdentifier,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
entities: TextSourcesList,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = copyMessage(
|
||||||
|
toChat.id,
|
||||||
|
fromChatId,
|
||||||
|
messageId,
|
||||||
|
entities,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend inline fun TelegramBot.copyMessage(
|
||||||
|
toChat: Chat,
|
||||||
|
fromChat: Chat,
|
||||||
|
messageId: MessageIdentifier,
|
||||||
|
entities: TextSourcesList,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = copyMessage(
|
||||||
|
toChat.id,
|
||||||
|
fromChat.id,
|
||||||
|
messageId,
|
||||||
|
entities,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
@ -1,180 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api.send
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
|
||||||
import dev.inmo.tgbotapi.requests.send.CopyMessage
|
|
||||||
import dev.inmo.tgbotapi.requests.send.OrderChangingDeprecationWarn
|
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
|
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
|
||||||
import dev.inmo.tgbotapi.types.message.ParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
|
||||||
|
|
||||||
// TODO:: Swap fromChatId and toChatId for more correct order of parameters
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChatId: ChatIdentifier,
|
|
||||||
toChatId: ChatIdentifier,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = execute(
|
|
||||||
CopyMessage(
|
|
||||||
fromChatId,
|
|
||||||
messageId,
|
|
||||||
toChatId,
|
|
||||||
text,
|
|
||||||
parseMode,
|
|
||||||
disableNotification,
|
|
||||||
protectContent,
|
|
||||||
replyToMessageId,
|
|
||||||
allowSendingWithoutReply,
|
|
||||||
replyMarkup
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChat: Chat,
|
|
||||||
toChatId: ChatIdentifier,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = copyMessage(fromChat.id, toChatId, messageId, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChatId: ChatIdentifier,
|
|
||||||
toChat: Chat,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = copyMessage(fromChatId, toChat.id, messageId, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChat: Chat,
|
|
||||||
toChat: Chat,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
text: String? = null,
|
|
||||||
parseMode: ParseMode? = null,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = copyMessage(fromChat.id, toChat.id, messageId, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChatId: ChatIdentifier,
|
|
||||||
toChatId: ChatIdentifier,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = execute(
|
|
||||||
CopyMessage(
|
|
||||||
fromChatId,
|
|
||||||
messageId,
|
|
||||||
toChatId,
|
|
||||||
entities,
|
|
||||||
disableNotification,
|
|
||||||
protectContent,
|
|
||||||
replyToMessageId,
|
|
||||||
allowSendingWithoutReply,
|
|
||||||
replyMarkup
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChat: Chat,
|
|
||||||
toChatId: ChatIdentifier,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = copyMessage(fromChat.id, toChatId, messageId, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChatId: ChatIdentifier,
|
|
||||||
toChat: Chat,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = copyMessage(fromChatId, toChat.id, messageId, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
|
||||||
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
|
||||||
*/
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
suspend inline fun TelegramBot.copyMessage(
|
|
||||||
fromChat: Chat,
|
|
||||||
toChat: Chat,
|
|
||||||
messageId: MessageIdentifier,
|
|
||||||
entities: TextSourcesList,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
protectContent: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
) = copyMessage(fromChat.id, toChat.id, messageId, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
|
@ -1,6 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api.send
|
package dev.inmo.tgbotapi.extensions.api.send
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.games.sendGame
|
import dev.inmo.tgbotapi.extensions.api.send.games.sendGame
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.*
|
import dev.inmo.tgbotapi.extensions.api.send.media.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.payments.sendInvoice
|
import dev.inmo.tgbotapi.extensions.api.send.payments.sendInvoice
|
||||||
@ -29,6 +31,10 @@ import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
|||||||
import dev.inmo.tgbotapi.types.polls.*
|
import dev.inmo.tgbotapi.types.polls.*
|
||||||
import dev.inmo.tgbotapi.types.venue.Venue
|
import dev.inmo.tgbotapi.types.venue.Venue
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlin.js.JsName
|
||||||
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
|
|
||||||
// Contact
|
// Contact
|
||||||
@ -950,7 +956,18 @@ suspend inline fun TelegramBot.reply(
|
|||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = copyMessage(fromChatId, to.chat.id, messageId, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
|
) = copyMessage(
|
||||||
|
to.chat.id,
|
||||||
|
fromChatId,
|
||||||
|
messageId,
|
||||||
|
text,
|
||||||
|
parseMode,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
to.messageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
suspend inline fun TelegramBot.reply(
|
suspend inline fun TelegramBot.reply(
|
||||||
to: Message,
|
to: Message,
|
||||||
@ -995,6 +1012,80 @@ suspend fun TelegramBot.reply(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will use [handleLiveLocation] with replying to [message] each time new message will be sent by live location update
|
||||||
|
*
|
||||||
|
* @see handleLiveLocation
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.reply(
|
||||||
|
message: Message,
|
||||||
|
locationsFlow: Flow<EditLiveLocationInfo>,
|
||||||
|
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null
|
||||||
|
) = handleLiveLocation(
|
||||||
|
message.chat.id,
|
||||||
|
locationsFlow,
|
||||||
|
liveTimeMillis,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
message.messageId,
|
||||||
|
allowSendingWithoutReply
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will use [handleLiveLocation] with replying to [message] each time new message will be sent by live location update
|
||||||
|
*
|
||||||
|
* @see handleLiveLocation
|
||||||
|
*/
|
||||||
|
@JvmName("replyLiveLocationWithLocation")
|
||||||
|
@JsName("replyLiveLocationWithLocation")
|
||||||
|
suspend fun TelegramBot.reply(
|
||||||
|
message: Message,
|
||||||
|
locationsFlow: Flow<Location>,
|
||||||
|
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null
|
||||||
|
) {
|
||||||
|
handleLiveLocation(
|
||||||
|
message.chat.id,
|
||||||
|
locationsFlow,
|
||||||
|
liveTimeMillis,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
message.messageId,
|
||||||
|
allowSendingWithoutReply
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will use [handleLiveLocation] with replying to [message] each time new message will be sent by live location update
|
||||||
|
*
|
||||||
|
* @see handleLiveLocation
|
||||||
|
*/
|
||||||
|
@JvmName("replyLiveLocationWithLatLong")
|
||||||
|
@JsName("replyLiveLocationWithLatLong")
|
||||||
|
suspend fun TelegramBot.reply(
|
||||||
|
message: Message,
|
||||||
|
locationsFlow: Flow<Pair<Double, Double>>,
|
||||||
|
liveTimeMillis: Long = defaultLivePeriodDelayMillis,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null
|
||||||
|
) {
|
||||||
|
handleLiveLocation(
|
||||||
|
message.chat.id,
|
||||||
|
locationsFlow,
|
||||||
|
liveTimeMillis,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
message.messageId,
|
||||||
|
allowSendingWithoutReply
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun TelegramBot.reply(
|
suspend fun TelegramBot.reply(
|
||||||
to: Message,
|
to: Message,
|
||||||
mediaFile: TelegramMediaFile,
|
mediaFile: TelegramMediaFile,
|
||||||
|
@ -0,0 +1,212 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.send
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.send.SendLiveLocation
|
||||||
|
import dev.inmo.tgbotapi.requests.send.SendStaticLocation
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
|
import dev.inmo.tgbotapi.types.location.Location
|
||||||
|
import dev.inmo.tgbotapi.types.location.StaticLocation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLocation(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
latitude: Double,
|
||||||
|
longitude: Double,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = execute(
|
||||||
|
SendLiveLocation(
|
||||||
|
chatId,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
livePeriod,
|
||||||
|
horizontalAccuracy,
|
||||||
|
heading,
|
||||||
|
proximityAlertRadius,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLocation(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
location: Location,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendLocation(
|
||||||
|
chatId,
|
||||||
|
location.latitude,
|
||||||
|
location.longitude,
|
||||||
|
livePeriod,
|
||||||
|
horizontalAccuracy,
|
||||||
|
heading,
|
||||||
|
proximityAlertRadius,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLocation(
|
||||||
|
chat: Chat,
|
||||||
|
latitude: Double,
|
||||||
|
longitude: Double,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendLocation(
|
||||||
|
chat.id,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
livePeriod,
|
||||||
|
horizontalAccuracy,
|
||||||
|
heading,
|
||||||
|
proximityAlertRadius,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLocation(
|
||||||
|
chat: Chat,
|
||||||
|
location: Location,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendLocation(
|
||||||
|
chat.id,
|
||||||
|
location.latitude,
|
||||||
|
location.longitude,
|
||||||
|
livePeriod,
|
||||||
|
horizontalAccuracy,
|
||||||
|
heading,
|
||||||
|
proximityAlertRadius,
|
||||||
|
disableNotification,
|
||||||
|
protectContent,
|
||||||
|
replyToMessageId,
|
||||||
|
allowSendingWithoutReply,
|
||||||
|
replyMarkup
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLiveLocation(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
latitude: Double,
|
||||||
|
longitude: Double,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendLocation(chatId, latitude, longitude, livePeriod, horizontalAccuracy, heading, proximityAlertRadius, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLiveLocation(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
location: Location,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendLocation(chatId, location.latitude, location.longitude, livePeriod, horizontalAccuracy, heading, proximityAlertRadius, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLiveLocation(
|
||||||
|
chat: Chat,
|
||||||
|
latitude: Double,
|
||||||
|
longitude: Double,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendLocation(chat.id, latitude, longitude, livePeriod, horizontalAccuracy, heading, proximityAlertRadius, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
|
||||||
|
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
|
||||||
|
*/
|
||||||
|
suspend fun TelegramBot.sendLiveLocation(
|
||||||
|
chat: Chat,
|
||||||
|
location: Location,
|
||||||
|
livePeriod: Seconds,
|
||||||
|
horizontalAccuracy: Meters? = null,
|
||||||
|
heading: Degrees? = null,
|
||||||
|
proximityAlertRadius: Meters? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
protectContent: Boolean = false,
|
||||||
|
replyToMessageId: MessageIdentifier? = null,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = sendLocation(chat.id, location.latitude, location.longitude, livePeriod, horizontalAccuracy, heading, proximityAlertRadius, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.types.ChatIdentifier
|
|||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
|
import dev.inmo.tgbotapi.types.location.Location
|
||||||
import dev.inmo.tgbotapi.types.location.StaticLocation
|
import dev.inmo.tgbotapi.types.location.StaticLocation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,7 +41,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
*/
|
*/
|
||||||
suspend fun TelegramBot.sendLocation(
|
suspend fun TelegramBot.sendLocation(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
location: StaticLocation,
|
location: Location,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
@ -87,7 +88,7 @@ suspend fun TelegramBot.sendLocation(
|
|||||||
*/
|
*/
|
||||||
suspend fun TelegramBot.sendLocation(
|
suspend fun TelegramBot.sendLocation(
|
||||||
chat: Chat,
|
chat: Chat,
|
||||||
location: StaticLocation,
|
location: Location,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
@ -125,7 +126,7 @@ suspend fun TelegramBot.sendStaticLocation(
|
|||||||
*/
|
*/
|
||||||
suspend fun TelegramBot.sendStaticLocation(
|
suspend fun TelegramBot.sendStaticLocation(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
location: StaticLocation,
|
location: Location,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
@ -154,7 +155,7 @@ suspend fun TelegramBot.sendStaticLocation(
|
|||||||
*/
|
*/
|
||||||
suspend fun TelegramBot.sendStaticLocation(
|
suspend fun TelegramBot.sendStaticLocation(
|
||||||
chat: Chat,
|
chat: Chat,
|
||||||
location: StaticLocation,
|
location: Location,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
protectContent: Boolean = false,
|
protectContent: Boolean = false,
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.bot.TelegramBot
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
|
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
|
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
|
||||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,20 +57,6 @@ interface BehaviourContext : FlowsUpdatesFilter, TelegramBot, CoroutineScope {
|
|||||||
upstreamUpdatesFlow: Flow<Update>? = null,
|
upstreamUpdatesFlow: Flow<Update>? = null,
|
||||||
triggersHolder: TriggersHolder = TriggersHolder()
|
triggersHolder: TriggersHolder = TriggersHolder()
|
||||||
): BehaviourContext
|
): BehaviourContext
|
||||||
|
|
||||||
/**
|
|
||||||
* @param updatesFilter unused
|
|
||||||
*/
|
|
||||||
@Deprecated("Do not use this method")
|
|
||||||
fun copy(
|
|
||||||
bot: TelegramBot = this.bot,
|
|
||||||
scope: CoroutineScope = this.scope,
|
|
||||||
broadcastChannelsSize: Int = 100,
|
|
||||||
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
|
|
||||||
upstreamUpdatesFlow: Flow<Update>? = null,
|
|
||||||
triggersHolder: TriggersHolder = TriggersHolder(),
|
|
||||||
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null
|
|
||||||
): BehaviourContext = copy(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, triggersHolder)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DefaultBehaviourContext(
|
class DefaultBehaviourContext(
|
||||||
@ -79,9 +65,7 @@ class DefaultBehaviourContext(
|
|||||||
broadcastChannelsSize: Int = 100,
|
broadcastChannelsSize: Int = 100,
|
||||||
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
|
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
|
||||||
private val upstreamUpdatesFlow: Flow<Update>? = null,
|
private val upstreamUpdatesFlow: Flow<Update>? = null,
|
||||||
override val triggersHolder: TriggersHolder = TriggersHolder(),
|
override val triggersHolder: TriggersHolder = TriggersHolder()
|
||||||
@Deprecated("This parameter is not used anymore")
|
|
||||||
private val updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>? = null
|
|
||||||
) : AbstractFlowsUpdatesFilter(), TelegramBot by bot, CoroutineScope by scope, BehaviourContext {
|
) : AbstractFlowsUpdatesFilter(), TelegramBot by bot, CoroutineScope by scope, BehaviourContext {
|
||||||
|
|
||||||
private val additionalUpdatesSharedFlow = MutableSharedFlow<Update>(0, broadcastChannelsSize, onBufferOverflow)
|
private val additionalUpdatesSharedFlow = MutableSharedFlow<Update>(0, broadcastChannelsSize, onBufferOverflow)
|
||||||
@ -137,19 +121,6 @@ fun <BC : BehaviourContext> BC.createSubContext(
|
|||||||
triggersHolder = triggersHolder
|
triggersHolder = triggersHolder
|
||||||
) as BC
|
) as BC
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new [BehaviourContext] using its [BehaviourContext.copy] method
|
|
||||||
*
|
|
||||||
* @param updatesFilter This param will not be used anymore
|
|
||||||
*/
|
|
||||||
@Deprecated("It is not recommended to use updates filter anymore")
|
|
||||||
fun <BC : BehaviourContext> BC.createSubContext(
|
|
||||||
scope: CoroutineScope = LinkedSupervisorScope(),
|
|
||||||
triggersHolder: TriggersHolder = this.triggersHolder,
|
|
||||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
|
||||||
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?,
|
|
||||||
) = createSubContext(scope, triggersHolder, updatesUpstreamFlow)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [kotlin.coroutines.CoroutineContext]
|
* Launch [behaviourContextReceiver] in context of [this] as [BehaviourContext] and as [kotlin.coroutines.CoroutineContext]
|
||||||
*
|
*
|
||||||
@ -187,27 +158,6 @@ suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new one [BehaviourContext] using [createSubContext] and launches [behaviourContextReceiver] in a new context
|
|
||||||
* using [doInContext]
|
|
||||||
*
|
|
||||||
* @param stopOnCompletion ___TRUE BY DEFAULT___
|
|
||||||
* @param updatesFilter Is not used anymore
|
|
||||||
*/
|
|
||||||
@Deprecated("It is not recommended to use updates filter anymore")
|
|
||||||
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter(
|
|
||||||
scope: CoroutineScope = LinkedSupervisorScope(),
|
|
||||||
triggersHolder: TriggersHolder = this.triggersHolder,
|
|
||||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
|
||||||
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?,
|
|
||||||
stopOnCompletion: Boolean = true,
|
|
||||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
|
||||||
): T {
|
|
||||||
return createSubContextAndDoWithUpdatesFilter(
|
|
||||||
scope, triggersHolder, updatesUpstreamFlow, stopOnCompletion, behaviourContextReceiver
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will cancel ALL subsequent contexts, expectations and waiters
|
* This method will cancel ALL subsequent contexts, expectations and waiters
|
||||||
*/
|
*/
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.ExceptionHandler
|
import dev.inmo.micro_utils.coroutines.ExceptionHandler
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
|
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
|
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
|
||||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||||
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
|
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
|
||||||
|
@ -3,14 +3,12 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.callbackQueryUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias CallbackQueryMapper<T> = suspend T.() -> T?
|
typealias CallbackQueryMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
@ -22,7 +20,7 @@ suspend inline fun <reified O> BehaviourContext.waitCallbackQueries(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asCallbackQueryUpdate() ?.data as O).let(::listOfNotNull)
|
(it.callbackQueryUpdateOrNull() ?.data as O).let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.chatJoinRequestUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asChatJoinRequestUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias ChatJoinRequestsMapper = suspend ChatJoinRequest.() -> ChatJoinRequest?
|
typealias ChatJoinRequestsMapper = suspend ChatJoinRequest.() -> ChatJoinRequest?
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ suspend inline fun <reified O> BehaviourContext.internalWaitChatJoinRequests(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asChatJoinRequestUpdate() ?.data as? O).let(::listOfNotNull)
|
(it.chatJoinRequestUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
||||||
import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate
|
import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate
|
||||||
@ -10,7 +9,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
|||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias ChatMemberUpdatedMapper<T> = suspend T.() -> T?
|
typealias ChatMemberUpdatedMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.chosenInlineResultUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asChosenInlineResultUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias ChosenInlineResultMapper<T> = suspend T.() -> T?
|
typealias ChosenInlineResultMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ suspend inline fun <reified O> BehaviourContext.waitChosenInlineResults(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asChosenInlineResultUpdate() ?.data as? O).let(::listOfNotNull)
|
(it.chosenInlineResultUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChosenInlineResult(
|
suspend fun BehaviourContext.waitChosenInlineResult(
|
||||||
|
@ -3,18 +3,9 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
@ -4,18 +4,12 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
|
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
@ -3,22 +3,12 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
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.withContent
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContent(
|
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContent(
|
||||||
|
@ -3,23 +3,16 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asCommonMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContentMessage(
|
suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedContentMessage(
|
||||||
@ -32,7 +25,7 @@ suspend inline fun <reified O : MessageContent> BehaviourContext.waitEditedConte
|
|||||||
) {
|
) {
|
||||||
val messages = when (it) {
|
val messages = when (it) {
|
||||||
is BaseEditMessageUpdate -> {
|
is BaseEditMessageUpdate -> {
|
||||||
val commonMessage = it.data.asCommonMessage() ?: return@expectFlow emptyList()
|
val commonMessage = it.data.commonMessageOrNull() ?: return@expectFlow emptyList()
|
||||||
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
if (commonMessage !is MediaGroupMessage<*> || includeMediaGroups) {
|
||||||
listOf(commonMessage)
|
listOf(commonMessage)
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,19 +3,16 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||||
import dev.inmo.tgbotapi.types.message.PrivateEventMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias EventMessageToEventMapper<T> = suspend ChatEventMessage<T>.() -> T?
|
typealias EventMessageToEventMapper<T> = suspend ChatEventMessage<T>.() -> T?
|
||||||
|
|
||||||
@ -27,7 +24,7 @@ suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEvents(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>() ?.chatEvent.let(::listOfNotNull)
|
it.baseSentMessageUpdateOrNull() ?.data ?.chatEventMessageOrNull() ?.withEvent<O>() ?.chatEvent.let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChannelEvents(
|
suspend fun BehaviourContext.waitChannelEvents(
|
||||||
|
@ -3,19 +3,16 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.ChannelEventMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||||
import dev.inmo.tgbotapi.types.message.PrivateEventMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEventsMessages(
|
suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEventsMessages(
|
||||||
@ -25,7 +22,7 @@ suspend inline fun <reified O : ChatEvent> BehaviourContext.waitEventsMessages(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asBaseSentMessageUpdate() ?.data ?.asChatEventMessage() ?.withEvent<O>().let(::listOfNotNull)
|
it.baseSentMessageUpdateOrNull() ?.data ?.chatEventMessageOrNull() ?.withEvent<O>().let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChannelEventsMessages(
|
suspend fun BehaviourContext.waitChannelEventsMessages(
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.inlineQueryUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
import dev.inmo.tgbotapi.types.InlineQueries.query.*
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias InlineQueryMapper<T> = suspend T.() -> T?
|
typealias InlineQueryMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ suspend inline fun <reified O : InlineQuery> BehaviourContext.waitInlineQueries(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asInlineQueryUpdate() ?.data as? O).let(::listOfNotNull)
|
(it.inlineQueryUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitAnyInlineQuery(
|
suspend fun BehaviourContext.waitAnyInlineQuery(
|
||||||
|
@ -2,15 +2,9 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.sentMediaGroupUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@ -20,7 +15,7 @@ suspend inline fun <reified T : MediaGroupContent> BehaviourContext.buildMediaGr
|
|||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
): Flow<List<MediaGroupMessage<T>>> = flowsUpdatesFilter.expectFlow(bot, initRequest, errorFactory) { update ->
|
): 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>() }
|
val mapped = mediaGroup.mapNotNull { it.withContent<T>() }
|
||||||
listOf(
|
listOf(
|
||||||
mapped
|
mapped
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.messageUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
import dev.inmo.tgbotapi.extensions.utils.passportMessageOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asPassportMessage
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.PassportMessage
|
import dev.inmo.tgbotapi.types.message.PassportMessage
|
||||||
import dev.inmo.tgbotapi.types.passport.PassportData
|
import dev.inmo.tgbotapi.types.passport.PassportData
|
||||||
@ -11,7 +10,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportEle
|
|||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias PassportMessageMapper = suspend PassportMessage.() -> PassportData
|
typealias PassportMessageMapper = suspend PassportMessage.() -> PassportData
|
||||||
|
|
||||||
@ -23,7 +21,7 @@ suspend inline fun <reified O : EncryptedPassportElement> BehaviourContext.waitP
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asMessageUpdate() ?.data ?.asPassportMessage() ?.passportData ?.data ?.filterIsInstance<O>() ?: emptyList()
|
it.messageUpdateOrNull() ?.data ?.passportMessageOrNull() ?.passportData ?.data ?.filterIsInstance<O>() ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitAnyPassportMessages(
|
suspend fun BehaviourContext.waitAnyPassportMessages(
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.pollAnswerUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asPollAnswerUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias PollAnswerMapper = suspend PollAnswer.() -> PollAnswer?
|
typealias PollAnswerMapper = suspend PollAnswer.() -> PollAnswer?
|
||||||
|
|
||||||
@ -19,5 +15,5 @@ suspend fun BehaviourContext.waitPollAnswers(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asPollAnswerUpdate() ?.data.let(::listOfNotNull)
|
it.pollAnswerUpdateOrNull() ?.data.let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.pollUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asPollUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.polls.*
|
import dev.inmo.tgbotapi.types.polls.*
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias PollMapper<T> = suspend T.() -> T?
|
typealias PollMapper<T> = suspend T.() -> T?
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ suspend inline fun <reified O : Poll> BehaviourContext.waitPolls(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asPollUpdate() ?.data as? O).let(::listOfNotNull)
|
(it.pollUpdateOrNull() ?.data as? O).let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.preCheckoutQueryUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asPreCheckoutQueryUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias PreCheckoutQueryMapper = suspend PreCheckoutQuery.() -> PreCheckoutQuery?
|
typealias PreCheckoutQueryMapper = suspend PreCheckoutQuery.() -> PreCheckoutQuery?
|
||||||
|
|
||||||
@ -19,5 +15,5 @@ suspend fun BehaviourContext.waitPreCheckoutQueries(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
it.asPreCheckoutQueryUpdate() ?.data.let(::listOfNotNull)
|
it.preCheckoutQueryUpdateOrNull() ?.data.let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.utils.shippingQueryUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asShippingQueryUpdate
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.toList
|
|
||||||
|
|
||||||
typealias ShippingQueryMapper = suspend ShippingQuery.() -> ShippingQuery?
|
typealias ShippingQueryMapper = suspend ShippingQuery.() -> ShippingQuery?
|
||||||
|
|
||||||
@ -17,5 +15,5 @@ suspend fun BehaviourContext.waitShippingQueries(
|
|||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
(it.asShippingQueryUpdate() ?.data).let(::listOfNotNull)
|
(it.shippingQueryUpdateOrNull() ?.data).let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.filters
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
|
||||||
import dev.inmo.tgbotapi.types.queries.callback.CallbackQuery
|
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
|
||||||
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||||
|
import dev.inmo.tgbotapi.types.queries.callback.CallbackQuery
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,10 +6,11 @@ import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
|||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CallbackQueryFilterByUser
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserCallbackQueryMarkerFactory
|
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.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.callbackQueryUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.types.queries.callback.*
|
import dev.inmo.tgbotapi.types.queries.callback.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@ -20,7 +21,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : CallbackQuery> B
|
|||||||
markerFactory: MarkerFactory<in T, Any> = ByUserCallbackQueryMarkerFactory,
|
markerFactory: MarkerFactory<in T, Any> = ByUserCallbackQueryMarkerFactory,
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = 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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatChatJoinRequestMarkerFactory
|
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.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.chat.ChatJoinRequest
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
@ -29,5 +29,5 @@ suspend fun <BC : BehaviourContext> BC.onChatJoinRequest(
|
|||||||
markerFactory: MarkerFactory<in ChatJoinRequest, Any> = ByChatChatJoinRequestMarkerFactory,
|
markerFactory: MarkerFactory<in ChatJoinRequest, Any> = ByChatChatJoinRequestMarkerFactory,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatJoinRequest>
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatJoinRequest>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = 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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserIdChosenInlineResultMarkerFactory
|
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.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.InlineQueries.ChosenInlineResult.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
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,
|
markerFactory: MarkerFactory<in T, Any> = ByUserIdChosenInlineResultMarkerFactory,
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||||
(it.asChosenInlineResultUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
(it.chosenInlineResultUpdateOrNull() ?.data as? T) ?.let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,9 +10,8 @@ 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.ByChatMessageMarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
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.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.extensions.utils.extensions.parseCommandsWithParams
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
@ -35,7 +34,7 @@ internal suspend fun <BC : BehaviourContext> BC.commandUncounted(
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
sizeRequirement && textSources.any {
|
sizeRequirement && textSources.any {
|
||||||
commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false)
|
commandRegex.matches(it.botCommandTextSourceOrNull() ?.command ?: return@any false)
|
||||||
}
|
}
|
||||||
}.let {
|
}.let {
|
||||||
initialFilter ?.times(it) ?: it
|
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.ByChatMessageMarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
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.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.extensions.utils.extensions.parseCommandsWithParams
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
import dev.inmo.tgbotapi.types.message.content.TextMessage
|
||||||
@ -33,7 +33,7 @@ suspend fun <BC : BehaviourContext> BC.unhandledCommand(
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
sizeRequirement && textSources.any {
|
sizeRequirement && textSources.any {
|
||||||
val command = it.asBotCommandTextSource() ?.command ?: return@any false
|
val command = it.botCommandTextSourceOrNull() ?.command ?: return@any false
|
||||||
!triggersHolder.handleableCommandsHolder.isHandled(command)
|
!triggersHolder.handleableCommandsHolder.isHandled(command)
|
||||||
}
|
}
|
||||||
}.let {
|
}.let {
|
||||||
|
@ -12,12 +12,9 @@ import dev.inmo.tgbotapi.extensions.utils.whenCommonMessage
|
|||||||
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
import dev.inmo.tgbotapi.types.update.media_group.SentMediaGroupUpdate
|
||||||
|
|
||||||
typealias CommonMessageFilter<T> = SimpleFilter<CommonMessage<T>>
|
typealias CommonMessageFilter<T> = SimpleFilter<CommonMessage<T>>
|
||||||
|
|
||||||
|
@ -20,17 +20,11 @@ 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.filters.MessageFilterByChat
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
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.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.extensions.utils.withContent
|
||||||
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaCollectionContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
@ -41,7 +35,7 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MessageContent>
|
|||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is BaseEditMessageUpdate -> (it.asEditMessageUpdate() ?.data ?.withContent<T>())
|
is BaseEditMessageUpdate -> (it.editMessageUpdateOrNull() ?.data ?.withContent<T>())
|
||||||
else -> null
|
else -> null
|
||||||
} ?.let(::listOfNotNull)
|
} ?.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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
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.marker_factories.MarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate
|
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage
|
import dev.inmo.tgbotapi.extensions.utils.chatEventMessageOrNull
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
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>>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<T>>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserInlineQueryMarkerFactory
|
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.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.InlineQueries.query.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
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,
|
markerFactory: MarkerFactory<in T, Any> = ByUserInlineQueryMarkerFactory,
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||||
(it.asInlineQueryUpdate() ?.data as? T) ?.let(::listOfNotNull)
|
(it.inlineQueryUpdateOrNull() ?.data as? T) ?.let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.*
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||||
|
@ -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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMediaGroupMarkerFactory
|
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.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.abstracts.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
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,
|
markerFactory: MarkerFactory<in List<MediaGroupMessage<T>>, Any> = ByChatMediaGroupMarkerFactory,
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<T>>>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<T>>>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||||
(it.asSentMediaGroupUpdate() ?.data ?.takeIf { messages ->
|
(it.sentMediaGroupUpdateOrNull() ?.data ?.takeIf { messages ->
|
||||||
messages.all { message ->
|
messages.all { message ->
|
||||||
message.content is T
|
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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
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.marker_factories.MarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
import dev.inmo.tgbotapi.extensions.utils.messageUpdateOrNull
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asPassportMessage
|
import dev.inmo.tgbotapi.extensions.utils.passportMessageOrNull
|
||||||
import dev.inmo.tgbotapi.types.message.PassportMessage
|
import dev.inmo.tgbotapi.types.message.PassportMessage
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
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,
|
markerFactory: MarkerFactory<in PassportMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PassportMessage>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PassportMessage>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = 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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByIdPollAnswerMarkerFactory
|
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.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.polls.PollAnswer
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
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,
|
markerFactory: MarkerFactory<in PollAnswer, Any> = ByIdPollAnswerMarkerFactory,
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PollAnswer>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PollAnswer>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = 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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByIdPollMarkerFactory
|
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.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.polls.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
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,
|
markerFactory: MarkerFactory<in T, Any> = ByIdPollMarkerFactory,
|
||||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, T>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = 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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserPreCheckoutQueryMarkerFactory
|
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.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.payments.PreCheckoutQuery
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
@ -31,5 +31,5 @@ suspend fun <BC : BehaviourContext> BC.onPreCheckoutQuery(
|
|||||||
markerFactory: MarkerFactory<in PreCheckoutQuery, Any> = ByUserPreCheckoutQueryMarkerFactory,
|
markerFactory: MarkerFactory<in PreCheckoutQuery, Any> = ByUserPreCheckoutQueryMarkerFactory,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PreCheckoutQuery>
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PreCheckoutQuery>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = 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.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserShippingQueryMarkerFactory
|
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.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.payments.ShippingQuery
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
@ -31,5 +31,5 @@ suspend fun <BC : BehaviourContext> BC.onShippingQuery(
|
|||||||
markerFactory: MarkerFactory<in ShippingQuery, Any> = ByUserShippingQueryMarkerFactory,
|
markerFactory: MarkerFactory<in ShippingQuery, Any> = ByUserShippingQueryMarkerFactory,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ShippingQuery>
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ShippingQuery>
|
||||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||||
(it.asShippingQueryUpdate() ?.data) ?.let(::listOfNotNull)
|
(it.shippingQueryUpdateOrNull() ?.data) ?.let(::listOfNotNull)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocation
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocationMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitEditedLocationMessage
|
||||||
import dev.inmo.tgbotapi.types.location.*
|
import dev.inmo.tgbotapi.types.location.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.queries.callback.CallbackQuery
|
|
||||||
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
||||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||||
|
import dev.inmo.tgbotapi.types.queries.callback.CallbackQuery
|
||||||
|
|
||||||
object ByUserCallbackQueryMarkerFactory : MarkerFactory<CallbackQuery, Any> {
|
object ByUserCallbackQueryMarkerFactory : MarkerFactory<CallbackQuery, Any> {
|
||||||
override suspend fun invoke(data: CallbackQuery) = data.user
|
override suspend fun invoke(data: CallbackQuery) = data.user
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
id "org.jetbrains.kotlin.plugin.serialization"
|
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"
|
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.microutils.languageCodes
|
||||||
|
|
||||||
api libs.ktor.client.core
|
api libs.ktor.client.core
|
||||||
|
|
||||||
|
api project(":tgbotapi.ksp:lib")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commonTest {
|
commonTest {
|
||||||
@ -46,12 +49,15 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// targets.all {
|
|
||||||
// compilations.all {
|
dependencies {
|
||||||
// kotlinOptions {
|
add("kspCommonMainMetadata", project(":tgbotapi.ksp:processor"))
|
||||||
// freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", "-Xopt-in=kotlin.RequiresOptIn"]
|
add("kspJvm", project(":tgbotapi.ksp:processor"))
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
ksp {
|
||||||
|
arg("cctargetPackage", "dev.inmo.tgbotapi.extensions.utils")
|
||||||
|
arg("ccoutputFileName", "ClassCastsNew")
|
||||||
|
arg("ccoutputFolder", project(":tgbotapi.utils").file("src/commonMain/kotlin").absolutePath)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package dev.inmo.tgbotapi.abstracts
|
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.Currencied
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Priced
|
import dev.inmo.tgbotapi.types.payments.abstracts.Priced
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
interface CommonSendInvoiceData : Titled, Currencied, Priced {
|
interface CommonSendInvoiceData : Titled, Currencied, Priced {
|
||||||
val description: String
|
val description: String
|
||||||
val payload: String
|
val payload: String
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.abstracts
|
package dev.inmo.tgbotapi.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.chat.User
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,6 +8,7 @@ import dev.inmo.tgbotapi.types.chat.User
|
|||||||
*
|
*
|
||||||
* @see FromUser
|
* @see FromUser
|
||||||
*/
|
*/
|
||||||
|
@ClassCastsIncluded
|
||||||
interface WithUser {
|
interface WithUser {
|
||||||
val user: User
|
val user: User
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.abstracts.types
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
|
||||||
|
|
||||||
interface ReplyMarkup {
|
|
||||||
val replyMarkup: KeyboardMarkup?
|
|
||||||
}
|
|
@ -0,0 +1,9 @@
|
|||||||
|
package dev.inmo.tgbotapi.abstracts.types
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
|
|
||||||
|
interface WithReplyMarkup {
|
||||||
|
val replyMarkup: KeyboardMarkup?
|
||||||
|
}
|
||||||
|
@Deprecated("Renamed", ReplaceWith("WithReplyMarkup", "dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup"))
|
||||||
|
typealias ReplyMarkup = WithReplyMarkup
|
@ -1,7 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.requests
|
package dev.inmo.tgbotapi.requests
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.types.MessageAction
|
import dev.inmo.tgbotapi.abstracts.types.MessageAction
|
||||||
import dev.inmo.tgbotapi.abstracts.types.ReplyMarkup
|
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
@ -17,7 +17,7 @@ data class StopPoll(
|
|||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||||
) : MessageAction, SimpleRequest<Poll>, ReplyMarkup {
|
) : MessageAction, SimpleRequest<Poll>, WithReplyMarkup {
|
||||||
override fun method(): String = "stopPoll"
|
override fun method(): String = "stopPoll"
|
||||||
override val resultDeserializer: DeserializationStrategy<Poll>
|
override val resultDeserializer: DeserializationStrategy<Poll>
|
||||||
get() = PollSerializer
|
get() = PollSerializer
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.requests.edit.abstracts
|
package dev.inmo.tgbotapi.requests.edit.abstracts
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.types.ReplyMarkup
|
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
|
|
||||||
interface EditReplyMessage : ReplyMarkup {
|
interface EditReplyMessage : WithReplyMarkup {
|
||||||
override val replyMarkup: InlineKeyboardMarkup?
|
override val replyMarkup: InlineKeyboardMarkup?
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,9 @@ import kotlinx.serialization.*
|
|||||||
|
|
||||||
const val OrderChangingDeprecationWarn = "The order of parameters in this factory will be changed soon. To avoid unexpected behaviour, swap message id and target chat id parameters"
|
const val OrderChangingDeprecationWarn = "The order of parameters in this factory will be changed soon. To avoid unexpected behaviour, swap message id and target chat id parameters"
|
||||||
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
fun CopyMessage(
|
fun CopyMessage(
|
||||||
fromChatId: ChatIdentifier,
|
|
||||||
toChatId: ChatIdentifier,
|
toChatId: ChatIdentifier,
|
||||||
|
fromChatId: ChatIdentifier,
|
||||||
messageId: MessageIdentifier,
|
messageId: MessageIdentifier,
|
||||||
text: String? = null,
|
text: String? = null,
|
||||||
parseMode: ParseMode? = null,
|
parseMode: ParseMode? = null,
|
||||||
@ -46,10 +45,9 @@ fun CopyMessage(
|
|||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
@Deprecated(OrderChangingDeprecationWarn)
|
|
||||||
fun CopyMessage(
|
fun CopyMessage(
|
||||||
fromChatId: ChatIdentifier,
|
|
||||||
toChatId: ChatIdentifier,
|
toChatId: ChatIdentifier,
|
||||||
|
fromChatId: ChatIdentifier,
|
||||||
messageId: MessageIdentifier,
|
messageId: MessageIdentifier,
|
||||||
entities: List<TextSource>,
|
entities: List<TextSource>,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package dev.inmo.tgbotapi.requests.send.abstracts
|
package dev.inmo.tgbotapi.requests.send.abstracts
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.types.ReplyMarkup
|
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
|
||||||
|
|
||||||
interface ReplyingMarkupSendMessageRequest<T: Any>: SendMessageRequest<T>, ReplyMarkup
|
interface ReplyingMarkupSendMessageRequest<T: Any>: SendMessageRequest<T>, WithReplyMarkup
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.requests.send.games
|
package dev.inmo.tgbotapi.requests.send.games
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.types.ReplyMarkup
|
import dev.inmo.tgbotapi.abstracts.types.WithReplyMarkup
|
||||||
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
|
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
@ -29,7 +29,7 @@ data class SendGame (
|
|||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: KeyboardMarkup? = null
|
override val replyMarkup: KeyboardMarkup? = null
|
||||||
) : SendMessageRequest<ContentMessage<GameContent>>,
|
) : SendMessageRequest<ContentMessage<GameContent>>,
|
||||||
ReplyMarkup {
|
WithReplyMarkup {
|
||||||
override fun method(): String = "sendGame"
|
override fun method(): String = "sendGame"
|
||||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<GameContent>>
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<GameContent>>
|
||||||
get() = commonResultDeserializer
|
get() = commonResultDeserializer
|
||||||
|
@ -72,7 +72,7 @@ data class SendInvoice(
|
|||||||
ChatRequest,
|
ChatRequest,
|
||||||
DisableNotification,
|
DisableNotification,
|
||||||
ReplyMessageId,
|
ReplyMessageId,
|
||||||
ReplyMarkup,
|
WithReplyMarkup,
|
||||||
SendMessageRequest<ContentMessage<InvoiceContent>> {
|
SendMessageRequest<ContentMessage<InvoiceContent>> {
|
||||||
override fun method(): String = "sendInvoice"
|
override fun method(): String = "sendInvoice"
|
||||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
||||||
|
@ -39,19 +39,6 @@ val UserId.userLink: String
|
|||||||
val User.link: String
|
val User.link: String
|
||||||
get() = id.userLink
|
get() = id.userLink
|
||||||
|
|
||||||
/**
|
|
||||||
* https://core.telegram.org/bots/api#formatting-options
|
|
||||||
*/
|
|
||||||
@Deprecated("Renamed", ReplaceWith("userLink", "dev.inmo.tgbotapi.types.userLink"))
|
|
||||||
val Identifier.link: String
|
|
||||||
get() = "tg://user?id=$this"
|
|
||||||
/**
|
|
||||||
* https://core.telegram.org/bots/api#formatting-options
|
|
||||||
*/
|
|
||||||
@Deprecated("Renamed", ReplaceWith("userLink", "dev.inmo.tgbotapi.types.userLink"))
|
|
||||||
val ChatId.link: String
|
|
||||||
get() = chatId.link
|
|
||||||
|
|
||||||
typealias UserId = ChatId
|
typealias UserId = ChatId
|
||||||
|
|
||||||
fun Identifier.toChatId(): ChatId = ChatId(this)
|
fun Identifier.toChatId(): ChatId = ChatId(this)
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts
|
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.InlineQueries.InlineQueryResult.serializers.InlineQueryResultSerializer
|
||||||
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
|
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable(InlineQueryResultSerializer::class)
|
@Serializable(InlineQueryResultSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
interface InlineQueryResult {
|
interface InlineQueryResult {
|
||||||
val type: String
|
val type: String
|
||||||
val id: InlineQueryIdentifier
|
val id: InlineQueryIdentifier
|
||||||
val replyMarkup: InlineKeyboardMarkup?
|
val replyMarkup: InlineKeyboardMarkup?
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
|
package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContentSerializer
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContentSerializer
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable(InputMessageContentSerializer::class)
|
@Serializable(InputMessageContentSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface InputMessageContent
|
sealed interface InputMessageContent
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.types.actions
|
package dev.inmo.tgbotapi.types.actions
|
||||||
|
|
||||||
import dev.inmo.micro_utils.common.Warning
|
import dev.inmo.micro_utils.common.Warning
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -13,6 +14,7 @@ import kotlinx.serialization.encoding.Encoder
|
|||||||
* Use BotAction objects realisations to notify user about bot actions
|
* Use BotAction objects realisations to notify user about bot actions
|
||||||
*/
|
*/
|
||||||
@Serializable(BotActionSerializer::class)
|
@Serializable(BotActionSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface BotAction {
|
sealed interface BotAction {
|
||||||
val actionName: String
|
val actionName: String
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons
|
package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.games.CallbackGame
|
import dev.inmo.tgbotapi.types.games.CallbackGame
|
||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
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
|
* https://core.telegram.org/bots/api#inlinekeyboardbutton for more info
|
||||||
*/
|
*/
|
||||||
@Serializable(InlineKeyboardButtonSerializer::class)
|
@Serializable(InlineKeyboardButtonSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface InlineKeyboardButton {
|
sealed interface InlineKeyboardButton {
|
||||||
val text: String
|
val text: String
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.types.buttons
|
package dev.inmo.tgbotapi.types.buttons
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable(KeyboardMarkupSerializer::class)
|
@Serializable(KeyboardMarkupSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface KeyboardMarkup
|
sealed interface KeyboardMarkup
|
||||||
|
@ -19,15 +19,6 @@ data class ReplyForce(
|
|||||||
val Selective = Selective()
|
val Selective = Selective()
|
||||||
val NonSelective = NonSelective()
|
val NonSelective = NonSelective()
|
||||||
val Default = ReplyForce()
|
val Default = ReplyForce()
|
||||||
|
|
||||||
@Deprecated("Renamed", ReplaceWith("ReplyForce.Selective"))
|
|
||||||
inline val ReplyForceSelective
|
|
||||||
get() = Selective
|
|
||||||
@Deprecated("Renamed", ReplaceWith("ReplyForce.NonSelective"))
|
|
||||||
inline val ReplyForceNonSelective
|
|
||||||
get() = NonSelective
|
|
||||||
@Deprecated("Renamed", ReplaceWith("ReplyForce.Default"))
|
|
||||||
val ReplyForceDefault = ReplyForce()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.chat
|
package dev.inmo.tgbotapi.types.chat
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ sealed interface AbleToAddInAttachmentMenuChat : Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializable(PreviewChatSerializer::class)
|
@Serializable(PreviewChatSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface Chat {
|
sealed interface Chat {
|
||||||
val id: ChatId
|
val id: ChatId
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,3 @@ data class OwnerChatMember(
|
|||||||
@Required
|
@Required
|
||||||
private val type: String = "creator"
|
private val type: String = "creator"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Renamed", ReplaceWith("OwnerChatMember", "dev.inmo.tgbotapi.types.chat.member.OwnerChatMember"))
|
|
||||||
typealias CreatorChatMember = OwnerChatMember
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.dice
|
package dev.inmo.tgbotapi.types.dice
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
@ -9,6 +10,7 @@ import kotlinx.serialization.encoding.Decoder
|
|||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
@Serializable(DiceAnimationTypeSerializer::class)
|
@Serializable(DiceAnimationTypeSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface DiceAnimationType {
|
sealed interface DiceAnimationType {
|
||||||
val emoji: String
|
val emoji: String
|
||||||
val valueLimits: IntRange
|
val valueLimits: IntRange
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package dev.inmo.tgbotapi.types.files
|
package dev.inmo.tgbotapi.types.files
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
import dev.inmo.tgbotapi.types.FileUniqueId
|
import dev.inmo.tgbotapi.types.FileUniqueId
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare common part of media files in Telegram. Note: it is not representation of JVM `File` type
|
* Declare common part of media files in Telegram. Note: it is not representation of JVM `File` type
|
||||||
*/
|
*/
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface TelegramMediaFile {
|
sealed interface TelegramMediaFile {
|
||||||
val fileId: FileId
|
val fileId: FileId
|
||||||
val fileUniqueId: FileUniqueId
|
val fileUniqueId: FileUniqueId
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.types.location
|
package dev.inmo.tgbotapi.types.location
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.*
|
import dev.inmo.tgbotapi.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
@ -18,6 +19,7 @@ import kotlinx.serialization.json.JsonObject
|
|||||||
* @see dev.inmo.tgbotapi.extensions.utils.asLiveLocation
|
* @see dev.inmo.tgbotapi.extensions.utils.asLiveLocation
|
||||||
*/
|
*/
|
||||||
@Serializable(LocationSerializer::class)
|
@Serializable(LocationSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface Location : Locationed, HorizontallyAccured
|
sealed interface Location : Locationed, HorizontallyAccured
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package dev.inmo.tgbotapi.types.media
|
package dev.inmo.tgbotapi.types.media
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.InputFile
|
import dev.inmo.tgbotapi.requests.abstracts.InputFile
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable(TelegramMediaSerializer::class)
|
@Serializable(TelegramMediaSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface TelegramMedia {
|
sealed interface TelegramMedia {
|
||||||
val type: String
|
val type: String
|
||||||
val file: InputFile
|
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.chat.User
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
|
||||||
|
|
||||||
data class LeftChatMember(
|
data class LeftChatMemberEvent(
|
||||||
override val user: User
|
override val user: User
|
||||||
) : PublicChatEvent, WithUser
|
) : 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
|
package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
interface ChatEvent
|
interface ChatEvent
|
||||||
|
@ -1,42 +1,74 @@
|
|||||||
package dev.inmo.tgbotapi.types.message
|
package dev.inmo.tgbotapi.types.message
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.chat.*
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
import dev.inmo.tgbotapi.types.chat.User
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
|
||||||
sealed class ForwardInfo {
|
@ClassCastsIncluded
|
||||||
|
sealed interface ForwardInfo {
|
||||||
abstract val dateOfOriginal: TelegramDate
|
abstract val dateOfOriginal: TelegramDate
|
||||||
|
|
||||||
|
data class ByAnonymous(
|
||||||
|
override val dateOfOriginal: TelegramDate,
|
||||||
|
val senderName: String
|
||||||
|
) : ForwardInfo
|
||||||
|
|
||||||
|
data class ByUser(
|
||||||
|
override val dateOfOriginal: TelegramDate,
|
||||||
|
override val from: User
|
||||||
|
) : ForwardInfo, FromUser
|
||||||
|
|
||||||
|
sealed interface PublicChat : ForwardInfo {
|
||||||
|
val chat: dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represent forward info for the message sent by [channelChat] into some group
|
||||||
|
*/
|
||||||
|
data class SentByChannel(
|
||||||
|
override val dateOfOriginal: TelegramDate,
|
||||||
|
val channelChat: ChannelChat,
|
||||||
|
val signature: String? = null
|
||||||
|
) : PublicChat {
|
||||||
|
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
get() = channelChat
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represent forward info for the message sent by [channelChat] into that channel
|
||||||
|
*/
|
||||||
|
data class FromChannel(
|
||||||
|
override val dateOfOriginal: TelegramDate,
|
||||||
|
val messageId: MessageIdentifier,
|
||||||
|
val channelChat: ChannelChat,
|
||||||
|
val signature: String? = null
|
||||||
|
) : PublicChat {
|
||||||
|
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
get() = channelChat
|
||||||
|
}
|
||||||
|
|
||||||
|
data class FromSupergroup(
|
||||||
|
override val dateOfOriginal: TelegramDate,
|
||||||
|
val group: SupergroupChat
|
||||||
|
) : PublicChat {
|
||||||
|
override val chat: dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
get() = group
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class AnonymousForwardInfo(
|
@Deprecated("Replaced", ReplaceWith("ForwardInfo.ByAnonymous", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
|
||||||
override val dateOfOriginal: TelegramDate,
|
typealias AnonymousForwardInfo = ForwardInfo.ByAnonymous
|
||||||
val senderName: String
|
|
||||||
) : ForwardInfo()
|
|
||||||
|
|
||||||
data class UserForwardInfo(
|
@Deprecated("Replaced", ReplaceWith("ForwardInfo.ByUser", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
|
||||||
override val dateOfOriginal: TelegramDate,
|
typealias UserForwardInfo = ForwardInfo.ByUser
|
||||||
override val from: User
|
|
||||||
) : ForwardInfo(), FromUser
|
|
||||||
|
|
||||||
sealed class ForwardFromPublicChatInfo : ForwardInfo() {
|
@Deprecated("Replaced", ReplaceWith("ForwardInfo.PublicChat", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
|
||||||
abstract val chat: PublicChat
|
typealias ForwardFromPublicChatInfo = ForwardInfo.PublicChat
|
||||||
}
|
|
||||||
|
|
||||||
data class ForwardFromChannelInfo(
|
@Deprecated("Replaced", ReplaceWith("ForwardInfo.PublicChat.FromChannel", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
|
||||||
override val dateOfOriginal: TelegramDate,
|
typealias ForwardFromChannelInfo = ForwardInfo.PublicChat.FromChannel
|
||||||
val messageId: MessageIdentifier,
|
|
||||||
val channelChat: ChannelChat,
|
|
||||||
val signature: String? = null
|
|
||||||
) : ForwardFromPublicChatInfo() {
|
|
||||||
override val chat: PublicChat
|
|
||||||
get() = channelChat
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ForwardFromSupergroupInfo(
|
@Deprecated("Replaced", ReplaceWith("ForwardInfo.PublicChat.FromSupergroup", "dev.inmo.tgbotapi.types.message.ForwardInfo"))
|
||||||
override val dateOfOriginal: TelegramDate,
|
typealias ForwardFromSupergroupInfo = ForwardInfo.PublicChat.FromSupergroup
|
||||||
val group: SupergroupChat
|
|
||||||
) : ForwardFromPublicChatInfo() {
|
|
||||||
override val chat: PublicChat
|
|
||||||
get() = group
|
|
||||||
}
|
|
||||||
|
@ -156,26 +156,39 @@ internal data class RawMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val forwarded: ForwardInfo? by lazy {
|
private val forwarded: ForwardInfo? by lazy {
|
||||||
forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field
|
forward_date
|
||||||
|
?: return@lazy null // According to the documentation, now any forwarded message contains this field
|
||||||
when {
|
when {
|
||||||
forward_sender_name != null -> AnonymousForwardInfo(
|
forward_sender_name != null -> ForwardInfo.ByAnonymous(
|
||||||
forward_date,
|
forward_date,
|
||||||
forward_sender_name
|
forward_sender_name
|
||||||
)
|
)
|
||||||
forward_from_chat is ChannelChat -> ForwardFromChannelInfo(
|
|
||||||
forward_date,
|
forward_from_chat is ChannelChat -> if (forward_from_message_id == null) {
|
||||||
forward_from_message_id ?: error("Channel forwarded message must contain message id, but was not"),
|
ForwardInfo.PublicChat.SentByChannel(
|
||||||
forward_from_chat,
|
forward_date,
|
||||||
forward_signature
|
forward_from_chat,
|
||||||
)
|
forward_signature
|
||||||
forward_from_chat is SupergroupChat -> ForwardFromSupergroupInfo(
|
)
|
||||||
|
} else {
|
||||||
|
ForwardInfo.PublicChat.FromChannel(
|
||||||
|
forward_date,
|
||||||
|
forward_from_message_id,
|
||||||
|
forward_from_chat,
|
||||||
|
forward_signature
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_from_chat is SupergroupChat -> ForwardInfo.PublicChat.FromSupergroup(
|
||||||
forward_date,
|
forward_date,
|
||||||
forward_from_chat
|
forward_from_chat
|
||||||
)
|
)
|
||||||
forward_from != null -> UserForwardInfo(
|
|
||||||
|
forward_from != null -> ForwardInfo.ByUser(
|
||||||
forward_date,
|
forward_date,
|
||||||
forward_from
|
forward_from
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.abstracts
|
package dev.inmo.tgbotapi.types.message.abstracts
|
||||||
|
|
||||||
import com.soywiz.klock.DateTime
|
import com.soywiz.klock.DateTime
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.message.RawMessage
|
import dev.inmo.tgbotapi.types.message.RawMessage
|
||||||
@ -9,6 +10,7 @@ import kotlinx.serialization.descriptors.*
|
|||||||
import kotlinx.serialization.encoding.Decoder
|
import kotlinx.serialization.encoding.Decoder
|
||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
interface Message {
|
interface Message {
|
||||||
val messageId: MessageIdentifier
|
val messageId: MessageIdentifier
|
||||||
val chat: Chat
|
val chat: Chat
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content
|
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.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
@ -108,6 +109,7 @@ sealed interface MediaContent: MessageContent {
|
|||||||
fun asTelegramMedia(): TelegramMedia
|
fun asTelegramMedia(): TelegramMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface ResendableContent {
|
sealed interface ResendableContent {
|
||||||
fun createResend(
|
fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.textsources
|
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.captionLength
|
||||||
import dev.inmo.tgbotapi.types.textLength
|
import dev.inmo.tgbotapi.types.textLength
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -10,6 +11,7 @@ typealias TextSourcesList = List<TextSource>
|
|||||||
typealias MutableTextSourcesList = MutableList<TextSource>
|
typealias MutableTextSourcesList = MutableList<TextSource>
|
||||||
|
|
||||||
@Serializable(TextSourceSerializer::class)
|
@Serializable(TextSourceSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface TextSource {
|
sealed interface TextSource {
|
||||||
val markdown: String
|
val markdown: String
|
||||||
val markdownV2: 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.crypto.md5
|
import dev.inmo.micro_utils.crypto.md5
|
||||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
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.*
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.*
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.type
|
import dev.inmo.tgbotapi.types.passport.encrypted.type
|
||||||
@ -18,6 +19,7 @@ import kotlinx.serialization.json.*
|
|||||||
val ByteArray.passportFileHash: MD5
|
val ByteArray.passportFileHash: MD5
|
||||||
get() = md5()
|
get() = md5()
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
@Serializable(PassportElementErrorSerializer::class)
|
@Serializable(PassportElementErrorSerializer::class)
|
||||||
sealed class PassportElementError {
|
sealed class PassportElementError {
|
||||||
abstract val source: String
|
abstract val source: String
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
|
package dev.inmo.tgbotapi.types.passport.decrypted.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
interface SecureValue {
|
interface SecureValue {
|
||||||
val credentials: List<EndDataCredentials>
|
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.crypto.SourceBytes
|
||||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer
|
import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
@ -9,6 +10,7 @@ import kotlinx.serialization.json.JsonObject
|
|||||||
typealias PassportElementHash = SourceBytes
|
typealias PassportElementHash = SourceBytes
|
||||||
|
|
||||||
@Serializable(EncryptedElementSerializer::class)
|
@Serializable(EncryptedElementSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
interface EncryptedPassportElement {
|
interface EncryptedPassportElement {
|
||||||
val hash: PassportElementHash
|
val hash: PassportElementHash
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.polls
|
|||||||
import com.soywiz.klock.DateTime
|
import com.soywiz.klock.DateTime
|
||||||
import com.soywiz.klock.TimeSpan
|
import com.soywiz.klock.TimeSpan
|
||||||
import dev.inmo.tgbotapi.abstracts.TextedInput
|
import dev.inmo.tgbotapi.abstracts.TextedInput
|
||||||
|
import dev.inmo.tgbotapi.ksp.lib.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.message.*
|
import dev.inmo.tgbotapi.types.message.*
|
||||||
import dev.inmo.tgbotapi.types.message.RawMessageEntity
|
import dev.inmo.tgbotapi.types.message.RawMessageEntity
|
||||||
@ -16,6 +17,7 @@ import kotlinx.serialization.encoding.Decoder
|
|||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface ScheduledCloseInfo {
|
sealed interface ScheduledCloseInfo {
|
||||||
val closeDateTime: DateTime
|
val closeDateTime: DateTime
|
||||||
}
|
}
|
||||||
@ -45,6 +47,7 @@ val LongSeconds.asExactScheduledCloseInfo
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Serializable(PollSerializer::class)
|
@Serializable(PollSerializer::class)
|
||||||
|
@ClassCastsIncluded
|
||||||
sealed interface Poll {
|
sealed interface Poll {
|
||||||
val id: PollIdentifier
|
val id: PollIdentifier
|
||||||
val question: String
|
val question: String
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.update.abstracts
|
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.UpdateIdentifier
|
||||||
import dev.inmo.tgbotapi.types.update.RawUpdate
|
import dev.inmo.tgbotapi.types.update.RawUpdate
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
@ -10,6 +11,7 @@ import kotlinx.serialization.encoding.Decoder
|
|||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
|
||||||
|
@ClassCastsIncluded
|
||||||
interface Update {
|
interface Update {
|
||||||
val updateId: UpdateIdentifier
|
val updateId: UpdateIdentifier
|
||||||
val data: Any
|
val data: Any
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.utils.internal
|
package dev.inmo.tgbotapi.utils.internal
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.MultilevelTextSource
|
import dev.inmo.tgbotapi.types.message.textsources.MultilevelTextSource
|
||||||
import dev.inmo.tgbotapi.types.UserId
|
|
||||||
import dev.inmo.tgbotapi.types.link
|
|
||||||
import dev.inmo.tgbotapi.utils.extensions.*
|
import dev.inmo.tgbotapi.utils.extensions.*
|
||||||
|
|
||||||
internal fun MultilevelTextSource.markdownV2Default(
|
internal fun MultilevelTextSource.markdownV2Default(
|
||||||
@ -61,8 +60,8 @@ internal fun MultilevelTextSource.underlineMarkdownV2(): String = markdownV2Defa
|
|||||||
internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.userLink)
|
||||||
internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
|
internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.userLink)
|
||||||
|
|
||||||
internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + subsources.makeMarkdownV2String()
|
internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + subsources.makeMarkdownV2String()
|
||||||
internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + subsources.makeHtmlString()
|
internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + subsources.makeHtmlString()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.utils.internal
|
package dev.inmo.tgbotapi.utils.internal
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.UserId
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.link
|
|
||||||
import dev.inmo.tgbotapi.types.message.*
|
import dev.inmo.tgbotapi.types.message.*
|
||||||
import dev.inmo.tgbotapi.utils.extensions.*
|
import dev.inmo.tgbotapi.utils.extensions.*
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ private inline fun String.hashTag(adapt: String.() -> String): String = if (star
|
|||||||
"#${adapt()}"
|
"#${adapt()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.userLink)
|
||||||
|
|
||||||
internal fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
internal fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
||||||
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.requests.abstracts
|
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
@Deprecated("Duplacation of asMultipartFile", ReplaceWith("asMultipartFile", "dev.inmo.tgbotapi.requests.abstracts.asMultipartFile"))
|
|
||||||
fun File.toInputFile() = asMultipartFile()
|
|
7
tgbotapi.ksp/lib/build.gradle
Normal file
7
tgbotapi.ksp/lib/build.gradle
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
}
|
||||||
|
|
||||||
|
project.description = "Class Casts generator KSP library to include into your library"
|
||||||
|
|
||||||
|
apply from: "$mppProjectWithSerializationPresetPath"
|
@ -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,77 @@
|
|||||||
|
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.AnnotationSpec
|
||||||
|
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 {
|
||||||
|
addAnnotation(
|
||||||
|
AnnotationSpec.builder(Suppress::class).apply {
|
||||||
|
addMember("\"unused\"")
|
||||||
|
addMember("\"RemoveRedundantQualifierName\"")
|
||||||
|
addMember("\"RedundantVisibilityModifier\"")
|
||||||
|
addMember("\"NOTHING_TO_INLINE\"")
|
||||||
|
addMember("\"UNCHECKED_CAST\"")
|
||||||
|
addMember("\"OPT_IN_USAGE\"")
|
||||||
|
useSiteTarget(AnnotationSpec.UseSiteTarget.FILE)
|
||||||
|
}.build()
|
||||||
|
)
|
||||||
|
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
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user