diff --git a/CHANGELOG.md b/CHANGELOG.md index 69028b1f66..f7e9277351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,93 @@ # TelegramBotAPI changelog +## 0.30.0 Bot API 5.0 + +**THIS UPDATE CONTAINS A LOT OF BREAKING CHANGES. PLEASE, BE CAREFUL ON UPGRADING OF YOUR PROJECT** + +* `Common`: + * `Version`: + * `Coroutine`: `1.4.0` -> `1.4.1` + * **NEW** `MicroUtils`: `0.2.7` +* `Core`: + * Support of `logOut` method (`LogOut` object as a `Request`) + * Support of `close` method (`Close` object as a `Request`) + * `SetWebhook` updates: + * New field `ipAddress`. It works the same as `ip_address` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) + section + * New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) + section + * New field `ExtendedPrivateChat#bio` + * New data class `ChatLocation` + * New field `UnbanChatMember#onlyIfBanned` + * New fields `ExtendedChannelChat#linkedGroupChatId` and `ExtendedSupergroupChat#linkedChannelChatId` + * New fields `ExtendedSupergroupChat#location` + * New fields `AudioFile#fileName` and `VideoFile#fileName` + * New fields `SendDocument#disableContentTypeDetection` and `InputMediaDocument#disableContentTypeDetection` + * New request `UnpinAllChatMessages` + * New parameter for `unpinChatMessage` method: `messageId` + * New dice type `FootballDiceAnimationType` + * Limits for dices has been changed + * `commonDiceResultLimit` has been deprecated + * New field `DiceAnimationType#valueLimits` + * Locations updates: + * New interface `Headed` with property `heading` + * New interface `HorizontallyAccured` with property `horizontalAccuracy` + * New interface `ProximityAlertable` with property `proximityAlertRadius` + * `Location` class has been separated: + * `StaticLocation` for static locations + * `LiveLocation` for live locations + * Property `Livable#livePeriod` now use typealias type `Seconds` (the same by meaning - `Int`) + * `EditLocationMessage` now extends `Locationed`, `HorizontallyAccured`, `ProximityAlertable` and `Headed` interfaces + * New properties in `EditChatMessageLiveLocation`: `horizontalAccuracy`, `heading`, `proximityAlertRadius` + * New properties in `EditInlineMessageLiveLocation`: `horizontalAccuracy`, `heading`, `proximityAlertRadius` + * Main constructor of `SendLocation` now is internal. Instead of that currently available next factories: + * `SendLocation` - sending of static location without live parameters + * `SendStaticLocation` - sending of static location without live parameters + * `SendLiveLocation` - sending of live location with live parameters + * `PositionedSendMessageRequest` now extends `Locationed` + * `LocationContent#createResend` now can create `LiveLocation` + * Support of `ProximityAlertTriggered`. It is `CommonEvent` + * Property `pollQuestionTextLength` now have maximum up to `300` + * Anonymous Admins: + * New field `AdministratorChatMember#isAnonymous` + * Several new interfaces of messages: + * `SignedMessage` - any message which possibly have `authorSignature` + * `WithSenderChatMessage` - any message which have `senderChat`. Property `senderChat` is not-nullable due to + separation of implementators + * `PublicMessage` - all channel messages have property `val chat: PublicChat` instead of common `val chat: Chat` + * `ChannelMessage` - all channel messages have property `val chat: ChannelChat` instead of common `val chat: Chat` + * Old `ChannelMessage` was safely renamed to `ChannelMessageImpl` (old name was set as typealias and deprecated) + * `GroupMessage` - all group messages have property `val chat: GroupChat` instead of common `val chat: Chat` + * `FromChannelGroupMessage` - instances should have property `val channel: ChannelChat` + * `AnonymousGroupMessage` - instances may have setup property `authorSignature` + * `CommonGroupMessage` - just common message + * `PrivateMessage` - works like previous `CommonMessageImpl` + * Previous `CommonMessageImpl` safely renamed to `PrivateMessageImpl` + * New property `PromoteChatMember#isAnonymous` + * Update all classes which must have `entities`/`caption_entities` fields + * New request `CopyMessage` + * New extension `List#makeString` for more comfortable work with new api with entities + * Support for Google Places identifiers for venues + * New extensions for text sources separating: + * `List#separateForMessage` + * `List#separateForCaption` + * `List#separateForText` + * Rewritten work with text sources and text parts: + * Now any `Message` type with entities will have full list of entities. That means that parts without any + formatter entities will use `RegularTextSource` + * `MultilevelTextSource#textParts` has been deprecated. Now each `MultilevelTextSource` have its own + `textSources` list + * New dsl for creating of `TextSource` lists + * Built-in `handleSafely` and `ExceptionHandler` is deprecated + * New common factories for `StorageFile` +* `API`: + * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` + * New extensions `TelegramBot#unpinAllChatMessages` + * Extensions `TelegramBot#promoteChatMember` got `isAnonymous` parameter + * All old api methods has been actualized to their analogs in `Core` + * All `telegramBot` with `token: String` got `apiUrl` parameter + * Factory `telegramBotWithCustomClientConfig` has been renamed to `telegramBot` + ## 0.29.4 * `Core`: diff --git a/gradle.properties b/gradle.properties index cfac4de912..42d720c08a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,16 +6,18 @@ kotlin.incremental=true kotlin.incremental.js=true kotlin_version=1.4.10 -kotlin_coroutines_version=1.4.0 +kotlin_coroutines_version=1.4.1 kotlin_serialisation_runtime_version=1.0.1 klock_version=1.12.1 uuid_version=0.2.2 ktor_version=1.4.1 +micro_utils_version=0.2.7 + javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.29.4 +library_version=0.30.0 gradle_bintray_plugin_version=1.8.5 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index eaf93b61f8..e0248e76d1 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -47,6 +47,8 @@ kotlin { api "com.soywiz.korlibs.klock:klock:$klock_version" api "com.benasher44:uuid:$uuid_version" + api "dev.inmo:micro_utils.coroutines:$micro_utils_version" + api "io.ktor:ktor-client-core:$ktor_version" } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index e9145102ab..139ae89e82 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Captioned { val caption: String? @@ -19,8 +19,16 @@ interface CaptionedInput : Captioned { val captionEntities: List } +/** + * @see CaptionedInput.captionEntities + * @see justTextSources + */ +val CaptionedInput.textSources + get() = captionEntities.justTextSources() + /** * Convert its [CaptionedInput.captionEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ -fun CaptionedInput.fullEntitiesList(): FullTextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList() +@Deprecated("Currently list of entities already full. This method is redundant") +fun CaptionedInput.fullEntitiesList(): TextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt index 6ee7716366..6a2ac806a7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/CommonVenueData.kt @@ -1,8 +1,12 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.* + interface CommonVenueData : Titled { override val title: String val address: String - val foursquareId: String? - val foursquareType: String? // TODO:: Rewrite with enum or interface + val foursquareId: FoursquareId? + val foursquareType: FoursquareType? // TODO:: Rewrite with enum or interface + val googlePlaceId: GooglePlaceId? + val googlePlaceType: GooglePlaceType? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt index ef79db3bb2..fb837163fd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Explained.kt @@ -1,16 +1,22 @@ package dev.inmo.tgbotapi.CommonAbstracts import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.utils.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource interface Explained { val explanation: String? } -interface ExplainedOutput : Explained { +interface ParsableExplainedOutput : Explained { val parseMode: ParseMode? } +interface EntitiesExplainedOutput : Explained { + val entities: List? +} + +interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput + interface ExplainedInput : Explained { /** * Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] @@ -19,8 +25,16 @@ interface ExplainedInput : Explained { val explanationEntities: List } +/** + * @see ExplainedInput.explanationEntities + * @see justTextSources + */ +val ExplainedInput.textSources + get() = explanationEntities.justTextSources() + /** * Convert its [ExplainedInput.explanationEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ -fun ExplainedInput.fullEntitiesList(): FullTextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList() +@Deprecated("Currently list of entities already full. This method is redundant") +fun ExplainedInput.fullEntitiesList(): TextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Headed.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Headed.kt new file mode 100644 index 0000000000..629c19c285 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Headed.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.Degrees + +interface Headed { + val heading: Degrees? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/HorizontallyAccured.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/HorizontallyAccured.kt new file mode 100644 index 0000000000..6f64e012a1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/HorizontallyAccured.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.Meters + +interface HorizontallyAccured { + val horizontalAccuracy: Meters? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt index 228adeb9f8..2eef14eea2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Livable.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.Seconds + interface Livable { /** - * Period in SECONDS + * Period in [Seconds] */ - val livePeriod: Int? + val livePeriod: Seconds? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/ProximityAlertable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/ProximityAlertable.kt new file mode 100644 index 0000000000..413ff99b87 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/ProximityAlertable.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.Meters + +interface ProximityAlertable { + val proximityAlertRadius: Meters? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index 95bbd565b8..aac31893f5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -1,6 +1,16 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.MessageEntity.textsources.regular +import dev.inmo.tgbotapi.types.MessageEntity.toTextParts +import dev.inmo.tgbotapi.types.captionLength +import dev.inmo.tgbotapi.types.textLength + +const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods" + +typealias TextSourcesList = List +@Deprecated("All lists of TextSource in public API now are full. So, this typealias is redundant") typealias FullTextSourcesList = List +@Deprecated("All lists of TextPart in public API now are full. So, this typealias is redundant") typealias FullTextPartsList = List interface TextSource { @@ -8,11 +18,25 @@ interface TextSource { val asMarkdownV2Source: String val asHtmlSource: String val source: String + + val asText: String + get() = source } +@Suppress("NOTHING_TO_INLINE") +inline operator fun TextSource.plus(other: TextSource) = listOf(this, other) +@Suppress("NOTHING_TO_INLINE") +inline operator fun TextSource.plus(other: List) = listOf(this) + other +@Suppress("NOTHING_TO_INLINE") +inline operator fun TextSource.plus(text: String) = listOf(this, regular(text)) +@Suppress("NOTHING_TO_INLINE") +inline operator fun List.plus(text: String) = this + regular(text) interface MultilevelTextSource : TextSource { + @Deprecated("Will be removed in near major release") val textParts: List + get() = textParts(0) + val textSources: List } data class TextPart( @@ -21,3 +45,49 @@ data class TextPart( ) fun List.justTextSources() = map { it.source } +fun List.makeString() = joinToString("") { it.source } +internal fun MultilevelTextSource.textParts(offset: Int): List = textSources.toTextParts(offset) +fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> { + if (isEmpty()) { + return emptyList() + } + + val resultList = mutableListOf>(mutableListOf()) + var currentPartLength = 0 + val maxSize = limit.last + 1 + + for (current in this) { + if (current.source.length > maxSize) { + error("Currently unsupported parts with size more than target one-message parts (${current.source.length} > ${maxSize})") + } + + if (currentPartLength + current.source.length > maxSize) { + if (numberOfParts == null || numberOfParts < resultList.size) { + resultList.add(mutableListOf()) + currentPartLength = 0 + } else { + break + } + } + + resultList.last().add(current) + currentPartLength += current.source.length + } + + return resultList +} + +/** + * This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with + * [captionLength] and all others with + */ +fun List.separateForCaption(): List> { + val captionPart = separateForMessage(captionLength, 1).first() + return listOf(captionPart) + minus(captionPart).separateForMessage(textLength) +} + +/** + * This method will prepare [TextSource]s list for messages with [textLength] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun List.separateForText(): List> = separateForMessage(textLength) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt new file mode 100644 index 0000000000..4ff32e73de --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Texted.kt @@ -0,0 +1,40 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource + +interface Texted { + val text: String? +} + +interface ParsableOutput : Texted { + val parseMode: ParseMode? +} + +interface EntitiesOutput : Texted { + val entities: List? +} + +interface TextedOutput : ParsableOutput, EntitiesOutput + +interface TextedInput : Texted { + /** + * Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] + * @see [CaptionedInput.fullEntitiesList] + */ + val textEntities: List +} + +/** + * @see TextedInput.textEntities + * @see justTextSources + */ +val TextedInput.textSources + get() = textEntities.justTextSources() + +/** + * Convert its [TextedInput.textEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] + * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] + */ +@Deprecated("Currently list of entities already full. This method is redundant") +fun TextedInput.fullEntitiesList(): TextSourcesList = text ?.fullListOfSubSource(textEntities) ?.map { it.source } ?: emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt index 4acaca76f2..3321882208 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/types/ReplyMessageId.kt @@ -4,4 +4,5 @@ import dev.inmo.tgbotapi.types.MessageIdentifier interface ReplyMessageId { val replyToMessageId: MessageIdentifier? + val allowSendingWithoutReply: Boolean? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt index 909f3a72ad..949c55caf0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/KtorRequestsExecutor.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.bot.Ktor +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.BaseRequestsExecutor import dev.inmo.tgbotapi.bot.Ktor.base.* import dev.inmo.tgbotapi.bot.exceptions.newRequestException @@ -10,7 +11,6 @@ import dev.inmo.tgbotapi.types.Response import dev.inmo.tgbotapi.utils.* import io.ktor.client.HttpClient import io.ktor.client.features.* -import io.ktor.client.statement.HttpStatement import io.ktor.client.statement.readText import kotlinx.serialization.json.Json @@ -37,7 +37,7 @@ class KtorRequestsExecutor( } override suspend fun execute(request: Request): T { - return handleSafely( + return safely( { e -> throw if (e is ClientRequestException) { val content = e.response ?.readText() ?: throw e diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt index 80a11d0912..cbccc36e5c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileRequestCallFactory.kt @@ -1,15 +1,12 @@ package dev.inmo.tgbotapi.bot.Ktor.base +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory -import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper -import dev.inmo.tgbotapi.utils.handleSafely import io.ktor.client.HttpClient -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.HttpMethod +import io.ktor.client.request.get import kotlinx.serialization.json.Json object DownloadFileRequestCallFactory : KtorCallFactory { @@ -21,7 +18,7 @@ object DownloadFileRequestCallFactory : KtorCallFactory { ): T? = (request as? DownloadFile) ?.let { val fullUrl = "${urlsKeeper.fileBaseUrl}/${it.filePath}" - return handleSafely { + return safely { @Suppress("UNCHECKED_CAST") client.get(fullUrl) as T // always ByteArray } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt index 0489a54374..b878b0cd6a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt @@ -14,6 +14,8 @@ data class PromoteChatMember( override val userId: UserId, @SerialName(untilDateField) override val untilDate: TelegramDate? = null, + @SerialName(isAnonymousField) + private val isAnonymous: Boolean? = null, @SerialName(canChangeInfoField) private val canChangeInfo: Boolean? = null, @SerialName(canPostMessagesField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt index 6aef8178e3..afe519c847 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/UnbanChatMember.kt @@ -10,7 +10,9 @@ data class UnbanChatMember( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(userIdField) - override val userId: UserId + override val userId: UserId, + @SerialName(onlyIfBannedField) + val onlyIfBanned: Boolean? = null ) : ChatMemberRequest { override fun method(): String = "unbanChatMember" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt index e3ea186dcc..af3e88920c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/PinChatMessage.kt @@ -6,6 +6,11 @@ import dev.inmo.tgbotapi.types.* import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer +/** + * Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot + * must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a + * supergroup or 'can_edit_messages' admin right in a channel. + */ @Serializable data class PinChatMessage ( @SerialName(chatIdField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt new file mode 100644 index 0000000000..d5f8da23c3 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinAllChatMessages.kt @@ -0,0 +1,28 @@ +package dev.inmo.tgbotapi.requests.chat.modify + +import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.chatIdField +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an + * administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or + * 'can_edit_messages' admin right in a channel. + * + * @see PinChatMessage + * @see UnpinChatMessage + */ +@Serializable +data class UnpinAllChatMessages( + @SerialName(chatIdField) + override val chatId: ChatIdentifier +): ChatRequest, SimpleRequest { + override fun method(): String = "unpinAllChatMessages" + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt index 456d0649b9..868559b16d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/modify/UnpinChatMessage.kt @@ -3,14 +3,18 @@ package dev.inmo.tgbotapi.requests.chat.modify import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chatIdField +import dev.inmo.tgbotapi.types.messageIdField import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @Serializable data class UnpinChatMessage( @SerialName(chatIdField) - override val chatId: ChatIdentifier + override val chatId: ChatIdentifier, + @SerialName(messageIdField) + val messageId: MessageIdentifier? = null ): ChatRequest, SimpleRequest { override fun method(): String = "unpinChatMessage" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt index 0bc1869d0d..ba93fd4206 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.LocationContent +import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass>() @@ -20,6 +21,12 @@ data class EditChatMessageLiveLocation( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditReplyMessage, EditLocationMessage { @@ -28,4 +35,10 @@ data class EditChatMessageLiveLocation( get() = commonResultDeserializer override val requestSerializer: SerializationStrategy<*> get() = serializer() + + init { + if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) { + throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy) + } + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt index 60bcf9a122..f12c2d522d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/LiveLocation/EditInlineMessageLiveLocation.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.requests.edit.LiveLocation import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* @Serializable @@ -13,10 +14,22 @@ data class EditInlineMessageLiveLocation( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditReplyMessage, EditLocationMessage { override fun method(): String = "editMessageLiveLocation" override val requestSerializer: SerializationStrategy<*> get() = serializer() + + init { + if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) { + throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy) + } + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt index b41276c47d..853d39ee5b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditLocationMessage.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.requests.edit.abstracts -interface EditLocationMessage { - val latitude: Double - val longitude: Double -} +import dev.inmo.tgbotapi.CommonAbstracts.* + +interface EditLocationMessage : Locationed, HorizontallyAccured, ProximityAlertable, Headed diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt index 0c09216c1f..286695eaa3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/abstracts/EditTextChatMessage.kt @@ -1,8 +1,7 @@ package dev.inmo.tgbotapi.requests.edit.abstracts -import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput -interface EditTextChatMessage { - val text: String - val parseMode: ParseMode? +interface EditTextChatMessage : TextedOutput { + override val text: String } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt index ac53971139..617970f108 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditChatMessageCaption.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.requests.edit.caption +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +14,37 @@ import kotlinx.serialization.* const val editMessageCaptionMethod = "editMessageCaption" +fun EditChatMessageCaption( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageCaption( + chatId, + messageId, + text, + parseMode, + null, + replyMarkup +) + +fun EditChatMessageCaption( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageCaption( + chatId, + messageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + replyMarkup +) + @Serializable -data class EditChatMessageCaption( +data class EditChatMessageCaption internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(messageIdField) @@ -22,9 +53,14 @@ data class EditChatMessageCaption( override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditTextChatMessage, EditReplyMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } override fun method(): String = editMessageCaptionMethod override val resultDeserializer: DeserializationStrategy> diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt index 4cd418ab54..20145b3939 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/caption/EditInlineMessageCaption.kt @@ -1,23 +1,56 @@ package dev.inmo.tgbotapi.requests.edit.caption +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.* +fun EditInlineMessageCaption( + inlineMessageId: InlineMessageIdentifier, + text: String, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageCaption( + inlineMessageId, + text, + parseMode, + null, + replyMarkup +) + +fun EditInlineMessageCaption( + inlineMessageId: InlineMessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageCaption( + inlineMessageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + replyMarkup +) + @Serializable -data class EditInlineMessageCaption( +data class EditInlineMessageCaption internal constructor( @SerialName(inlineMessageIdField) override val inlineMessageId: InlineMessageIdentifier, @SerialName(captionField) override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } + override fun method(): String = editMessageCaptionMethod override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt index b327d18645..a0f37f90b3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditChatMessageText.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.requests.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +14,41 @@ import kotlinx.serialization.* const val editMessageTextMethod = "editMessageText" +fun EditChatMessageText( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageText( + chatId, + messageId, + text, + parseMode, + null, + disableWebPagePreview, + replyMarkup +) + +fun EditChatMessageText( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditChatMessageText( + chatId, + messageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableWebPagePreview, + replyMarkup +) + @Serializable -data class EditChatMessageText( +data class EditChatMessageText internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(messageIdField) @@ -22,11 +57,16 @@ data class EditChatMessageText( override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } override fun method(): String = editMessageTextMethod override val resultDeserializer: DeserializationStrategy> diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt index 00a714fa55..2e0be3eafe 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/edit/text/EditInlineMessageText.kt @@ -1,26 +1,63 @@ package dev.inmo.tgbotapi.requests.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.media.editMessageMediaMethod import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.* +fun EditInlineMessageText( + inlineMessageId: InlineMessageIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageText( + inlineMessageId, + text, + parseMode, + null, + disableWebPagePreview, + replyMarkup +) + +fun EditInlineMessageText( + inlineMessageId: InlineMessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = EditInlineMessageText( + inlineMessageId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableWebPagePreview, + replyMarkup +) + @Serializable -data class EditInlineMessageText( +data class EditInlineMessageText internal constructor( @SerialName(inlineMessageIdField) override val inlineMessageId: InlineMessageIdentifier, @SerialName(textField) override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + override fun method(): String = editMessageMediaMethod override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt new file mode 100644 index 0000000000..9f1bea26bf --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt @@ -0,0 +1,23 @@ +package dev.inmo.tgbotapi.requests.local + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to close the bot instance before moving it from one local server to another. You need to delete the + * webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will + * return error 429 in the first 10 minutes after the bot is launched. + * + * @see io.ktor.client.features.ClientRequestException + */ +@Serializable +object Close : SimpleRequest { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "close" + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt new file mode 100644 index 0000000000..63eb15993b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.requests.local + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to log out from the cloud Bot API server before launching the bot locally. You **must** log out the bot + * before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful + * call, you will not be able to log in again using the same token for 10 minutes + */ +@Serializable +object LogOut : SimpleRequest { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "logOut" + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt new file mode 100644 index 0000000000..817ff9ba0c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/CopyMessage.kt @@ -0,0 +1,77 @@ +package dev.inmo.tgbotapi.requests.send + +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.types.MessageAction +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.parseModeField +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass +import kotlinx.serialization.* + +fun CopyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = CopyMessage(fromChatId, toChatId, messageId, text, parseMode, null, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +fun CopyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = CopyMessage(fromChatId, toChatId, messageId, entities.makeString(), null, entities.toRawMessageEntities(), disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +@Serializable +data class CopyMessage internal constructor( + @SerialName(fromChatIdField) + val fromChatId: ChatIdentifier, + @SerialName(chatIdField) + val toChatId: ChatIdentifier, + @SerialName(messageIdField) + override val messageId: MessageIdentifier, + @SerialName(captionField) + override val text: String? = null, + @SerialName(parseModeField) + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, + @SerialName(disableNotificationField) + override val disableNotification: Boolean = false, + @SerialName(replyToMessageIdField) + override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, + @SerialName(replyMarkupField) + override val replyMarkup: KeyboardMarkup? = null +): SimpleRequest, + ReplyingMarkupSendMessageRequest, + MessageAction, + TextedOutput { + override val chatId: ChatIdentifier + get() = fromChatId + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + + override fun method(): String = "copyMessage" + + override val resultDeserializer: DeserializationStrategy + get() = MessageIdSerializer + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt index 2124808ed7..77613e5d93 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendContact.kt @@ -26,6 +26,8 @@ data class SendContact( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, @@ -36,6 +38,7 @@ data class SendContact( contact: Contact, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): this( chatId, @@ -44,6 +47,7 @@ data class SendContact( contact.lastName, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -58,11 +62,13 @@ fun Contact.toRequest( chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): SendContact = SendContact( chatId, this, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt index 248984de66..8347737808 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendDice.kt @@ -24,6 +24,8 @@ data class SendDice( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : ReplyingMarkupSendMessageRequest>, ReplyMessageId, DisableNotification { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt index 9a765ca175..69da7631dc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendLocation.kt @@ -1,19 +1,79 @@ package dev.inmo.tgbotapi.requests.send +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.LocationContent +import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() +fun SendLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = SendLocation( + chatId, + latitude, + longitude, + null, + null, + null, + null, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup +) + +fun SendStaticLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = SendLocation(chatId, latitude, longitude, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +fun SendLiveLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + livePeriod: Seconds, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = SendLocation( + chatId, + latitude, + longitude, + livePeriod, + horizontalAccuracy, + heading, + proximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup +) + @Serializable -data class SendLocation( +data class SendLocation internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(latitudeField) @@ -21,16 +81,28 @@ data class SendLocation( @SerialName(longitudeField) override val longitude: Double, @SerialName(livePeriodField) - val livePeriod: Long? = null, + override val livePeriod: Seconds? = null, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, ReplyingMarkupSendMessageRequest>, - PositionedSendMessageRequest> + PositionedSendMessageRequest>, + HorizontallyAccured, + Livable, + ProximityAlertable, + Headed { override fun method(): String = "sendLocation" override val resultDeserializer: DeserializationStrategy> @@ -42,5 +114,8 @@ data class SendLocation( if (livePeriod != null && livePeriod !in livePeriodLimit) { error("Live period for sending location must be in $livePeriodLimit, but was $livePeriod") } + if (horizontalAccuracy != null && horizontalAccuracy !in horizontalAccuracyLimit) { + throwRangeError("horizontalAccuracy", horizontalAccuracyLimit, horizontalAccuracy) + } } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt index f6b8ef20e0..c36219778c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendMessage.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.requests.send +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -15,20 +17,65 @@ import kotlinx.serialization.* internal val TextContentMessageResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() +fun SendTextMessage( + chatId: ChatIdentifier, + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = SendTextMessage( + chatId, + text, + parseMode, + null, + disableWebPagePreview, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup +) + +fun SendTextMessage( + chatId: ChatIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = SendTextMessage( + chatId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableWebPagePreview, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup +) + @Serializable -data class SendTextMessage( +data class SendTextMessage internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(textField) override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, @@ -36,6 +83,10 @@ data class SendTextMessage( TextableSendMessageRequest>, DisableWebPagePreview { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } + init { if (text.length !in textLength) { throwRangeError("Text length", textLength, text.length) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt index 81cc758590..fe0c5f2825 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendVenue.kt @@ -25,11 +25,19 @@ data class SendVenue( @SerialName(addressField) val address: String, @SerialName(foursquareIdField) - val foursquareId: String? = null, + val foursquareId: FoursquareId? = null, + @SerialName(foursquareTypeField) + val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + val googlePlaceType: GooglePlaceType? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, @@ -42,17 +50,22 @@ data class SendVenue( venue: Venue, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): this( - chatId, - venue.location.latitude, - venue.location.longitude, - venue.title, - venue.address, - venue.foursquareId, - disableNotification, - replyToMessageId, - replyMarkup + chatId = chatId, + latitude = venue.location.latitude, + longitude = venue.location.longitude, + title = venue.title, + address = venue.address, + foursquareId = venue.foursquareId, + foursquareType = venue.foursquareType, + googlePlaceId = venue.googlePlaceId, + googlePlaceType = venue.googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) override fun method(): String = "sendVenue" @@ -66,11 +79,13 @@ fun Venue.toRequest( chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): SendVenue = SendVenue( chatId, this, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt index e2823f307e..533d2b515d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/PositionedSendMessageRequest.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.requests.send.abstracts -interface PositionedSendMessageRequest: SendMessageRequest { - val latitude: Double - val longitude: Double -} \ No newline at end of file +import dev.inmo.tgbotapi.CommonAbstracts.Locationed + +interface PositionedSendMessageRequest: SendMessageRequest, Locationed \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt index 078c94f326..e77f2d321d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/TextableSendMessageRequest.kt @@ -1,8 +1,5 @@ package dev.inmo.tgbotapi.requests.send.abstracts -import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput -interface TextableSendMessageRequest: SendMessageRequest { - val text: String? - val parseMode: ParseMode? -} \ No newline at end of file +interface TextableSendMessageRequest: SendMessageRequest, TextedOutput diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt index 8c901e5e5e..7f49e410fe 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/games/SendGame.kt @@ -22,6 +22,8 @@ data class SendGame ( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt index de4578c8d0..4e58cc23a4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -25,6 +27,7 @@ fun SendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val animationAsFileId = (animation as? FileId) ?.fileId @@ -38,11 +41,57 @@ fun SendAnimation( thumbAsFileId, caption, parseMode, + null, duration, width, height, disableNotification, replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) + + return if (animationAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendAnimationFiles(animationAsFile, thumbAsFile) + ) + } +} + +fun SendAnimation( + chatId: ChatIdentifier, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val animationAsFileId = (animation as? FileId) ?.fileId + val animationAsFile = animation as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendAnimationData( + chatId, + animationAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + duration, + width, + height, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -71,6 +120,8 @@ data class SendAnimationData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(widthField) @@ -81,6 +132,8 @@ data class SendAnimationData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, @@ -91,6 +144,10 @@ data class SendAnimationData internal constructor( DuratedSendMessageRequest>, SizedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt index dd06aa2faf..82e15305a9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAudio.kt @@ -1,10 +1,11 @@ package dev.inmo.tgbotapi.requests.send.media -import dev.inmo.tgbotapi.CommonAbstracts.Performerable +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -26,6 +27,7 @@ fun SendAudio( title: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val audioAsFileId = (audio as? FileId) ?.fileId @@ -39,11 +41,57 @@ fun SendAudio( thumbAsFileId, caption, parseMode, + null, duration, performer, title, disableNotification, replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) + + return if (audioAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendAudioFiles(audioAsFile, thumbAsFile) + ) + } +} + +fun SendAudio( + chatId: ChatIdentifier, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val audioAsFileId = (audio as? FileId) ?.fileId + val audioAsFile = audio as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendAudioData( + chatId, + audioAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + duration, + performer, + title, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -72,6 +120,8 @@ data class SendAudioData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(performerField) @@ -82,6 +132,8 @@ data class SendAudioData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, @@ -93,6 +145,10 @@ data class SendAudioData internal constructor( DuratedSendMessageRequest>, Performerable { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt index 0b2db11bf8..6a515be8a4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendDocument.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -14,6 +16,15 @@ import dev.inmo.tgbotapi.utils.mapOfNotNull import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* +/** + * Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned. + * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile] + * + * @see ContentMessage + * @see DocumentContent + */ fun SendDocument( chatId: ChatIdentifier, document: InputFile, @@ -22,7 +33,9 @@ fun SendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null ): Request> { val documentAsFileId = (document as? FileId) ?.fileId val documentAsFile = document as? MultipartFile @@ -35,9 +48,61 @@ fun SendDocument( thumbAsFileId, caption, parseMode, + null, disableNotification, replyToMessageId, - replyMarkup + allowSendingWithoutReply, + replyMarkup, + disableContentTypeDetection + ) + + return if (documentAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendDocumentFiles(documentAsFile, thumbAsFile) + ) + } +} + +/** + * Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned. + * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile] + * + * @see ContentMessage + * @see DocumentContent + */ +fun SendDocument( + chatId: ChatIdentifier, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +): Request> { + val documentAsFileId = (document as? FileId) ?.fileId + val documentAsFile = document as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendDocumentData( + chatId, + documentAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup, + disableContentTypeDetection ) return if (documentAsFile == null && thumbAsFile == null) { @@ -53,6 +118,15 @@ fun SendDocument( private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() +/** + * Use this method to send general files. On success, the sent [ContentMessage] with [DocumentContent] is returned. + * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for [document] [MultipartFile] + * + * @see ContentMessage + * @see DocumentContent + */ @Serializable data class SendDocumentData internal constructor( @SerialName(chatIdField) @@ -65,18 +139,28 @@ data class SendDocumentData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) - override val replyMarkup: KeyboardMarkup? = null + override val replyMarkup: KeyboardMarkup? = null, + @SerialName(disableContentTypeDetectionField) + val disableContentTypeDetection: Boolean? = null ) : DataRequest>, SendMessageRequest>, ReplyingMarkupSendMessageRequest>, TextableSendMessageRequest>, ThumbedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt index c49a398ec4..df4a949fa1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt @@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.types.InputMedia.* import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass import dev.inmo.tgbotapi.utils.* -import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.buildJsonArray @@ -22,7 +21,8 @@ fun SendMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ): Request> { if (media.size !in mediaCountInMediaGroup) { throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size) @@ -43,7 +43,8 @@ fun SendMediaGroup( chatId, media, disableNotification, - replyToMessageId + replyToMessageId, + allowSendingWithoutReply ) return if (files.isEmpty()) { @@ -66,8 +67,9 @@ inline fun SendPlaylist( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId) + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) /** * Use this method to be sure that you are correctly sending documents media group @@ -79,8 +81,9 @@ inline fun SendDocumentsGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId) + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) /** * Use this method to be sure that you are correctly sending visual media group @@ -93,8 +96,9 @@ inline fun SendVisualMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId) + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) private val messagesListSerializer: KSerializer> = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass()) @@ -107,7 +111,9 @@ data class SendMediaGroupData internal constructor( @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) - override val replyToMessageId: MessageIdentifier? = null + override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null ) : DataRequest>, SendMessageRequest> { @SerialName(mediaField) private val convertedMedia: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt index 5ffd41caf2..c492456f31 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -20,6 +22,7 @@ fun SendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val data = SendPhotoData( @@ -27,8 +30,38 @@ fun SendPhoto( (photo as? FileId) ?.fileId, caption, parseMode, + null, disableNotification, replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) + return data.photo ?.let { + data + } ?: MultipartRequestImpl( + data, + SendPhotoFiles(photo as MultipartFile) + ) +} + +fun SendPhoto( + chatId: ChatIdentifier, + photo: InputFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val data = SendPhotoData( + chatId, + (photo as? FileId) ?.fileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + disableNotification, + replyToMessageId, + allowSendingWithoutReply, replyMarkup ) return data.photo ?.let { @@ -52,10 +85,14 @@ data class SendPhotoData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, @@ -63,6 +100,10 @@ data class SendPhotoData internal constructor( ReplyingMarkupSendMessageRequest>, TextableSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt index afa7f152d5..e19140ba51 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendSticker.kt @@ -17,12 +17,14 @@ fun SendSticker( sticker: InputFile, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> = SendStickerByFileId( chatId, sticker as? FileId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ).let { when (sticker) { @@ -44,6 +46,8 @@ data class SendStickerByFileId internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendMessageRequest>, ReplyingMarkupSendMessageRequest> { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt index 3c2ba65bd3..52e7ae8ba3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -26,6 +28,7 @@ fun SendVideo( supportStreaming: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val videoAsFileId = (video as? FileId) ?.fileId @@ -39,12 +42,60 @@ fun SendVideo( thumbAsFileId, caption, parseMode, + null, duration, width, height, supportStreaming, disableNotification, replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) + + return if (videoAsFile == null && thumbAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendVideoFiles(videoAsFile, thumbAsFile) + ) + } +} + +fun SendVideo( + chatId: ChatIdentifier, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + supportStreaming: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val videoAsFileId = (video as? FileId) ?.fileId + val videoAsFile = video as? MultipartFile + val thumbAsFileId = (thumb as? FileId) ?.fileId + val thumbAsFile = thumb as? MultipartFile + + val data = SendVideoData( + chatId, + videoAsFileId, + thumbAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + duration, + width, + height, + supportStreaming, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -73,6 +124,8 @@ data class SendVideoData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(widthField) @@ -85,6 +138,8 @@ data class SendVideoData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, @@ -95,6 +150,10 @@ data class SendVideoData internal constructor( DuratedSendMessageRequest>, SizedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt index 66376e093b..94d5b710fb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideoNote.kt @@ -4,26 +4,22 @@ import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.media.VideoNoteContent import dev.inmo.tgbotapi.utils.mapOfNotNull -import dev.inmo.tgbotapi.utils.throwRangeError import kotlinx.serialization.* fun SendVideoNote( chatId: ChatIdentifier, videoNote: InputFile, thumb: InputFile? = null, - caption: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, // in documentation - length (size of video side) disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val videoNoteAsFileId = (videoNote as? FileId) ?.fileId @@ -35,12 +31,11 @@ fun SendVideoNote( chatId, videoNoteAsFileId, thumbAsFileId, - caption, - parseMode, duration, size, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -65,10 +60,6 @@ data class SendVideoNoteData internal constructor( val videoNote: String? = null, @SerialName(thumbField) override val thumb: String? = null, - @SerialName(captionField) - override val text: String? = null, - @SerialName(parseModeField) - override val parseMode: ParseMode? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(lengthField) @@ -77,12 +68,13 @@ data class SendVideoNoteData internal constructor( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, SendMessageRequest>, ReplyingMarkupSendMessageRequest>, - TextableSendMessageRequest>, ThumbedSendMessageRequest>, DuratedSendMessageRequest>, SizedSendMessageRequest> @@ -90,14 +82,6 @@ data class SendVideoNoteData internal constructor( override val height: Int? get() = width - init { - text ?.let { - if (it.length !in captionLength) { - throwRangeError("Caption length", captionLength, it.length) - } - } - } - override fun method(): String = "sendVideoNote" override val resultDeserializer: DeserializationStrategy> get() = commonResultDeserializer diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt index 1429239446..69e6d0f756 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVoice.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.requests.send.media +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup @@ -22,6 +24,7 @@ fun SendVoice( duration: Long? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request> { val voiceAsFileId = (voice as? FileId) ?.fileId @@ -32,9 +35,47 @@ fun SendVoice( voiceAsFileId, caption, parseMode, + null, duration, disableNotification, replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) + + return if (voiceAsFile == null) { + data + } else { + MultipartRequestImpl( + data, + SendVoiceFiles(voiceAsFile) + ) + } +} + +fun SendVoice( + chatId: ChatIdentifier, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +): Request> { + val voiceAsFileId = (voice as? FileId) ?.fileId + val voiceAsFile = voice as? MultipartFile + + val data = SendVoiceData( + chatId, + voiceAsFileId, + entities.makeString(), + null, + entities.toRawMessageEntities(), + duration, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -61,12 +102,16 @@ data class SendVoiceData internal constructor( override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(durationField) override val duration: Long? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : DataRequest>, @@ -75,6 +120,10 @@ data class SendVoiceData internal constructor( TextableSendMessageRequest>, DuratedSendMessageRequest> { + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + init { text ?.let { if (it.length !in captionLength) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt index ef21eb0930..af6bc6e0da 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/payments/SendInvoice.kt @@ -57,6 +57,8 @@ data class SendInvoice( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null ) : Currencied, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index 7ded492c21..5c2784e85d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -1,19 +1,17 @@ package dev.inmo.tgbotapi.requests.send.polls +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import dev.inmo.tgbotapi.types.message.content.PollContent import dev.inmo.tgbotapi.types.polls.* -import dev.inmo.tgbotapi.utils.fullListOfSubSource -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions -import com.soywiz.klock.DateTime import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() @@ -43,6 +41,7 @@ fun SendPoll( isClosed: Boolean = false, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = SendRegularPoll( chatId, @@ -50,6 +49,7 @@ fun SendPoll( options, isAnonymous, isClosed, + allowSendingWithoutReply = allowSendingWithoutReply, disableNotification = disableNotification, replyToMessageId = replyToMessageId, replyMarkup = replyMarkup @@ -63,6 +63,7 @@ fun Poll.createRequest( chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = when (this) { is RegularPoll -> SendRegularPoll( @@ -75,6 +76,7 @@ fun Poll.createRequest( scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) is QuizPoll -> correctOptionId ?.let { correctOptionId -> @@ -85,11 +87,11 @@ fun Poll.createRequest( correctOptionId, isAnonymous, isClosed, - explanation ?.fullListOfSubSource(explanationEntities) ?.justTextSources() ?.toMarkdownV2Captions() ?.firstOrNull(), - MarkdownV2, + fullEntitiesList(), scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } ?: SendRegularPoll( @@ -102,6 +104,7 @@ fun Poll.createRequest( scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) is UnknownPollType -> SendRegularPoll( @@ -114,6 +117,7 @@ fun Poll.createRequest( scheduledCloseInfo, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } @@ -165,6 +169,8 @@ data class SendRegularPoll( override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendPoll() { @@ -186,8 +192,69 @@ data class SendRegularPoll( } } +fun SendQuizPoll( + chatId: ChatIdentifier, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + explanation: String? = null, + parseMode: ParseMode? = null, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = SendQuizPoll( + chatId, + question, + options, + correctOptionId, + isAnonymous, + isClosed, + explanation, + parseMode, + null, + closeInfo, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup +) + +fun SendQuizPoll( + chatId: ChatIdentifier, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = SendQuizPoll( + chatId, + question, + options, + correctOptionId, + isAnonymous, + isClosed, + entities.makeString(), + null, + entities.toRawMessageEntities(), + closeInfo, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup +) + @Serializable -data class SendQuizPoll( +data class SendQuizPoll internal constructor( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(questionField) @@ -204,18 +271,25 @@ data class SendQuizPoll( override val explanation: String? = null, @SerialName(explanationParseModeField) override val parseMode: ParseMode? = null, + @SerialName(explanationEntitiesField) + private val rawEntities: List? = null, @Transient override val closeInfo: ScheduledCloseInfo? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, + @SerialName(allowSendingWithoutReplyField) + override val allowSendingWithoutReply: Boolean? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null ) : SendPoll(), ExplainedOutput { override val type: String = quizPollType override val requestSerializer: SerializationStrategy<*> get() = serializer() + override val entities: List? by lazy { + rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources() + } @SerialName(openPeriodField) override val openPeriod: LongSeconds? diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt index 5dc0f0841a..9a2c5a3a0f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt @@ -16,14 +16,18 @@ private fun correctWebhookUrl(sourceUrl: String) = if (sourceUrl.contains("://") fun SetWebhook( url: String, certificate: MultipartFile, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): MultipartRequestImpl, Boolean> = MultipartRequestImpl( SetWebhook( correctWebhookUrl(url), - null, + null as String?, + ipAddress, maxAllowedConnections, - allowedUpdates + allowedUpdates, + dropPendingUpdates ), mapOf(certificateField to certificate) ) @@ -31,47 +35,83 @@ fun SetWebhook( fun SetWebhook( url: String, certificate: FileId, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): SetWebhook = SetWebhook( correctWebhookUrl(url), certificate.fileId, + ipAddress, maxAllowedConnections, - allowedUpdates + allowedUpdates, + dropPendingUpdates ) +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ @Suppress("USELESS_CAST") fun SetWebhook( url: String, certificate: InputFile, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): Request = when (certificate) { - is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, maxAllowedConnections, allowedUpdates) - is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, maxAllowedConnections, allowedUpdates) + is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) + is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) } +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ +@Suppress("USELESS_CAST") fun SetWebhook( url: String, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null -) = SetWebhook( + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null +): Request = SetWebhook( correctWebhookUrl(url), null, + ipAddress, maxAllowedConnections, - allowedUpdates + allowedUpdates, + dropPendingUpdates ) +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ @Serializable data class SetWebhook internal constructor( @SerialName(urlField) val url: String, @SerialName(certificateField) val certificateFile: String? = null, + @SerialName(ipAddressField) + val ipAddress: String? = null, @SerialName(maxAllowedConnectionsField) val maxAllowedConnections: Int? = null, @SerialName(allowedUpdatesField) - val allowedUpdates: List? = null + val allowedUpdates: List? = null, + @SerialName(dropPendingUpdatesField) + val dropPendingUpdates: Boolean? = null ) : DataRequest { override fun method(): String = "setWebhook" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 2babc7b429..813ac70c44 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types import kotlinx.serialization.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.* +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.longOrNull @Serializable(ChatIdentifierSerializer::class) sealed class ChatIdentifier diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt new file mode 100644 index 0000000000..3d24f1eb8f --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatLocation.kt @@ -0,0 +1,19 @@ +package dev.inmo.tgbotapi.types + +import dev.inmo.tgbotapi.types.location.StaticLocation +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Represents a location to which a chat is connected. + * + * @see dev.inmo.tgbotapi.requests.chat.get.GetChat + * @see dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedSupergroupChat + */ +@Serializable +data class ChatLocation( + @SerialName(locationField) + val location: StaticLocation, + @SerialName(addressField) + val address: String +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt index d4f9727948..3b734ef904 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt @@ -14,5 +14,6 @@ data class AdministratorChatMemberImpl( override val canRestrictMembers: Boolean, override val canPinMessages: Boolean, override val canPromoteMembers: Boolean, + override val isAnonymous: Boolean, override val customTitle: String? ) : AdministratorChatMember diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt index 153679d274..af981b2312 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.User data class CreatorChatMember( override val user: User, + override val isAnonymous: Boolean, override val customTitle: String? ) : AdministratorChatMember { override val canBeEdited: Boolean = true diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt index 5e7e9875a7..4f8bd51b66 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/RawChatMember.kt @@ -40,12 +40,14 @@ internal data class RawChatMember( private val canSendOtherMessages: Boolean = false, @SerialName(canAddWebPagePreviewsField) private val canAddWebPagePreviews: Boolean = false, + @SerialName(isAnonymousField) + private val isAnonymous: Boolean = false, @SerialName(customTitleField) private val customTitle: String? = null ) { val asChatMember: ChatMember by lazy { when (status) { - "creator" -> CreatorChatMember(user, customTitle) + "creator" -> CreatorChatMember(user, isAnonymous, customTitle) "administrator" -> AdministratorChatMemberImpl( user, canBeEdited, @@ -57,6 +59,7 @@ internal data class RawChatMember( canRestrictMembers, canPinMessages, canPromoteMembers, + isAnonymous, customTitle ) "member" -> MemberChatMember(user) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt index 8b7e7cc18e..ba3bb2ac00 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt @@ -7,5 +7,6 @@ interface AdministratorChatMember : SpecialRightsChatMember { val canRemoveMessages: Boolean val canRestrictMembers: Boolean val canPromoteMembers: Boolean + val isAnonymous: Boolean val customTitle: String? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt index b0d0a88171..21d8324165 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/ChatMember.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.types.ChatMember.abstracts import dev.inmo.tgbotapi.types.ChatMember.RawChatMember import dev.inmo.tgbotapi.types.User -import kotlinx.serialization.* +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 0d3a71a24e..af9fb30db5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -24,10 +24,18 @@ typealias FileUniqueId = String typealias DiceResult = Int typealias FoursquareId = String typealias FoursquareType = String +typealias GooglePlaceId = String +typealias GooglePlaceType = String typealias Seconds = Int typealias LongSeconds = Long +typealias Meters = Float +typealias Degrees = Int + +val degreesLimit = 1 .. 360 +val horizontalAccuracyLimit = 0F .. 1500F + val getUpdatesLimit = 1 .. 100 val callbackQueryAnswerLength = 0 until 200 val captionLength = 0 .. 1024 @@ -43,7 +51,7 @@ val invoiceDescriptionLimit = 1 until 256 val invoicePayloadBytesLimit = 1 until 128 val pollOptionTextLength = 1 .. 100 -val pollQuestionTextLength = 1 until 256 +val pollQuestionTextLength = 1 .. 300 val pollOptionsLimit = 2 .. 10 val livePeriodLimit = 60 .. 86400 @@ -52,10 +60,11 @@ val inlineQueryAnswerResultsLimit = 0 .. 50 val customTitleLength = 0 .. 16 -val commonDiceResultLimit = 1 .. 6 -@Deprecated("Renamed", ReplaceWith("commonDiceResultLimit", "dev.inmo.tgbotapi.types.commonDiceResultLimit")) +val dartsAndCubeDiceResultLimit = 1 .. 6 +@Deprecated("Renamed", ReplaceWith("dartsAndCubeDiceResultLimit", "dev.inmo.tgbotapi.types.dartsAndCubeDiceResultLimit")) val diceResultLimit - get() = commonDiceResultLimit + get() = dartsAndCubeDiceResultLimit +val basketballAndFootballDiceResultLimit = 1 .. 5 val slotMachineDiceResultLimit = 1 .. 64 val botCommandLengthLimit = 1 .. 32 @@ -85,9 +94,12 @@ const val fromChatIdField = "from_chat_id" const val disableWebPagePreviewField = "disable_web_page_preview" const val disableNotificationField = "disable_notification" const val replyToMessageIdField = "reply_to_message_id" +const val allowSendingWithoutReplyField = "allow_sending_without_reply" const val replyMarkupField = "reply_markup" +const val disableContentTypeDetectionField = "disable_content_type_detection" const val supportStreamingField = "support_streaming" const val livePeriodField = "live_period" +const val proximityAlertRadiusField = "proximity_alert_radius" const val isBotField = "is_bot" const val firstNameField = "first_name" const val lastNameField = "last_name" @@ -96,12 +108,14 @@ const val canJoinGroupsField = "can_join_groups" const val canReadAllGroupMessagesField = "can_read_all_group_messages" const val supportInlineQueriesField = "supports_inline_queries" const val textEntitiesField = "text_entities" +const val entitiesField = "entities" const val stickerSetNameField = "set_name" const val stickerSetNameFullField = "sticker_set_name" const val slowModeDelayField = "slow_mode_delay" const val maskPositionField = "mask_position" const val phoneNumberField = "phone_number" const val userIdField = "user_id" +const val onlyIfBannedField = "only_if_banned" const val containsMasksField = "contains_masks" const val resultIdField = "result_id" const val inlineMessageIdField = "inline_message_id" @@ -114,6 +128,8 @@ const val showAlertField = "show_alert" const val cachedTimeField = "cached_time" const val foursquareIdField = "foursquare_id" const val foursquareTypeField = "foursquare_type" +const val googlePlaceIdField = "google_place_id" +const val googlePlaceTypeField = "google_place_type" const val untilDateField = "until_date" const val errorMessageField = "error_message" const val messageTextField = "message_text" @@ -123,6 +139,7 @@ const val switchPmTextField = "switch_pm_text" const val switchPmParameterField = "switch_pm_parameter" const val maxAllowedConnectionsField = "max_connections" const val allowedUpdatesField = "allowed_updates" +const val dropPendingUpdatesField = "drop_pending_updates" const val hasCustomCertificateField = "has_custom_certificate" const val pendingUpdateCountField = "pending_update_count" const val lastErrorDateField = "last_error_date" @@ -133,6 +150,7 @@ const val totalVoterCountField = "total_voter_count" const val correctOptionIdField = "correct_option_id" const val allowsMultipleAnswersField = "allows_multiple_answers" const val isAnonymousField = "is_anonymous" +const val captionEntitiesField = "caption_entities" const val loginUrlField = "login_url" const val forwardTextField = "forward_text" const val botUsernameField = "bot_username" @@ -143,6 +161,9 @@ const val inviteLinkField = "invite_link" const val pinnedMessageField = "pinned_message" const val customTitleField = "custom_title" const val optionIdsField = "option_ids" +const val ipAddressField = "ip_address" +const val linkedChatIdField = "linked_chat_id" +const val horizontalAccuracyField = "horizontal_accuracy" const val requestContactField = "request_contact" const val requestLocationField = "request_location" @@ -240,11 +261,13 @@ const val heightField = "height" const val lengthField = "length" const val latitudeField = "latitude" const val longitudeField = "longitude" +const val headingField = "heading" const val fromField = "from" const val userField = "user" const val dateField = "date" const val chatField = "chat" const val usernameField = "username" +const val bioField = "bio" const val nameField = "name" const val emailField = "email" const val locationField = "location" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt index 92623a6402..16324e7e85 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/LocationChosenInlineResult.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult +import dev.inmo.tgbotapi.types.location.StaticLocation data class LocationChosenInlineResult( override val resultId: InlineQueryIdentifier, override val user: User, - val location: Location, + val location: StaticLocation, override val inlineMessageId: InlineMessageIdentifier?, override val query: String ) : ChosenInlineResult diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt index 4900c189b4..4db078be40 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/ChosenInlineResult/RawChosenInlineResult.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.ChosenInlineResult +import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -14,7 +15,7 @@ internal data class RawChosenInlineResult( @SerialName(queryField) val query: String, @SerialName(locationField) - val location: Location? = null, + val location: StaticLocation? = null, @SerialName(inlineMessageIdField) val inlineMessageId: InlineMessageIdentifier? = null ) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt index 7d478397ec..30f23487c8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioCachedImpl.kt @@ -1,30 +1,54 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudioCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultAudioCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioCachedImpl(id, fileId, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultAudioCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioCachedImpl(id, fileId, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultAudioCachedImpl( +data class InlineQueryResultAudioCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(audioFileIdField) override val fileId: FileId, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultAudioCached { override val type: String = inlineQueryResultAudioType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt index e009ab8f66..f4221fae20 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultAudioImpl.kt @@ -1,17 +1,42 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudio import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultAudioImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + performer: String? = null, + duration: Int? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioImpl(id, url, title, performer, duration, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultAudioImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + performer: String? = null, + duration: Int? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultAudioImpl(id, url, title, performer, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultAudioImpl( +data class InlineQueryResultAudioImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(audioUrlField) @@ -23,13 +48,18 @@ data class InlineQueryResultAudioImpl( @SerialName(audioDurationField) override val duration: Int? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultAudio { override val type: String = inlineQueryResultAudioType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt index 85b4cb2644..2b7bd33291 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentCachedImpl.kt @@ -1,18 +1,41 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocumentCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultDocumentCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultDocumentCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultDocumentCachedImpl( +data class InlineQueryResultDocumentCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(documentFileIdField) @@ -22,13 +45,18 @@ data class InlineQueryResultDocumentCachedImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultDocumentCached { override val type: String = inlineQueryResultDocumentType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt index 4043852c3c..bca7294ef3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultDocumentImpl.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocument import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +14,37 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultDocumentImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + mimeType: MimeType, + thumbUrl: String? = null, + thumbWidth: Int? = null, + thumbHeight: Int? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultDocumentImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + mimeType: MimeType, + thumbUrl: String? = null, + thumbWidth: Int? = null, + thumbHeight: Int? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultDocumentImpl( +data class InlineQueryResultDocumentImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(documentUrlField) @@ -31,13 +62,18 @@ data class InlineQueryResultDocumentImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultDocument { override val type: String = inlineQueryResultDocumentType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt index 091cc13c2a..a65dd530ac 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifCachedImpl.kt @@ -1,18 +1,39 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGifCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultGifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultGifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultGifCachedImpl( +data class InlineQueryResultGifCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(gifFileIdField) @@ -20,13 +41,18 @@ data class InlineQueryResultGifCachedImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultGifCached { override val type: String = inlineQueryResultGifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt index afb8b7215d..d282045d62 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultGifImpl.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGif import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -11,8 +13,37 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultGifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultGifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultGifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultGifImpl( +data class InlineQueryResultGifImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(gifUrlField) @@ -30,15 +61,20 @@ data class InlineQueryResultGifImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultGif { override val type: String = inlineQueryResultGifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } init { if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt index e7eebe43ab..5b6d19776f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultLocation.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult -import dev.inmo.tgbotapi.CommonAbstracts.Livable -import dev.inmo.tgbotapi.CommonAbstracts.Locationed +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent @@ -17,10 +16,16 @@ data class InlineQueryResultLocation( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, @SerialName(titleField) override val title: String, @SerialName(livePeriodField) - override val livePeriod: Int? = null, + override val livePeriod: Seconds? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null, @SerialName(thumbUrlField) override val thumbUrl: String? = null, @SerialName(thumbWidthField) @@ -33,7 +38,10 @@ data class InlineQueryResultLocation( override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResult, Locationed, + HorizontallyAccured, Livable, + ProximityAlertable, + Headed, TitledInlineQueryResult, WithInputMessageContentInlineQueryResult, ThumbedInlineQueryResult, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt index 014664fca9..d7726fa700 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifCachedImpl.kt @@ -1,18 +1,39 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4GifCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultMpeg4GifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultMpeg4GifCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultMpeg4GifCachedImpl( +data class InlineQueryResultMpeg4GifCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(mpeg4GifFileIdField) @@ -20,13 +41,18 @@ data class InlineQueryResultMpeg4GifCachedImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultMpeg4GifCached { override val type: String = inlineQueryResultMpeg4GifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt index 206016a70f..9b07306447 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultMpeg4GifImpl.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4Gif import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -11,8 +13,37 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultMpeg4GifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultMpeg4GifImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + thumbMimeType: MimeType? = null, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + title: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultMpeg4GifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultMpeg4GifImpl( +data class InlineQueryResultMpeg4GifImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(mpeg4GifUrlField) @@ -30,15 +61,20 @@ data class InlineQueryResultMpeg4GifImpl( @SerialName(titleField) override val title: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultMpeg4Gif { override val type: String = inlineQueryResultMpeg4GifType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } init { if (thumbMimeType != null && thumbMimeType !in telegramInlineModeGifPermittedMimeTypes) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt index 270fa12fa9..942fb9039a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoCachedImpl.kt @@ -1,18 +1,41 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhotoCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultPhotoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultPhotoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultPhotoCachedImpl( +data class InlineQueryResultPhotoCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(photoFileIdField) @@ -22,13 +45,18 @@ data class InlineQueryResultPhotoCachedImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultPhotoCached { override val type: String = inlineQueryResultPhotoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt index bd35faee26..332a2ce09c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultPhotoImpl.kt @@ -1,17 +1,46 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhoto import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultPhotoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + width: Int? = null, + height: Int? = null, + title: String? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoImpl(id, url, thumbUrl, width, height, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultPhotoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + width: Int? = null, + height: Int? = null, + title: String? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultPhotoImpl(id, url, thumbUrl, width, height, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultPhotoImpl( +data class InlineQueryResultPhotoImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(photoUrlField) @@ -27,13 +56,18 @@ data class InlineQueryResultPhotoImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultPhoto { override val type: String = inlineQueryResultPhotoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt index 30ec5796f2..e514afb1dd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVenue.kt @@ -22,9 +22,13 @@ data class InlineQueryResultVenue( @SerialName(addressField) override val address: String, @SerialName(foursquareIdField) - override val foursquareId: String? = null, + override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: String? = null, + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null, @SerialName(thumbUrlField) override val thumbUrl: String? = null, @SerialName(thumbWidthField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt index c5368ae68f..8fe16705c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoCachedImpl.kt @@ -1,18 +1,41 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideoCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVideoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultVideoCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVideoCachedImpl( +data class InlineQueryResultVideoCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(videoFileIdField) @@ -22,13 +45,18 @@ data class InlineQueryResultVideoCachedImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVideoCached { override val type: String = inlineQueryResultVideoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt index 63ca03891b..e055c7f468 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVideoImpl.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideo import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -12,8 +14,39 @@ import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVideoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + mimeType: MimeType, + title: String, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + description: String? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultVideoImpl( + id: InlineQueryIdentifier, + url: String, + thumbUrl: String, + mimeType: MimeType, + title: String, + width: Int? = null, + height: Int? = null, + duration: Int? = null, + description: String? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVideoImpl( +data class InlineQueryResultVideoImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(videoUrlField) @@ -33,13 +66,18 @@ data class InlineQueryResultVideoImpl( @SerialName(descriptionField) override val description: String? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVideo { override val type: String = inlineQueryResultVideoType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt index e840e1f444..e5e236120d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceCachedImpl.kt @@ -1,18 +1,39 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoiceCached import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVoiceCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent) + +fun InlineQueryResultVoiceCachedImpl( + id: InlineQueryIdentifier, + fileId: FileId, + title: String, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVoiceCachedImpl( +data class InlineQueryResultVoiceCachedImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(voiceFileIdField) @@ -20,13 +41,18 @@ data class InlineQueryResultVoiceCachedImpl( @SerialName(titleField) override val title: String, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVoiceCached { override val type: String = inlineQueryResultVoiceType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt index 7a8f85efc6..02c4189ed8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/InlineQueryResultVoiceImpl.kt @@ -1,17 +1,50 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoice import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InlineQueryResultVoiceImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + duration: Int? = null, + text: String? = null, + parseMode: ParseMode? = null, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceImpl( + id, + url, + title, + duration, + text, + parseMode, + null, + replyMarkup, + inputMessageContent +) + +fun InlineQueryResultVoiceImpl( + id: InlineQueryIdentifier, + url: String, + title: String, + duration: Int? = null, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null, + inputMessageContent: InputMessageContent? = null +) = InlineQueryResultVoiceImpl(id, url, title, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) + @Serializable -data class InlineQueryResultVoiceImpl( +data class InlineQueryResultVoiceImpl internal constructor( @SerialName(idField) override val id: InlineQueryIdentifier, @SerialName(voiceUrlField) @@ -21,13 +54,18 @@ data class InlineQueryResultVoiceImpl( @SerialName(voiceDurationField) override val duration: Int? = null, @SerialName(captionField) - override val caption: String? = null, + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, @SerialName(replyMarkupField) override val replyMarkup: InlineKeyboardMarkup? = null, @SerialName(inputMessageContentField) override val inputMessageContent: InputMessageContent? = null ) : InlineQueryResultVoice { override val type: String = inlineQueryResultVoiceType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt index 4d044cb2fa..b27d04396d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/audio/InlineQueryResultAudioCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.WithInputMessageContentInlineQueryResult @@ -8,4 +9,9 @@ const val inlineQueryResultAudioType = "audio" interface InlineQueryResultAudioCommon : InlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt index 6000638253..fa51b3e0e0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/document/InlineQueryResultDocumentCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultDocumentType = "document" @@ -9,4 +10,9 @@ interface InlineQueryResultDocumentCommon : InlineQueryResult, TitledInlineQueryResult, DescribedInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt index 6c64ec21b0..95e5f14480 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/gif/InlineQueryResultGifCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultGifType = "gif" @@ -8,4 +9,9 @@ const val inlineQueryResultGifType = "gif" interface InlineQueryResultGifCommon : InlineQueryResult, OptionallyTitledInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt index f8649eb7b8..69b4e5b88c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/mpeg4gif/InlineQueryResultMpeg4GifCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultMpeg4GifType = "mpeg4_gif" @@ -8,4 +9,9 @@ const val inlineQueryResultMpeg4GifType = "mpeg4_gif" interface InlineQueryResultMpeg4GifCommon : InlineQueryResult, OptionallyTitledInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt index b65989092d..1f33a3a9b9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/photo/InlineQueryResultPhotoCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultPhotoType = "photo" @@ -9,4 +10,9 @@ interface InlineQueryResultPhotoCommon : InlineQueryResult, OptionallyTitledInlineQueryResult, DescribedInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt index a82aecbd03..a015faac61 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/video/InlineQueryResultVideoCommon.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultVideoType = "video" @@ -9,4 +10,9 @@ interface InlineQueryResultVideoCommon : InlineQueryResult, TitledInlineQueryResult, DescribedInlineQueryResult, CaptionedOutput, - WithInputMessageContentInlineQueryResult + TextedOutput, + WithInputMessageContentInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt index 8ff23d5ea3..0bb3dee55b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InlineQueryResult/abstracts/results/voice/InlineQueryResultVoiceCommon.kt @@ -1,11 +1,17 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* const val inlineQueryResultVoiceType = "voice" interface InlineQueryResultVoiceCommon : InlineQueryResult, CaptionedOutput, + TextedOutput, WithInputMessageContentInlineQueryResult, - TitledInlineQueryResult + TitledInlineQueryResult { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt index 9096ab0eac..eda3152abf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputLocationMessageContent.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent -import dev.inmo.tgbotapi.CommonAbstracts.Livable -import dev.inmo.tgbotapi.CommonAbstracts.Locationed +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent import kotlinx.serialization.SerialName @@ -13,6 +12,12 @@ data class InputLocationMessageContent( override val latitude: Double, @SerialName(longitudeField) override val longitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, @SerialName(livePeriodField) - override val livePeriod: Int? = null -) : Locationed, Livable, InputMessageContent \ No newline at end of file + override val livePeriod: Seconds? = null, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null +) : Locationed, HorizontallyAccured, ProximityAlertable, Livable, Headed, InputMessageContent \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt index 698608c632..9a2d74746b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputTextMessageContent.kt @@ -1,21 +1,47 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField -import dev.inmo.tgbotapi.types.disableWebPagePreviewField -import dev.inmo.tgbotapi.types.messageTextField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +/** + * Represents the [InputMessageContent] of a text message to be sent as the result of an inline query. + */ +fun InputTextMessageContent( + text: String, + parseMode: ParseMode? = null, + disableWebPagePreview: Boolean? = null +) = InputTextMessageContent(text, parseMode, null, disableWebPagePreview) + +/** + * Represents the [InputMessageContent] of a text message to be sent as the result of an inline query. + */ +fun InputTextMessageContent( + entities: List, + disableWebPagePreview: Boolean? = null +) = InputTextMessageContent(entities.makeString(), null, entities.toRawMessageEntities(), disableWebPagePreview) + @Serializable -data class InputTextMessageContent( +data class InputTextMessageContent internal constructor( @SerialName(messageTextField) - override val caption: String, + override val text: String, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(entitiesField) + private val rawEntities: List? = null, @SerialName(disableWebPagePreviewField) override val disableWebPagePreview: Boolean? = null -) : CaptionedOutput, DisableWebPagePreview, InputMessageContent \ No newline at end of file +) : CaptionedOutput, TextedOutput, DisableWebPagePreview, InputMessageContent { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text + override val entities: List? by lazy { + rawEntities ?.asTextParts(text) ?.justTextSources() + } +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt index f8be7df0c5..e744c10404 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/InputMessageContent/InputVenueMessageContent.kt @@ -18,7 +18,11 @@ data class InputVenueMessageContent( @SerialName(addressField) override val address: String, @SerialName(foursquareIdField) - override val foursquareId: String? = null, + override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: String? = null + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null ) : Locationed, CommonVenueData, InputMessageContent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt index 260eb39cc2..fe94c7e34d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/LocationInlineQuery.kt @@ -1,7 +1,9 @@ package dev.inmo.tgbotapi.types.InlineQueries.query -import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery +import dev.inmo.tgbotapi.types.InlineQueryIdentifier +import dev.inmo.tgbotapi.types.User +import dev.inmo.tgbotapi.types.location.Location data class LocationInlineQuery( override val id: InlineQueryIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt index 2d15827909..eaf43fca71 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/query/RawInlineQuery.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.query import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.Location import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt index c56a9044f3..5eb5e61c8e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAnimation.kt @@ -1,25 +1,56 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +fun InputMediaAnimation( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaAnimation(file, text, parseMode, null, width, height, duration, thumb) + +fun InputMediaAnimation( + file: InputFile, + entities: List, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaAnimation(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) + @Serializable -data class InputMediaAnimation( +data class InputMediaAnimation internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, override val width: Int? = null, override val height: Int? = null, override val duration: Long? = null, override val thumb: InputFile? = null -) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedOutput { +) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput, CaptionedOutput { override val type: String = "animation" + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } + + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text @SerialName(mediaField) override val media: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt index 1c3b547428..01d416f485 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaAudio.kt @@ -1,30 +1,58 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput -import dev.inmo.tgbotapi.CommonAbstracts.Performerable -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.AudioFile -import dev.inmo.tgbotapi.types.files.PhotoSize -import dev.inmo.tgbotapi.types.mediaField -import dev.inmo.tgbotapi.types.message.content.media.AudioContent import kotlinx.serialization.* internal const val audioInputMediaType = "audio" +fun InputMediaAudio( + file: InputFile, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + thumb: InputFile? = null +) = InputMediaAudio( + file, entities.makeString(), null, entities.toRawMessageEntities(), duration, performer, title, thumb +) + +fun InputMediaAudio( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + duration: Long? = null, + performer: String? = null, + title: String? = null, + thumb: InputFile? = null +) = InputMediaAudio( + file, text, parseMode, null, duration, performer, title, thumb +) + @Serializable -data class InputMediaAudio( +data class InputMediaAudio internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, override val duration: Long? = null, override val performer: String? = null, override val title: String? = null, override val thumb: InputFile? = null -) : InputMedia, AudioMediaGroupMemberInputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, CaptionedOutput, Performerable { +) : InputMedia, AudioMediaGroupMemberInputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, Performerable { override val type: String = audioInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt index 465b630c6a..a448046867 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaDocument.kt @@ -1,24 +1,58 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.DocumentFile -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.* internal const val documentInputMediaType = "document" +fun InputMediaDocument( + file: InputFile, + caption: String? = null, + parseMode: ParseMode? = null, + thumb: InputFile? = null, + disableContentTypeDetection: Boolean? = null +) = InputMediaDocument(file, caption, parseMode, null, thumb, disableContentTypeDetection) + +fun InputMediaDocument( + file: InputFile, + entities: List, + thumb: InputFile? = null, + disableContentTypeDetection: Boolean? = null +) = InputMediaDocument(file, entities.makeString(), null, entities.toRawMessageEntities(), thumb, disableContentTypeDetection) + +/** + * Represents a general file to be sent. See https://core.telegram.org/bots/api#inputmediadocument + * + * @param disableContentTypeDetection Disables automatic server-side content type detection for files uploaded using + * multipart/form-data. Always used by Telegram system as true, if the document is sent as part of an album. + * + * @see InputFile + * @see MultipartFile + * @see FileId + */ @Serializable -data class InputMediaDocument( +data class InputMediaDocument internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, - override val thumb: InputFile? = null -) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia, CaptionedOutput { + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, + override val thumb: InputFile? = null, + @SerialName(disableContentTypeDetectionField) + val disableContentTypeDetection: Boolean? = null +) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia { override val type: String = documentInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt index 32a5c1b482..345d60b117 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaPhoto.kt @@ -1,24 +1,42 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.files.PhotoSize -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.* -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonObject internal const val photoInputMediaType = "photo" +fun InputMediaPhoto( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null +) = InputMediaPhoto(file, text, parseMode, null) + +fun InputMediaPhoto( + file: InputFile, + entities: List +) = InputMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) + @Serializable -data class InputMediaPhoto( +data class InputMediaPhoto internal constructor( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) - override val parseMode: ParseMode? = null + override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null ) : InputMedia, VisualMediaGroupMemberInputMedia { override val type: String = photoInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt index 302a1579d3..f7907dd023 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/InputMediaVideo.kt @@ -1,26 +1,53 @@ package dev.inmo.tgbotapi.types.InputMedia -import dev.inmo.tgbotapi.requests.abstracts.* +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.parseModeField -import dev.inmo.tgbotapi.types.mediaField import kotlinx.serialization.* -import kotlinx.serialization.json.JsonElement internal const val videoInputMediaType = "video" +fun InputMediaVideo( + file: InputFile, + text: String? = null, + parseMode: ParseMode? = null, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaVideo(file, text, parseMode, null, width, height, duration, thumb) + +fun InputMediaVideo( + file: InputFile, + entities: List, + width: Int? = null, + height: Int? = null, + duration: Long? = null, + thumb: InputFile? = null +) = InputMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) + @Serializable -data class InputMediaVideo( +data class InputMediaVideo internal constructor ( override val file: InputFile, - override val caption: String? = null, + @SerialName(captionField) + override val text: String? = null, @SerialName(parseModeField) override val parseMode: ParseMode? = null, + @SerialName(captionEntitiesField) + private val rawEntities: List? = null, override val width: Int? = null, override val height: Int? = null, override val duration: Long? = null, override val thumb: InputFile? = null ) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, VisualMediaGroupMemberInputMedia { override val type: String = videoInputMediaType + override val entities: List? by lazy { + rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources() + } override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt index 83965179f8..7e63cc915b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/MediaGroupMemberInputMedia.kt @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput +import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput import kotlinx.serialization.* -import kotlinx.serialization.json.* +import kotlinx.serialization.json.Json internal val argumentsFormatter by lazy { Json { @@ -15,7 +16,10 @@ internal fun T.buildArguments(withSerializer: SerializationStrategy) = ar ) @Serializable(MediaGroupMemberInputMediaSerializer::class) -interface MediaGroupMemberInputMedia : InputMedia, CaptionedOutput { +interface MediaGroupMemberInputMedia : InputMedia, CaptionedOutput, TextedOutput { + @Deprecated("Will be removed in next major release") + override val caption: String? + get() = text fun serialize(format: StringFormat): String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt index 1bda788bf4..d2b51c84b1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InputMedia/ThumbedInputMedia.kt @@ -1,20 +1,7 @@ package dev.inmo.tgbotapi.types.InputMedia import dev.inmo.tgbotapi.requests.abstracts.* -import dev.inmo.tgbotapi.types.thumbField -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable interface ThumbedInputMedia : InputMedia { val thumb: InputFile? - @Serializable - @SerialName(thumbField) - @Deprecated("Will be removed due to useless state") - val thumbMedia: String? - get() = thumb ?.let { - when (it) { - is FileId -> it.fileId - is MultipartFile -> it.fileId.toInputMediaFileAttachmentName() - } - } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Location.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Location.kt deleted file mode 100644 index 0571bfaf1e..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Location.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.inmo.tgbotapi.types - -import dev.inmo.tgbotapi.CommonAbstracts.Locationed -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class Location( - @SerialName(longitudeField) - override val longitude: Double, - @SerialName(latitudeField) - override val latitude: Double -) : Locationed diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt index 942e6d1704..d8bff5f11d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/RawMessageEntity.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.User -import dev.inmo.tgbotapi.utils.shiftSourcesToTheLeft +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.shiftSourcesToTheLeft import kotlinx.serialization.Serializable @Serializable @@ -17,26 +17,29 @@ internal data class RawMessageEntity( val language: String? = null ) -internal fun RawMessageEntity.asTextParts(source: String, subParts: List): List { - val sourceSubstring = source.substring(offset, offset + length) +internal fun RawMessageEntity.asTextParts( + source: String, + subParts: List +): List { + val sourceSubstring: String = source.substring(offset, offset + length) val range = offset until (offset + length) - val shiftedSubParts = subParts.shiftSourcesToTheLeft(offset) + val shiftedSubSources = sourceSubstring.fullListOfSubSource(subParts.shiftSourcesToTheLeft(offset)).justTextSources() return when (type) { - "mention" -> MentionTextSource(sourceSubstring, shiftedSubParts) - "hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubParts) - "cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubParts) - "bot_command" -> BotCommandTextSource(sourceSubstring, shiftedSubParts) + "mention" -> MentionTextSource(sourceSubstring, shiftedSubSources) + "hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubSources) + "cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubSources) + "bot_command" -> BotCommandTextSource(sourceSubstring) "url" -> URLTextSource(sourceSubstring) - "email" -> EMailTextSource(sourceSubstring, shiftedSubParts) - "phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubParts) - "bold" -> BoldTextSource(sourceSubstring, shiftedSubParts) - "italic" -> ItalicTextSource(sourceSubstring, shiftedSubParts) + "email" -> EMailTextSource(sourceSubstring, shiftedSubSources) + "phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubSources) + "bold" -> BoldTextSource(sourceSubstring, shiftedSubSources) + "italic" -> ItalicTextSource(sourceSubstring, shiftedSubSources) "code" -> CodeTextSource(sourceSubstring) "pre" -> PreTextSource(sourceSubstring, language) "text_link" -> TextLinkTextSource(sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link")) - "text_mention" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), shiftedSubParts) - "underline" -> UnderlineTextSource(sourceSubstring, shiftedSubParts) - "strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubParts) + "text_mention" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), shiftedSubSources) + "underline" -> UnderlineTextSource(sourceSubstring, shiftedSubSources) + "strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubSources) else -> RegularTextSource(sourceSubstring) }.let { val part = TextPart(range, it) @@ -48,7 +51,7 @@ internal fun RawMessageEntity.asTextParts(source: String, subParts: List { +internal fun createTextPart(originalFullString: String, entities: RawMessageEntities): List { val mutableEntities = entities.toMutableList() mutableEntities.sortBy { it.offset } val resultList = mutableListOf() @@ -74,8 +77,8 @@ internal fun createTextPart(from: String, entities: RawMessageEntities): List.asRawMessageEntities() = mapNotNull { - val source = it.source - when (source) { - is MentionTextSource -> RawMessageEntity("mention", it.range.first, it.range.last - it.range.first) - is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, it.range.last - it.range.first) - is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, it.range.last - it.range.first) - is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, it.range.last - it.range.first) - is URLTextSource -> RawMessageEntity("url", it.range.first, it.range.last - it.range.first) - is EMailTextSource -> RawMessageEntity("email", it.range.first, it.range.last - it.range.first) - is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, it.range.last - it.range.first) - is BoldTextSource -> RawMessageEntity("bold", it.range.first, it.range.last - it.range.first) - is ItalicTextSource -> RawMessageEntity("italic", it.range.first, it.range.last - it.range.first) - is CodeTextSource -> RawMessageEntity("code", it.range.first, it.range.last - it.range.first) - is PreTextSource -> RawMessageEntity("pre", it.range.first, it.range.last - it.range.first, language = source.language) - is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, it.range.last - it.range.first, source.url) - is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, it.range.last - it.range.first, user = source.user) - is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, it.range.last - it.range.first) - is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, it.range.last - it.range.first) - else -> null +internal fun TextPart.asRawMessageEntities(): List { + val source = source + val length = range.last - range.first + 1 + + return listOfNotNull( + when (source) { + is MentionTextSource -> RawMessageEntity("mention", range.first, length) + is HashTagTextSource -> RawMessageEntity("hashtag", range.first, length) + is CashTagTextSource -> RawMessageEntity("cashtag", range.first, length) + is BotCommandTextSource -> RawMessageEntity("bot_command", range.first, length) + is URLTextSource -> RawMessageEntity("url", range.first, length) + is EMailTextSource -> RawMessageEntity("email", range.first, length) + is PhoneNumberTextSource -> RawMessageEntity("phone_number", range.first, length) + is BoldTextSource -> RawMessageEntity("bold", range.first, length) + is ItalicTextSource -> RawMessageEntity("italic", range.first, length) + is CodeTextSource -> RawMessageEntity("code", range.first, length) + is PreTextSource -> RawMessageEntity("pre", range.first, length, language = source.language) + is TextLinkTextSource -> RawMessageEntity("text_link", range.first, length, source.url) + is TextMentionTextSource -> RawMessageEntity("text_mention", range.first, length, user = source.user) + is UnderlineTextSource -> RawMessageEntity("underline", range.first, length) + is StrikethroughTextSource -> RawMessageEntity("strikethrough", range.first, length) + else -> null + } + ) + if (source is MultilevelTextSource) { + source.textParts(range.first).asRawMessageEntities() + } else { + emptyList() } } -internal fun RawMessageEntities.asTextParts(sourceString: String): List = createTextPart(sourceString, this) +internal fun List.asRawMessageEntities(): List = flatMap { it.asRawMessageEntities() } + +internal fun List.toTextParts(preOffset: Int = 0): List { + var i = preOffset + return map { + TextPart( + i until (i + it.source.length), + it + ).also { + i = it.range.last + 1 + } + } +} + +fun String.removeLeading(word: String) = if (startsWith(word)){ + substring(word.length) +} else { + this +} + +internal fun List.toRawMessageEntities(): List = toTextParts().asRawMessageEntities() + +internal fun RawMessageEntities.asTextParts(sourceString: String): List = sourceString.fullListOfSubSource( + createTextPart(sourceString, this) +) internal typealias RawMessageEntities = List diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index b5c2823022..64c1d3dee4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -1,15 +1,26 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.boldMarkdown +import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2 -class BoldTextSource( +/** + * @see bold + */ +data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.boldMarkdown() } override val asMarkdownV2Source: String by lazy { boldMarkdownV2() } override val asHtmlSource: String by lazy { boldHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun bold(parts: List) = BoldTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun bold(vararg parts: TextSource) = bold(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun bold(text: String) = bold(regular(text)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt index eb95d69313..8ca260ddf2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -1,25 +1,30 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.commandMarkdown +import dev.inmo.tgbotapi.utils.internal.commandMarkdownV2 private val commandRegex = Regex("[/!][^@\\s]*") -class BotCommandTextSource( - override val source: String, - textParts: List -) : MultilevelTextSource { +/** + * @see botCommand + */ +data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( + override val source: String +) : TextSource { val command: String by lazy { commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" } - override val textParts: List by lazy { - command.fullListOfSubSource( - textParts.shiftSourcesToTheLeft(1) - ) - } override val asMarkdownSource: String by lazy { source.commandMarkdown() } - override val asMarkdownV2Source: String by lazy { commandMarkdownV2() } - override val asHtmlSource: String by lazy { commandHTML() } + override val asMarkdownV2Source: String by lazy { source.commandMarkdownV2() } + override val asHtmlSource: String by lazy { source.commandHTML() } } + +/** + * @param command Without leading "/" + */ +@Suppress("NOTHING_TO_INLINE") +inline fun botCommand(command: String) = BotCommandTextSource("/$command") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index 13e490b753..221fd5712e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -1,15 +1,26 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.cashTagMarkdown +import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2 -class CashTagTextSource( +/** + * @see cashTag + */ +data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.cashTagMarkdown() } override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() } override val asHtmlSource: String by lazy { cashTagHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun cashTag(parts: List) = CashTagTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun cashTag(vararg parts: TextSource) = cashTag(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun cashTag(tag: String) = cashTag(regular(tag)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt index c47cbbdb91..86d4aae7cd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt @@ -1,12 +1,22 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources +import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.codeMarkdown +import dev.inmo.tgbotapi.utils.internal.codeMarkdownV2 -class CodeTextSource( +/** + * @see code + */ +data class CodeTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { override val asMarkdownSource: String by lazy { source.codeMarkdown() } override val asMarkdownV2Source: String by lazy { source.codeMarkdownV2() } override val asHtmlSource: String by lazy { source.codeHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun code(code: String) = CodeTextSource(code) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index f5c7450238..77704d1e69 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -1,15 +1,26 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.emailMarkdown +import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2 -class EMailTextSource( +/** + * @see email + */ +data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.emailMarkdown() } override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) } override val asHtmlSource: String by lazy { emailHTML(source) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun email(parts: List) = EMailTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun email(vararg parts: TextSource) = email(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun email(emailAddress: String) = email(regular(emailAddress)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index 2cd398ad47..37ecbe8861 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -1,26 +1,35 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.hashTagMarkdown +import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2 -private val String.withoutSharp - get() = if (startsWith("#")){ - substring(1) - } else { - this - } - -class HashTagTextSource( +/** + * @see hashtag + */ +data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { - source.withoutSharp.fullListOfSubSource( - textParts.shiftSourcesToTheLeft(1) - ) - } override val asMarkdownSource: String by lazy { source.hashTagMarkdown() } override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() } override val asHtmlSource: String by lazy { hashTagHTML() } + + init { + if (!source.startsWith("#")) { + error("HashTag source must starts with #, but actual value is \"$source\"") + } + } } + +@Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_API_USAGE") +inline fun hashtag(parts: List) = (regular("#") + parts).let { HashTagTextSource(it.makeString(), it) } +@Suppress("NOTHING_TO_INLINE") +inline fun hashtag(vararg parts: TextSource) = hashtag(parts.toList()) +/** + * Without sharp (#) + */ +@Suppress("NOTHING_TO_INLINE") +inline fun hashtag(hashtag: String) = hashtag(regular(hashtag)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index 0c8ed6fa61..887238f2bb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -1,15 +1,27 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.italicMarkdown +import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2 -class ItalicTextSource( +/** + * @see italic + */ +data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.italicMarkdown() } override val asMarkdownV2Source: String by lazy { italicMarkdownV2() } override val asHtmlSource: String by lazy { italicHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun italic(parts: List) = ItalicTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun italic(vararg parts: TextSource) = italic(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun italic(text: String) = italic(regular(text)) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index bd3ef1efa4..ef17ac5632 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.mentionMarkdown +import dev.inmo.tgbotapi.utils.internal.mentionMarkdownV2 private val String.withoutCommercialAt get() = if (startsWith("@")) { @@ -11,16 +13,32 @@ private val String.withoutCommercialAt this } -class MentionTextSource( +/** + * @see mention + */ +data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { - source.withoutCommercialAt.fullListOfSubSource( - textParts.shiftSourcesToTheLeft(1) - ) - } override val asMarkdownSource: String by lazy { source.mentionMarkdown() } override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() } override val asHtmlSource: String by lazy { mentionHTML() } + + init { + if (!source.startsWith("@")) { + error("Mention source must starts with @, but actual value is \"$source\"") + } + } } + +@Suppress("NOTHING_TO_INLINE") +inline fun mention(parts: List) = (regular("@") + parts).let { MentionTextSource(it.makeString(), it) } +@Suppress("NOTHING_TO_INLINE") +inline fun mention(vararg parts: TextSource) = mention(parts.toList()) + +/** + * Without leading "@" + */ +@Suppress("NOTHING_TO_INLINE") +inline fun mention(whoToMention: String) = mention(regular(whoToMention)) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index 6aabef80fa..321fb3f6f5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -1,15 +1,27 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.phoneMarkdown +import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2 -class PhoneNumberTextSource( +/** + * @see phone + */ +data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.phoneMarkdown() } override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() } override val asHtmlSource: String by lazy { phoneHTML() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun phone(parts: List) = PhoneNumberTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun phone(vararg parts: TextSource) = phone(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun phone(number: String) = phone(regular(number)) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt index efebe3d252..8ec55f8deb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt @@ -1,9 +1,15 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.preMarkdown +import dev.inmo.tgbotapi.utils.internal.preMarkdownV2 -class PreTextSource( +/** + * @see pre + */ +data class PreTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val language: String? = null ) : TextSource { @@ -11,3 +17,7 @@ class PreTextSource( override val asMarkdownV2Source: String by lazy { source.preMarkdownV2(language) } override val asHtmlSource: String by lazy { source.preHTML(language) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun pre(code: String, language: String? = null) = PreTextSource(code, language) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt index 4439bcaf4d..d70f3d1129 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt @@ -1,12 +1,21 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.regularMarkdown +import dev.inmo.tgbotapi.utils.internal.regularMarkdownV2 -class RegularTextSource( +/** + * @see regular + */ +data class RegularTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { override val asMarkdownSource: String by lazy { source.regularMarkdown() } override val asMarkdownV2Source: String by lazy { source.regularMarkdownV2() } override val asHtmlSource: String by lazy { source.regularHtml() } } + +@Suppress("NOTHING_TO_INLINE") +inline fun regular(text: String) = RegularTextSource(text) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index 63ec29c07f..b273b012c0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -1,15 +1,26 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdown +import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2 -class StrikethroughTextSource( +/** + * @see strikethrough + */ +data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asHtmlSource: String by lazy { strikethroughHTML() } override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() } override val asMarkdownSource: String by lazy { source.strikethroughMarkdown() } -} \ No newline at end of file +} + +@Suppress("NOTHING_TO_INLINE") +inline fun strikethrough(parts: List) = StrikethroughTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun strikethrough(vararg parts: TextSource) = strikethrough(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun strikethrough(text: String) = strikethrough(regular(text)) \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt index 82bc46c3b3..c0e3098dba 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt @@ -1,9 +1,15 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.linkMarkdown +import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2 -class TextLinkTextSource( +/** + * @see link + */ +data class TextLinkTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val url: String ) : TextSource { @@ -11,3 +17,6 @@ class TextLinkTextSource( override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(url) } override val asHtmlSource: String by lazy { source.linkHTML(url) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun link(text: String, url: String) = TextLinkTextSource(text, url) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index 5109236b1b..4ef48dbee6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -1,17 +1,28 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.textMentionMarkdown +import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2 -class TextMentionTextSource( +/** + * @see mention + */ +data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val user: User, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.textMentionMarkdown(user.id) } override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(user.id) } override val asHtmlSource: String by lazy { textMentionHTML(user.id) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun mention(parts: List, user: User) = TextMentionTextSource(parts.makeString(), user, parts) +@Suppress("NOTHING_TO_INLINE") +inline fun mention(user: User, vararg parts: TextSource) = mention(parts.toList(), user) +@Suppress("NOTHING_TO_INLINE") +inline fun mention(text: String, user: User) = mention(user, regular(text)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt index b5763b8538..4a5fb0825b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt @@ -1,12 +1,21 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.linkMarkdown +import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2 -class URLTextSource( +/** + * @see link + */ +data class URLTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { override val asMarkdownSource: String by lazy { source.linkMarkdown(source) } override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(source) } override val asHtmlSource: String by lazy { source.linkHTML(source) } } + +@Suppress("NOTHING_TO_INLINE") +inline fun link(url: String) = URLTextSource(url) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index 00a195bc0a..3523f12496 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -1,15 +1,26 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.underlineMarkdown +import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2 -class UnderlineTextSource( +/** + * @see underline + */ +data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - textParts: List + override val textSources: List ) : MultilevelTextSource { - override val textParts: List by lazy { source.fullListOfSubSource(textParts) } override val asMarkdownSource: String by lazy { source.underlineMarkdown() } override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() } override val asHtmlSource: String by lazy { underlineHTML() } -} \ No newline at end of file +} + +@Suppress("NOTHING_TO_INLINE") +inline fun underline(parts: List) = UnderlineTextSource(parts.makeString(), parts) +@Suppress("NOTHING_TO_INLINE") +inline fun underline(vararg parts: TextSource) = underline(parts.toList()) +@Suppress("NOTHING_TO_INLINE") +inline fun underline(text: String) = underline(regular(text)) \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt new file mode 100644 index 0000000000..d8c73228f7 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageId.kt @@ -0,0 +1,24 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.* + +object MessageIdSerializer : KSerializer { + override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor + + override fun deserialize(decoder: Decoder): MessageIdentifier = JsonObject.serializer().deserialize(decoder)[messageIdField]!!.jsonPrimitive.long + + override fun serialize(encoder: Encoder, value: MessageIdentifier) { + JsonObject.serializer().serialize( + encoder, + JsonObject( + mapOf( + messageIdField to JsonPrimitive(value) + ) + ) + ) + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt index 8a3ab256e0..c8a3be6343 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt @@ -2,11 +2,13 @@ package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.* +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject internal object InlineKeyboardButtonSerializer : KSerializer { @InternalSerializationApi diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt index 053e640183..23a27339a0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatSerializers.kt @@ -6,7 +6,8 @@ import dev.inmo.tgbotapi.types.chat.abstracts.UnknownChatType import dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat import dev.inmo.tgbotapi.types.chat.extended.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.* +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt index 2a6043809f..3e42f887d1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/ChannelChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface ChannelChat : SuperPublicChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt index 849d6b9e3a..591a565624 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/GroupChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface GroupChat : PublicChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt index 2459398282..65a254544b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt @@ -1,5 +1,9 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface PrivateChat : Chat, UsernameChat { val firstName: String val lastName: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt index 98c70cec84..f78e434f44 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PublicChat.kt @@ -1,5 +1,9 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface PublicChat : Chat { val title: String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt index 0403f89fa6..ce290dbe2f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SuperPublicChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface SuperPublicChat : PublicChat, UsernameChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt index f49d4d144f..d4ad4d90d2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/SupergroupChat.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable + +@Serializable(PreviewChatSerializer::class) interface SupergroupChat : GroupChat, SuperPublicChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt index 99ced04a6a..eb2149799f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/UsernameChat.kt @@ -1,7 +1,10 @@ package dev.inmo.tgbotapi.types.chat.abstracts import dev.inmo.tgbotapi.types.Username +import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable +@Serializable(PreviewChatSerializer::class) interface UsernameChat : Chat { val username: Username? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt index 424e9cd9d7..e21d2e314b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedChannelChat.kt @@ -1,5 +1,11 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended +import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import kotlinx.serialization.Serializable -interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat +@Serializable(ExtendedChatSerializer::class) +interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat { + val linkedGroupChatId: ChatId? +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt index df9c9e157b..a24939a299 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedGroupChat.kt @@ -1,8 +1,11 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended import dev.inmo.tgbotapi.types.chat.ChatPermissions +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedGroupChat : GroupChat, ExtendedPublicChat { val permissions: ChatPermissions } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt index e88ca5fa9f..55a03723a5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedPrivateChat.kt @@ -1,5 +1,10 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.PrivateChat +import kotlinx.serialization.Serializable -interface ExtendedPrivateChat : PrivateChat, ExtendedChat +@Serializable(ExtendedChatSerializer::class) +interface ExtendedPrivateChat : PrivateChat, ExtendedChat { + val bio: String +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt index f850ac7601..fc50b3bd37 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/extended/ExtendedSupergroupChat.kt @@ -1,10 +1,15 @@ package dev.inmo.tgbotapi.types.chat.abstracts.extended -import dev.inmo.tgbotapi.types.StickerSetName +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.ExtendedChatSerializer import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat { val slowModeDelay: Long? val stickerSetName: StickerSetName? val canSetStickerSet: Boolean + val linkedChannelChatId: ChatId? + val location: ChatLocation? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt index f7a050628b..d632a1f04d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedChannelChatImpl.kt @@ -23,5 +23,7 @@ data class ExtendedChannelChatImpl( override val inviteLink: String? = null, @SerialName(pinnedMessageField) @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) - override val pinnedMessage: Message? = null + override val pinnedMessage: Message? = null, + @SerialName(linkedChatIdField) + override val linkedGroupChatId: ChatId? = null ) : ExtendedChannelChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt index d507fcfea3..4c1d9702de 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedPrivateChatImpl.kt @@ -16,5 +16,7 @@ data class ExtendedPrivateChatImpl( @SerialName(firstNameField) override val firstName: String = "", @SerialName(lastNameField) - override val lastName: String = "" + override val lastName: String = "", + @SerialName(bioField) + override val bio: String = "" ) : ExtendedPrivateChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt index 1e10877159..df17d30760 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/extended/ExtendedSupergroupChatImpl.kt @@ -32,5 +32,9 @@ data class ExtendedSupergroupChatImpl( @SerialName(slowModeDelayField) override val slowModeDelay: Long? = null, @SerialName(canSetStickerSetField) - override val canSetStickerSet: Boolean = false + override val canSetStickerSet: Boolean = false, + @SerialName(linkedChatIdField) + override val linkedChannelChatId: ChatId? = null, + @SerialName(locationField) + override val location: ChatLocation? = null ) : ExtendedSupergroupChat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt index 74ded7764f..7a79ba36dd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/dice/DiceAnimationType.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.dice +import dev.inmo.tgbotapi.types.* import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder @@ -8,27 +9,45 @@ import kotlinx.serialization.encoding.Encoder @Serializable(DiceAnimationTypeSerializer::class) sealed class DiceAnimationType { abstract val emoji: String + abstract val valueLimits: IntRange } @Serializable(DiceAnimationTypeSerializer::class) object CubeDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFB2" + override val valueLimits: IntRange + get() = dartsAndCubeDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) object DartsDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFAF" + override val valueLimits: IntRange + get() = dartsAndCubeDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) object BasketballDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFC0" + override val valueLimits: IntRange + get() = basketballAndFootballDiceResultLimit +} +@Serializable(DiceAnimationTypeSerializer::class) +object FootballDiceAnimationType : DiceAnimationType() { + override val emoji: String = "âš½" + override val valueLimits: IntRange + get() = basketballAndFootballDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) object SlotMachineDiceAnimationType : DiceAnimationType() { override val emoji: String = "\uD83C\uDFB0" + override val valueLimits: IntRange + get() = slotMachineDiceResultLimit } @Serializable(DiceAnimationTypeSerializer::class) data class CustomDiceAnimationType( override val emoji: String -) : DiceAnimationType() +) : DiceAnimationType() { + override val valueLimits: IntRange + get() = error("Custom dice animation type have unknown value limits") +} @Serializer(DiceAnimationType::class) internal object DiceAnimationTypeSerializer : KSerializer { @@ -39,6 +58,7 @@ internal object DiceAnimationTypeSerializer : KSerializer { DartsDiceAnimationType.emoji -> DartsDiceAnimationType BasketballDiceAnimationType.emoji -> BasketballDiceAnimationType SlotMachineDiceAnimationType.emoji -> SlotMachineDiceAnimationType + FootballDiceAnimationType.emoji -> FootballDiceAnimationType else -> CustomDiceAnimationType(type) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt index af686eda9b..554b878069 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt @@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.CommonAbstracts.Performerable import dev.inmo.tgbotapi.requests.abstracts.FileId -import dev.inmo.tgbotapi.types.FileUniqueId -import dev.inmo.tgbotapi.types.fileUniqueIdField +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName @@ -15,14 +14,20 @@ data class AudioFile( override val fileId: FileId, @SerialName(fileUniqueIdField) override val fileUniqueId: FileUniqueId, + @SerialName(durationField) override val duration: Long? = null, + @SerialName(performerField) override val performer: String? = null, + @SerialName(titleField) override val title: String? = null, + @SerialName(fileNameField) + override val fileName: String? = null, @SerialName(mimeTypeField) override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, + @SerialName(thumbField) override val thumb: PhotoSize? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, Performerable +) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, Performerable fun AudioFile.asVoiceFile() = VoiceFile(fileId, fileUniqueId, duration, mimeType, fileSize) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index 5780caa07c..eebd6ea018 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -1,14 +1,11 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.requests.abstracts.FileId -import dev.inmo.tgbotapi.types.FileUniqueId +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo -import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.fileUniqueIdField import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.utils.MimeType -import dev.inmo.tgbotapi.utils.toHtmlCaptions import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -18,15 +15,21 @@ data class VideoFile( override val fileId: FileId, @SerialName(fileUniqueIdField) override val fileUniqueId: FileUniqueId, + @SerialName(widthField) override val width: Int, + @SerialName(heightField) override val height: Int, + @SerialName(durationField) override val duration: Long? = null, + @SerialName(thumbField) override val thumb: PhotoSize? = null, + @SerialName(fileNameField) + override val fileName: String? = null, @SerialName(mimeTypeField) override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile +) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toInputMediaVideo( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt index f2bea226f2..41be71b854 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VoiceFile.kt @@ -23,5 +23,6 @@ data class VoiceFile( fun VoiceFile.asAudioFile( performer: String? = null, - title: String? = null -) = AudioFile(fileId, fileUniqueId, duration, performer, title, mimeType, fileSize) + title: String? = null, + fileName: String? = null +) = AudioFile(fileId, fileUniqueId, duration, performer, title, fileName, mimeType, fileSize) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt new file mode 100644 index 0000000000..b8b9878429 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/location/Location.kt @@ -0,0 +1,57 @@ +package dev.inmo.tgbotapi.types.location + +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.nonstrictJsonFormat +import kotlinx.serialization.* +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject + +@Serializable(LocationSerializer::class) +sealed class Location : Locationed, HorizontallyAccured + +@Serializable +data class StaticLocation( + @SerialName(longitudeField) + override val longitude: Double, + @SerialName(latitudeField) + override val latitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null +) : Location() + +@Serializable +data class LiveLocation( + @SerialName(longitudeField) + override val longitude: Double, + @SerialName(latitudeField) + override val latitude: Double, + @SerialName(horizontalAccuracyField) + override val horizontalAccuracy: Meters? = null, + @SerialName(livePeriodField) + override val livePeriod: Seconds, + @SerialName(headingField) + override val heading: Degrees? = null, + @SerialName(proximityAlertRadiusField) + override val proximityAlertRadius: Meters? = null +) : Location(), Livable, ProximityAlertable, Headed + +@Serializer(Location::class) +object LocationSerializer : KSerializer { + override fun deserialize(decoder: Decoder): Location = JsonObject.serializer().deserialize(decoder).let { + if (it.containsKey(livePeriodField) && it[livePeriodField] != JsonNull) { + nonstrictJsonFormat.decodeFromJsonElement(LiveLocation.serializer(), it) + } else { + nonstrictJsonFormat.decodeFromJsonElement(StaticLocation.serializer(), it) + } + } + + override fun serialize(encoder: Encoder, value: Location) { + when (value) { + is StaticLocation -> StaticLocation.serializer().serialize(encoder, value) + is LiveLocation -> LiveLocation.serializer().serialize(encoder, value) + } + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt index d0cbd5cf4b..ce972e7d52 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt @@ -1,10 +1,10 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage -import com.soywiz.klock.DateTime data class ChannelEventMessage( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt index d77100871f..70d670d41e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -7,7 +8,6 @@ import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -import com.soywiz.klock.DateTime data class ChannelMediaGroupMessage( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt similarity index 58% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessage.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt index bc4e26c60e..ba28d6c5ba 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt @@ -1,16 +1,16 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup -import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage -import com.soywiz.klock.DateTime -data class ChannelMessage( +data class ChannelMessageImpl( override val messageId: MessageIdentifier, - override val chat: Chat, + override val chat: ChannelChat, override val content: T, override val date: DateTime, override val editDate: DateTime?, @@ -18,5 +18,8 @@ data class ChannelMessage( override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, - val authorSignature: AuthorSignature? -) : PossiblySentViaBotCommonMessage + override val authorSignature: AuthorSignature? +) : ChannelMessage + +@Deprecated("Renamed", ReplaceWith("ChannelMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelMessageImpl")) +typealias ChannelMessage = ChannelMessageImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt new file mode 100644 index 0000000000..e502522020 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ProximityAlertTriggered.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents + +import dev.inmo.tgbotapi.types.Meters +import dev.inmo.tgbotapi.types.User +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent +import kotlinx.serialization.Serializable + +/** + * This object represents the content of a service message, sent whenever a user in the chat triggers a proximity alert + * set by another user. + */ +@Serializable +data class ProximityAlertTriggered( + val traveler: User, + val watcher: User, + val distance: Meters +) : CommonEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt index 6117b923c7..d55134b6c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage -import com.soywiz.klock.DateTime @Deprecated("Renamed", ReplaceWith("CommonGroupEventMessage")) typealias GroupEventMessage = CommonGroupEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt index 248f7da715..2694c7d187 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -import com.soywiz.klock.DateTime data class CommonMediaGroupMessage( override val messageId: MessageIdentifier, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt index 36e218907f..f5a382888e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage -import com.soywiz.klock.DateTime @Deprecated("Renamed", ReplaceWith("CommonSupergroupEventMessage")) typealias SupergroupEventMessage = CommonSupergroupEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt new file mode 100644 index 0000000000..8a72fc3393 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -0,0 +1,48 @@ +package dev.inmo.tgbotapi.types.message + +import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat +import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent + +data class FromChannelGroupMessageImpl( + override val chat: GroupChat, + override val channel: ChannelChat, + override val messageId: MessageIdentifier, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot?, + override val authorSignature: AuthorSignature? +) : FromChannelGroupMessage + +data class AnonymousGroupMessageImpl( + override val chat: GroupChat, + override val messageId: MessageIdentifier, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot?, + override val authorSignature: AuthorSignature? +) : AnonymousGroupMessage + +data class CommonGroupMessageImpl( + override val chat: GroupChat, + override val messageId: MessageIdentifier, + override val date: DateTime, + override val forwardInfo: ForwardInfo?, + override val editDate: DateTime?, + override val replyTo: Message?, + override val replyMarkup: InlineKeyboardMarkup?, + override val content: T, + override val senderBot: CommonBot? +) : CommonGroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt similarity index 73% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMessageImpl.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt index b0f51180ea..232fb6a88a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt @@ -1,16 +1,15 @@ package dev.inmo.tgbotapi.types.message +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.abstracts.PrivateMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo -import com.soywiz.klock.DateTime -data class CommonMessageImpl( +data class PrivateMessageImpl( override val messageId: MessageIdentifier, override val user: User, override val chat: Chat, @@ -22,4 +21,7 @@ data class CommonMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, val paymentInfo: SuccessfulPaymentInfo? -) : PossiblySentViaBotCommonMessage, FromUserMessage \ No newline at end of file +) : PrivateMessage + +@Deprecated("Renamed", ReplaceWith("PrivateMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateMessageImpl")) +typealias CommonMessageImpl = PrivateMessageImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 5f6991b77a..cfccea7958 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.* import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.games.RawGame +import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -30,12 +31,10 @@ import kotlin.reflect.KClass internal data class RawMessage( @SerialName(messageIdField) val messageId: MessageIdentifier, - @SerialName(dateField) val date: TelegramDate, - @SerialName(chatField) private val chat: Chat, - @SerialName(fromField) private val from: User? = null, + private val sender_chat: PublicChat? = null, private val forward_from: User? = null, private val forward_from_chat: Chat? = null, private val forward_from_message_id: MessageIdentifier? = null, @@ -86,16 +85,17 @@ internal data class RawMessage( // passport property private val passport_data: Unit? = null, + private val proximity_alert_triggered: ProximityAlertTriggered? = null, private val reply_markup: InlineKeyboardMarkup? = null ) { private val content: MessageContent? by lazy { val adaptedCaptionEntities = caption ?.let { - caption_entities ?.asTextParts(caption) + (caption_entities ?: emptyList()).asTextParts(caption) } ?: emptyList() when { - text != null -> TextContent(text, entities ?.asTextParts(text) ?: emptyList()) + text != null -> TextContent(text, (entities ?: emptyList()).asTextParts(text)) audio != null -> AudioContent( audio, caption, @@ -180,6 +180,7 @@ internal data class RawMessage( ) channel_chat_created -> ChannelChatCreated() pinned_message != null -> PinnedMessage(pinned_message.asMessage) + proximity_alert_triggered != null -> proximity_alert_triggered else -> null } } @@ -253,19 +254,61 @@ internal data class RawMessage( ) } } ?: when (chat) { - is ChannelChat -> ChannelMessage( - messageId, - chat, - content, - date.asDate, - edit_date?.asDate, - forwarded, - reply_to_message?.asMessage, - reply_markup, - via_bot, - author_signature - ) - else -> CommonMessageImpl( + is PublicChat -> when (chat) { + is ChannelChat -> ChannelMessageImpl( + messageId, + chat, + content, + date.asDate, + edit_date?.asDate, + forwarded, + reply_to_message?.asMessage, + reply_markup, + via_bot, + author_signature + ) + is GroupChat -> when (sender_chat) { + is ChannelChat -> FromChannelGroupMessageImpl( + chat, + sender_chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + is GroupChat -> AnonymousGroupMessageImpl( + chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot, + author_signature + ) + null -> CommonGroupMessageImpl( + chat, + messageId, + date.asDate, + forwarded, + edit_date ?.asDate, + reply_to_message ?.asMessage, + reply_markup, + content, + via_bot + ) + else -> error("Currently in groups supported only fields \"sender_chat\" with channel, group or null, but was $sender_chat") + } + else -> error("Unknown type of public chat: $chat") + } + is PrivateChat -> PrivateMessageImpl( messageId, from ?: error("Was detected common message, but owner (sender) of the message was not found"), chat, @@ -278,6 +321,7 @@ internal data class RawMessage( via_bot, paymentInfo ) + else -> error("Unknown type of chat: $chat") } } ?: error("Was not found supported type of data") } catch (e: Exception) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt new file mode 100644 index 0000000000..2ef124d5b1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage + +interface ChannelMessage : PossiblySentViaBotCommonMessage, SignedMessage, WithSenderChatMessage { + override val chat: ChannelChat + override val senderChat: ChannelChat + get() = chat +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt new file mode 100644 index 0000000000..0338591bcb --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat +import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent + +interface GroupMessage : PublicMessage { + override val chat: GroupChat +} + +interface FromChannelGroupMessage : GroupMessage, SignedMessage, WithSenderChatMessage { + val channel: ChannelChat + override val senderChat: ChannelChat + get() = channel +} +interface AnonymousGroupMessage : GroupMessage, SignedMessage, WithSenderChatMessage { + override val senderChat: GroupChat + get() = chat +} +interface CommonGroupMessage : GroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt index 2d45b0dba1..3bf616a482 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/Message.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.types.message.abstracts +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.RawMessage -import com.soywiz.klock.DateTime import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt new file mode 100644 index 0000000000..f57d2ce731 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage + +interface PrivateMessage : PossiblySentViaBotCommonMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt new file mode 100644 index 0000000000..1ab4b3786c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage + +interface PublicMessage : PossiblySentViaBotCommonMessage { + override val chat: PublicChat +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt new file mode 100644 index 0000000000..18aabe8616 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SignedMessage.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.AuthorSignature + +interface SignedMessage : Message { + val authorSignature: AuthorSignature? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt new file mode 100644 index 0000000000..55147cd92a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/WithSenderChatMessage.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.abstracts + +import dev.inmo.tgbotapi.types.chat.abstracts.Chat + +interface WithSenderChatMessage { + val senderChat: Chat +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt index 8802c91830..20d0c73370 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/ContactContent.kt @@ -14,8 +14,9 @@ data class ContactContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendContact( - chatId, contact, disableNotification, replyToMessageId, replyMarkup + chatId, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt index c287d15281..891f848d56 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/DiceContent.kt @@ -16,12 +16,14 @@ data class DiceContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendDice( chatId, dice.animationType, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt index a58505616b..5e7b21f9d9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/GameContent.kt @@ -16,12 +16,14 @@ data class GameContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendGame( chatId, game.title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt index 81f41ef536..36c5d90f35 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/LocationContent.kt @@ -1,12 +1,17 @@ package dev.inmo.tgbotapi.types.message.content import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.requests.send.SendLocation -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.requests.send.SendLiveLocation +import dev.inmo.tgbotapi.requests.send.SendStaticLocation +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent +import kotlinx.serialization.Serializable +@Serializable data class LocationContent( val location: Location ) : MessageContent { @@ -14,14 +19,30 @@ data class LocationContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? - ): Request> = SendLocation( - chatId, - location.latitude, - location.longitude, - null, - disableNotification, - replyToMessageId, - replyMarkup - ) + ): Request> = when (location) { + is StaticLocation -> SendStaticLocation( + chatId, + location.latitude, + location.longitude, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) + is LiveLocation -> SendLiveLocation( + chatId, + location.latitude, + location.longitude, + location.livePeriod, + location.horizontalAccuracy, + location.heading, + location.proximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) + } } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt index 074d7d7896..ddb139e0d6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PollContent.kt @@ -16,11 +16,13 @@ data class PollContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = poll.createRequest( chatId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index 270a6bab3e..08a2d23a34 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.types.message.content -import dev.inmo.tgbotapi.CommonAbstracts.FullTextSourcesList +import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.SendTextMessage @@ -10,7 +10,9 @@ import dev.inmo.tgbotapi.types.ParseMode.* import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.utils.internal.* +import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource +import dev.inmo.tgbotapi.utils.internal.toMarkdownTexts data class TextContent( val text: String, @@ -24,6 +26,7 @@ data class TextContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendTextMessage( chatId, @@ -32,6 +35,7 @@ data class TextContent( false, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) @@ -39,11 +43,13 @@ data class TextContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): List>> = createResends( chatId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup, HTMLParseMode ) @@ -52,6 +58,7 @@ data class TextContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup?, parseMode: ParseMode = HTMLParseMode ): List>> = when (parseMode) { @@ -66,6 +73,7 @@ data class TextContent( false, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) } @@ -75,4 +83,4 @@ data class TextContent( * Convert its [TextContent.entities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ -fun TextContent.fullEntitiesList(): FullTextSourcesList = text.fullListOfSubSource(entities).map { it.source } +fun TextContent.fullEntitiesList(): TextSourcesList = text.fullListOfSubSource(entities).map { it.source } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt index 9b662e8133..60a355afe1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VenueContent.kt @@ -16,8 +16,9 @@ data class VenueContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendVenue( - chatId, venue, disableNotification, replyToMessageId, replyMarkup + chatId, venue, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt index 8707e351ee..f0b1993573 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt @@ -11,6 +11,7 @@ interface ResendableContent { chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request @@ -18,6 +19,7 @@ interface ResendableContent { chatId: ChatIdentifier, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null - ): List> = listOf(createResend(chatId, disableNotification, replyToMessageId, replyMarkup)) + ): List> = listOf(createResend(chatId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt index 2d5c4b8ca8..f0cf652083 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AnimationContent.kt @@ -14,8 +14,8 @@ import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class AnimationContent( override val media: AnimationFile, @@ -27,6 +27,7 @@ data class AnimationContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendAnimation( chatId, @@ -39,6 +40,7 @@ data class AnimationContent( media.height, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt index e662354d3a..b326522b96 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/AudioContent.kt @@ -4,16 +4,15 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendAudio import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio +import dev.inmo.tgbotapi.types.InputMedia.toInputMediaAudio import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.* -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class AudioContent( override val media: AudioFile, @@ -24,6 +23,7 @@ data class AudioContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendAudio( chatId, @@ -36,6 +36,7 @@ data class AudioContent( media.title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt index f69c415813..8ff70ac761 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/DocumentContent.kt @@ -5,17 +5,17 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendDocument import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument +import dev.inmo.tgbotapi.types.InputMedia.toInputMediaDocument import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.files.asDocumentFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.* -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class DocumentContent( override val media: DocumentFile, @@ -26,6 +26,7 @@ data class DocumentContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendDocument( chatId, @@ -35,6 +36,7 @@ data class DocumentContent( HTMLParseMode, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt index de7b9eb17a..9a7ceabb4c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/PhotoContent.kt @@ -4,16 +4,16 @@ import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendPhoto import dev.inmo.tgbotapi.types.ChatIdentifier -import dev.inmo.tgbotapi.types.InputMedia.* +import dev.inmo.tgbotapi.types.InputMedia.InputMediaPhoto +import dev.inmo.tgbotapi.types.InputMedia.toInputMediaPhoto import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.* -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent +import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class PhotoContent( override val mediaCollection: Photo, @@ -26,6 +26,7 @@ data class PhotoContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendPhoto( chatId, @@ -34,6 +35,7 @@ data class PhotoContent( HTMLParseMode, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt index 68c5edc783..7b0ab518e2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt @@ -17,12 +17,14 @@ data class StickerContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendSticker( chatId, media.fileId, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt index 1049043f37..aa5b4185bb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoContent.kt @@ -5,18 +5,14 @@ import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.media.SendVideo import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo -import dev.inmo.tgbotapi.types.InputMedia.MediaGroupMemberInputMedia import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode -import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VideoFile import dev.inmo.tgbotapi.types.files.toInputMediaVideo import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions data class VideoContent( override val media: VideoFile, @@ -27,6 +23,7 @@ data class VideoContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendVideo( chatId, @@ -40,6 +37,7 @@ data class VideoContent( null, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt index 4957e19853..848e6bb1e9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VideoNoteContent.kt @@ -5,7 +5,6 @@ import dev.inmo.tgbotapi.requests.send.media.SendVideoNote import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VideoNoteFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage @@ -18,26 +17,17 @@ data class VideoNoteContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? - ): Request> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup) - - fun createResend( - chatId: ChatIdentifier, - caption: String?, - parseMode: ParseMode? = null, - disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null ): Request> = SendVideoNote( chatId, media.fileId, media.thumb ?.fileId, - caption, - parseMode, media.duration, media.width, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt index 1aa62d14ef..6a9894444f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/VoiceContent.kt @@ -13,8 +13,8 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.files.VoiceFile import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent -import dev.inmo.tgbotapi.utils.toHtmlCaptions -import dev.inmo.tgbotapi.utils.toMarkdownV2Captions +import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions data class VoiceContent( override val media: VoiceFile, @@ -25,6 +25,7 @@ data class VoiceContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> = SendVoice( chatId, @@ -34,6 +35,7 @@ data class VoiceContent( media.duration, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt index 35341e8dc5..b7dcca1c12 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/payments/InvoiceContent.kt @@ -15,6 +15,7 @@ data class InvoiceContent( chatId: ChatIdentifier, disableNotification: Boolean, replyToMessageId: MessageIdentifier?, + allowSendingWithoutReply: Boolean?, replyMarkup: KeyboardMarkup? ): Request> { error("Unfortunately, currently InvoiceOfPayment can not be resend due to requirement of additional parameters," + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt index 4cfdfe19c3..709fc5c9fe 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/polls/Poll.kt @@ -1,11 +1,12 @@ package dev.inmo.tgbotapi.types.polls -import dev.inmo.tgbotapi.CommonAbstracts.* +import com.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan +import dev.inmo.tgbotapi.CommonAbstracts.ExplainedInput +import dev.inmo.tgbotapi.CommonAbstracts.TextPart import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import com.soywiz.klock.DateTime -import com.soywiz.klock.TimeSpan import kotlinx.serialization.* import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt index 415a00e963..b27c18e1e7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/venue/Venue.kt @@ -3,13 +3,14 @@ package dev.inmo.tgbotapi.types.venue import dev.inmo.tgbotapi.CommonAbstracts.CommonVenueData import dev.inmo.tgbotapi.CommonAbstracts.Locationed import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class Venue( @SerialName(locationField) - val location: Location, + val location: StaticLocation, @SerialName(titleField) override val title: String, @SerialName(addressField) @@ -17,5 +18,9 @@ data class Venue( @SerialName(foursquareIdField) override val foursquareId: FoursquareId? = null, @SerialName(foursquareTypeField) - override val foursquareType: FoursquareType? = null + override val foursquareType: FoursquareType? = null, + @SerialName(googlePlaceIdField) + override val googlePlaceId: GooglePlaceId? = null, + @SerialName(googlePlaceTypeField) + override val googlePlaceType: GooglePlaceType? = null ) : CommonVenueData, Locationed by location diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt index 148d08835d..6f93f28984 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/HandleSafely.kt @@ -1,23 +1,21 @@ package dev.inmo.tgbotapi.utils +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.supervisorScope -typealias ExceptionHandler = suspend (Throwable) -> T +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("ExceptionHandler", "dev.inmo.micro_utils.coroutines.ExceptionHandler")) +typealias ExceptionHandler = ExceptionHandler /** * It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions * * @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this * exception will be available for catching */ +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely")) suspend inline fun handleSafely( noinline onException: ExceptionHandler = { throw it }, noinline block: suspend CoroutineScope.() -> T -): T { - return try { - supervisorScope(block) - } catch (e: Throwable) { - onException(e) - } -} +): T = safely(onException, block) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt index 5ee622b20f..a5beeeb0ca 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.utils import com.benasher44.uuid.uuid4 +import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.Input import kotlinx.serialization.Serializable @@ -18,3 +19,17 @@ data class StorageFile( ) { fun asInput() = inputSource() } + +@Suppress("NOTHING_TO_INLINE") +inline fun StorageFile( + fileName: String, + bytes: ByteArray, + mimeType: MimeType +) = StorageFile( + StorageFileInfo(mimeType.raw, fileName) +) { + ByteReadPacket(bytes) +} + +@Suppress("NOTHING_TO_INLINE") +inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt index f6876dbe8e..1e8770804d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.utils +const val telegramBotAPIDefaultUrl = "https://api.telegram.org" + class TelegramAPIUrlsKeeper( token: String, - hostUrl: String = "https://api.telegram.org" + hostUrl: String = telegramBotAPIDefaultUrl ) { val commonAPIUrl = "$hostUrl/bot$token" val fileBaseUrl = "$hostUrl/file/bot$token" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt index 88c9946627..03d00bc88b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/ThrowErrorWithRange.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.utils -internal fun throwRangeError( +internal fun > throwRangeError( valueName: String, - range: IntRange, - actualValue: Int + range: ClosedRange, + actualValue: T ): Nothing = error("$valueName must be in range $range, but was $actualValue") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt index 4094709bce..d936e4764c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt @@ -11,48 +11,6 @@ private sealed class DebounceAction { private data class AddValue(override val value: T) : DebounceAction() private data class RemoveJob(override val value: T, val job: Job) : DebounceAction() -@Deprecated("Unused and will be removed in next major release") -fun ReceiveChannel.debounceByValue( - delayMillis: Long, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default), - resultBroadcastChannelCapacity: Int = 32 -): ReceiveChannel { - val outChannel = Channel(resultBroadcastChannelCapacity) - val values = HashMap() - - val channel = Channel>(Channel.UNLIMITED) - scope.launch { - for (action in channel) { - when (action) { - is AddValue -> { - val msg = action.value - values[msg] ?.cancel() - lateinit var job: Job - job = launch { - delay(delayMillis) - - outChannel.send(msg) - channel.send(RemoveJob(msg, job)) - } - values[msg] = job - } - is RemoveJob -> if (values[action.value] == action.job) { - values.remove(action.value) - } - } - - } - } - - scope.launch { - for (msg in this@debounceByValue) { - channel.send(AddValue(msg)) - } - } - - return outChannel -} - typealias AccumulatedValues = Pair> fun ReceiveChannel>.accumulateByKey( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt similarity index 98% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt index 07efbe4b31..5e4cc86d4f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/BaseMessageUpdateToMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/BaseMessageUpdateToMediaGroupUpdate.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt similarity index 79% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt index 715c9d41d0..a1c9d049af 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/CaptionAndTextSourcesToText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.fullEntitiesList internal fun createFormattedText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last, mode: ParseMode = MarkdownParseMode ): List { @@ -48,17 +48,17 @@ internal fun createFormattedText( internal fun createMarkdownText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownParseMode) -internal fun FullTextSourcesList.toMarkdownTexts(): List = createMarkdownText( +internal fun TextSourcesList.toMarkdownTexts(): List = createMarkdownText( this, textLength.last ) internal fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() -internal fun FullTextSourcesList.toMarkdownExplanations(): List = createMarkdownText( +internal fun TextSourcesList.toMarkdownExplanations(): List = createMarkdownText( this, explanationLimit.last ) @@ -66,23 +66,23 @@ internal fun ExplainedInput.toMarkdownExplanations(): List = fullEntitie internal fun createMarkdownV2Text( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownV2ParseMode) -internal fun FullTextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( +internal fun TextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( this, captionLength.last ) internal fun CaptionedInput.toMarkdownV2Captions(): List = fullEntitiesList().toMarkdownV2Captions() -internal fun FullTextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( +internal fun TextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( this, textLength.last ) internal fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() -internal fun FullTextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( +internal fun TextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( this, explanationLimit.last ) @@ -90,17 +90,17 @@ internal fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntit internal fun createHtmlText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, HTMLParseMode) -internal fun FullTextSourcesList.toHtmlCaptions(): List = createHtmlText( +internal fun TextSourcesList.toHtmlCaptions(): List = createHtmlText( this, captionLength.last ) internal fun CaptionedInput.toHtmlCaptions(): List = fullEntitiesList().toHtmlCaptions() -internal fun FullTextSourcesList.toHtmlTexts(): List = createHtmlText( +internal fun TextSourcesList.toHtmlTexts(): List = createHtmlText( this, textLength.last ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt similarity index 71% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index 23869d4946..69e44e5d6c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -1,7 +1,6 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal -import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.link @@ -73,30 +72,40 @@ internal fun List.shiftSourcesToTheLeft(shiftCount: Int = 1): List.joinSubSourcesMarkdownV2() = joinToString("") { - it.source.asMarkdownV2Source +private fun List.joinSubSourcesMarkdownV2() = joinToString("") { + it.asMarkdownV2Source } -private fun List.joinSubSourcesHtml() = joinToString("") { - it.source.asHtmlSource +private fun List.joinSubSourcesHtml() = joinToString("") { + it.asHtmlSource } internal fun MultilevelTextSource.markdownV2Default( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "$openControlSymbol${textParts.joinSubSourcesMarkdownV2()}$closeControlSymbol" +) = "$openControlSymbol${textSources.joinSubSourcesMarkdownV2()}$closeControlSymbol" internal fun MultilevelTextSource.htmlDefault( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "<$openControlSymbol>${textParts.joinSubSourcesHtml()}" +) = "<$openControlSymbol>${textSources.joinSubSourcesHtml()}" internal fun MultilevelTextSource.linkMarkdownV2( link: String -) = "[${textParts.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})" +) = "[${textSources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})" internal fun MultilevelTextSource.linkHTML( link: String -) = "${textParts.joinSubSourcesHtml()}" +) = "${textSources.joinSubSourcesHtml()}" + + +internal fun MultilevelTextSource.optionalPrefix( + mustStartsWith: String, + controlWord: String = mustStartsWith +) = if (source.startsWith(mustStartsWith)) { + "" +} else { + controlWord +} internal fun MultilevelTextSource.emailMarkdownV2(address: String): String = linkMarkdownV2("mailto://$address") @@ -107,8 +116,8 @@ internal fun MultilevelTextSource.boldMarkdownV2(): String = markdownV2Default(m internal fun MultilevelTextSource.boldHTML(): String = htmlDefault(htmlBoldControl) -internal fun MultilevelTextSource.cashTagMarkdownV2(): String = textParts.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.cashTagHTML(): String = textParts.joinSubSourcesHtml() +internal fun MultilevelTextSource.cashTagMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.cashTagHTML(): String = textSources.joinSubSourcesHtml() internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl) @@ -126,18 +135,21 @@ internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnde internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link) -internal fun MultilevelTextSource.mentionMarkdownV2(): String = "@${textParts.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.mentionHTML(): String = "@${textParts.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + textSources.joinSubSourcesHtml() -internal fun MultilevelTextSource.hashTagMarkdownV2(): String = "\\#${textParts.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.hashTagHTML(): String = "#${textParts.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.hashTagMarkdownV2(): String = when { + source.startsWith("\\#") || source.startsWith("#") -> "" + else -> "\\#" +} + textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + textSources.joinSubSourcesHtml() -internal fun MultilevelTextSource.phoneMarkdownV2(): String = textParts.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.phoneHTML(): String = textParts.joinSubSourcesHtml() +internal fun MultilevelTextSource.phoneMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.phoneHTML(): String = textSources.joinSubSourcesHtml() -internal fun MultilevelTextSource.commandMarkdownV2(): String = "/${textParts.joinSubSourcesMarkdownV2()}" -internal fun MultilevelTextSource.commandHTML(): String = "/${textParts.joinSubSourcesHtml()}" +internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + textSources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + textSources.joinSubSourcesHtml() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt similarity index 98% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt index d9a079d9c6..2c3b8e8076 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StringFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/StringFormatting.kt @@ -1,7 +1,8 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.utils.internal -import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.ParseMode.* +import dev.inmo.tgbotapi.types.UserId +import dev.inmo.tgbotapi.types.link import dev.inmo.tgbotapi.utils.extensions.* const val markdownBoldControl = "*" diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt new file mode 100644 index 0000000000..e754be23b6 --- /dev/null +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt @@ -0,0 +1,56 @@ +package dev.inmo.tgbotapi.types.MessageEntity + +import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +import kotlin.test.assertTrue + +const val testText = "It is simple hello world with #tag and @mention" +const val formattedV2Text = "It *_is_ ~__simple__~* hello world with \\#tag and @mention" +const val formattedHtmlText = "It is simple hello world with #tag and @mention" +internal val testTextEntities = listOf( + RawMessageEntity( + "bold", + 3, + 9 + ), + RawMessageEntity( + "italic", + 3, + 2 + ), + RawMessageEntity( + "strikethrough", + 6, + 6 + ), + RawMessageEntity( + "underline", + 6, + 6 + ), + RawMessageEntity( + "hashtag", + 30, + 4 + ), + RawMessageEntity( + "mention", + 39, + 6 + ) +) + +fun List.testTextParts() { + assertTrue (first().source is RegularTextSource) + assertTrue (get(1).source is BoldTextSource) + assertTrue (get(2).source is RegularTextSource) + assertTrue (get(3).source is HashTagTextSource) + assertTrue (get(4).source is RegularTextSource) + assertTrue (get(5).source is MentionTextSource) + + val boldSource = get(1).source as BoldTextSource + assertTrue (boldSource.textSources.first() is ItalicTextSource) + assertTrue (boldSource.textSources[1] is RegularTextSource) + assertTrue (boldSource.textSources[2] is StrikethroughTextSource) + assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource) +} diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/utils/StringFormattingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt similarity index 55% rename from tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/utils/StringFormattingTests.kt rename to tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt index 7db4187b1c..34a7e66975 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/utils/StringFormattingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/StringFormattingTests.kt @@ -1,5 +1,9 @@ -package dev.inmo.tgbotapi.utils +package dev.inmo.tgbotapi.types.MessageEntity +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.types.MessageEntity.textsources.* +import dev.inmo.tgbotapi.CommonAbstracts.plus +import dev.inmo.tgbotapi.utils.internal.* import kotlin.test.Test import kotlin.test.assertEquals @@ -33,4 +37,20 @@ class StringFormattingTests { originalHelloWorld.preMarkdown() ) } + + @Test + fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() { + val sources: List = regular("It ") + + bold(italic("is") + + " " + + strikethrough(underline("simple"))) + + " hello world with " + + hashtag("tag") + + " and " + + mention("mention") + sources.toTextParts().testTextParts() + + assertEquals(formattedV2Text, sources.toMarkdownV2Texts().first()) + assertEquals(formattedHtmlText, sources.toHtmlTexts().first()) + } } diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt index f39a5cfef0..a4150e0d3d 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/TextPartsCreatingTests.kt @@ -1,141 +1,30 @@ package dev.inmo.tgbotapi.types.MessageEntity -import dev.inmo.tgbotapi.types.MessageEntity.textsources.* -import dev.inmo.tgbotapi.utils.* +import dev.inmo.tgbotapi.CommonAbstracts.justTextSources +import dev.inmo.tgbotapi.utils.internal.toHtmlTexts +import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Texts import kotlin.test.* class TextPartsCreatingTests { @Test fun testThatTextWithMultilevelPartsCorrectlyCreating() { - val text = "It is simple hello world" - val formattedV2Text = "It *_is_ ~__simple__~* hello world" - val entities = listOf( - RawMessageEntity( - "bold", - 3, - 9 - ), - RawMessageEntity( - "italic", - 3, - 2 - ), - RawMessageEntity( - "strikethrough", - 6, - 6 - ), - RawMessageEntity( - "underline", - 6, - 6 - ) - ) - - val textParts = createTextPart(text, entities) - - - assertTrue ( - textParts.first().source is BoldTextSource - ) - - val boldSource = textParts.first().source as BoldTextSource - assertTrue ( - boldSource.textParts.first().source is ItalicTextSource - ) - assertTrue ( - boldSource.textParts[1].source is RegularTextSource - ) - assertTrue ( - boldSource.textParts[2].source is StrikethroughTextSource - ) - assertTrue ( - (boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource - ) - - - val fullTextParts = text.fullListOfSubSource(textParts) - - assertTrue( - fullTextParts.first().source is RegularTextSource - ) - assertTrue( - fullTextParts[1].source is BoldTextSource - ) - assertTrue( - fullTextParts[2].source is RegularTextSource - ) + val textParts = testTextEntities.asTextParts(testText) + textParts.testTextParts() assertEquals( formattedV2Text, - createMarkdownV2Text(fullTextParts.map { it.source }).first() + textParts.justTextSources().toMarkdownV2Texts().first() ) } @Test fun testThatTextWithMultilevelPartsCorrectlyCreatingInHtml() { - val text = "It is simple hello world" - val formattedHtmlText = "It is simple hello world" - val entities = listOf( - RawMessageEntity( - "bold", - 3, - 9 - ), - RawMessageEntity( - "italic", - 3, - 2 - ), - RawMessageEntity( - "strikethrough", - 6, - 6 - ), - RawMessageEntity( - "underline", - 6, - 6 - ) - ) - - val textParts = createTextPart(text, entities) - - - assertTrue ( - textParts.first().source is BoldTextSource - ) - - val boldSource = textParts.first().source as BoldTextSource - assertTrue ( - boldSource.textParts.first().source is ItalicTextSource - ) - assertTrue ( - boldSource.textParts[1].source is RegularTextSource - ) - assertTrue ( - boldSource.textParts[2].source is StrikethroughTextSource - ) - assertTrue ( - (boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource - ) - - - val fullTextParts = text.fullListOfSubSource(textParts) - - assertTrue( - fullTextParts.first().source is RegularTextSource - ) - assertTrue( - fullTextParts[1].source is BoldTextSource - ) - assertTrue( - fullTextParts[2].source is RegularTextSource - ) + val textParts = testTextEntities.asTextParts(testText) + textParts.testTextParts() assertEquals( formattedHtmlText, - createHtmlText(fullTextParts.map { it.source }).first() + textParts.justTextSources().toHtmlTexts().first() ) } } diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt index 77bd43f636..7ac90e6b71 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TelegramDateTests.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types -import dev.inmo.tgbotapi.TestsJsonFormat import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.TestsJsonFormat import kotlinx.serialization.Serializable import kotlin.test.Test import kotlin.test.assertEquals diff --git a/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt b/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt index e668a64f14..ce99122dfa 100644 --- a/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt +++ b/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.utils -import kotlinx.serialization.* -import org.w3c.dom.get import kotlinx.browser.window +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient +import org.w3c.dom.get @Serializable(MimeTypeSerializer::class) actual class MimeType( diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt index 34350831f3..7492cc3d98 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/requests/abstracts/InputFileFromJavaFile.kt @@ -1,7 +1,9 @@ package dev.inmo.tgbotapi.requests.abstracts +import dev.inmo.tgbotapi.utils.MimeType import dev.inmo.tgbotapi.utils.StorageFile import java.io.File +import java.io.InputStream fun File.toInputFile() = if (exists()) { MultipartFile( diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt index 95a7ba5c9a..3617b5180f 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/MimeTypeActual.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.utils -import kotlinx.serialization.* +import kotlinx.serialization.Serializable @Serializable(MimeTypeSerializer::class) actual class MimeType( diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFileFactory.kt similarity index 91% rename from tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt rename to tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFileFactory.kt index 8d7ebe5c53..4aab4c57b6 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/StorageFileFactory.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.utils import io.ktor.utils.io.streams.asInput import java.io.File +import java.io.InputStream import java.nio.file.Files fun StorageFile( diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt index 18f9d0e72e..c931181091 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt @@ -3,29 +3,143 @@ package dev.inmo.tgbotapi.extensions.api import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutor import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper +import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig -import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.engine.* + +/** + * Allows to create bot using bot [urlsKeeper] + */ +fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper +): TelegramBot = KtorRequestsExecutor( + urlsKeeper, + HttpClient() +) /** * Allows to create bot using bot [urlsKeeper] and already prepared [client] */ fun telegramBot( urlsKeeper: TelegramAPIUrlsKeeper, - client: HttpClient = HttpClient() + client: HttpClient ): TelegramBot = KtorRequestsExecutor( urlsKeeper, client ) +/** + * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngineFactory] by passing [clientFactory] param and optionally + * configure it with [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper, + clientFactory: HttpClientEngineFactory, + noinline clientConfig: HttpClientConfig.() -> Unit = {} +) = telegramBot( + urlsKeeper, + HttpClient(clientFactory, clientConfig) +) + /** * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally * configure [HttpClient] using [clientConfig] */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper, + clientEngine: HttpClientEngine, + noinline clientConfig: HttpClientConfig<*>.() -> Unit = {} +) = telegramBot( + urlsKeeper, + HttpClient(clientEngine, clientConfig) +) + +/** + * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by configuring [HttpClient] using + * [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + urlsKeeper: TelegramAPIUrlsKeeper, + noinline clientConfig: HttpClientConfig<*>.() -> Unit +) = telegramBot( + urlsKeeper, + HttpClient(clientConfig) +) + +/** + * Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl +): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl)) + +/** + * Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl, + client: HttpClient +): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client) + +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + clientFactory: HttpClientEngineFactory, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig.() -> Unit = {} +) = telegramBot( + TelegramAPIUrlsKeeper(token, apiUrl), + clientFactory, + clientConfig +) + +/** + * Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally + * configure [HttpClient] using [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + clientEngine: HttpClientEngine, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig<*>.() -> Unit = {} +) = telegramBot( + TelegramAPIUrlsKeeper(token, apiUrl), + clientEngine, + clientConfig +) + +/** + * Allows to create bot using bot [token] and [apiUrl] and specify [HttpClientEngine] by configuring [HttpClient] using + * [clientConfig] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun telegramBot( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig<*>.() -> Unit +) = telegramBot( + TelegramAPIUrlsKeeper(token, apiUrl), + clientConfig +) + +/** + * Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally + * configure [HttpClient] using [clientConfig] + */ +@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) fun telegramBotWithCustomClientConfig( urlsKeeper: TelegramAPIUrlsKeeper, clientEngine: HttpClientEngine, - clientConfig: HttpClientConfig<*>.() -> Unit = {} + clientConfig: HttpClientConfig<*>.() -> Unit ): TelegramBot = telegramBot( urlsKeeper, HttpClient(clientEngine, clientConfig) @@ -34,43 +148,19 @@ fun telegramBotWithCustomClientConfig( /** * Allows to create bot using bot [urlsKeeper] and optionally configure [HttpClient] using [clientConfig] */ +@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) fun telegramBotWithCustomClientConfig( urlsKeeper: TelegramAPIUrlsKeeper, - clientConfig: HttpClientConfig<*>.() -> Unit = {} + clientConfig: HttpClientConfig<*>.() -> Unit ): TelegramBot = telegramBot( urlsKeeper, HttpClient(clientConfig) ) -/** - * Allows to create bot using bot [token] - */ -fun telegramBot( - token: String -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token)) - -/** - * Allows to create bot using bot [token] and already prepared [client] - */ -fun telegramBot( +@Suppress("NOTHING_TO_INLINE") +@Deprecated("Renamed", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) +inline fun telegramBotWithCustomClientConfig( token: String, - client: HttpClient -): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token), client) - -/** - * Allows to create bot using bot [token] and configure [HttpClient] using [clientConfig] - */ -fun telegramBotWithCustomClientConfig( - token: String, - clientConfig: HttpClientConfig<*>.() -> Unit -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientConfig) - -/** - * Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally - * configure [HttpClient] using [clientConfig] - */ -fun telegramBot( - token: String, - clientEngine: HttpClientEngine, - clientConfig: HttpClientConfig<*>.() -> Unit = {} -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientEngine, clientConfig) + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig<*>.() -> Unit +) = telegramBot(token, apiUrl = apiUrl, clientConfig = clientConfig) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/Close.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/Close.kt new file mode 100644 index 0000000000..14a613d890 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/Close.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.extensions.api + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.local.Close + +@Suppress("unused") +suspend inline fun TelegramBot.close() = execute(Close) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt similarity index 56% rename from tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt rename to tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt index c480c38fe1..683fa940b2 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LiveLocationProvider.kt @@ -1,25 +1,27 @@ package dev.inmo.tgbotapi.extensions.api +import com.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.editLiveLocation import dev.inmo.tgbotapi.extensions.api.edit.LiveLocation.stopLiveLocation -import dev.inmo.tgbotapi.requests.send.SendLocation +import dev.inmo.tgbotapi.requests.send.SendLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.LiveLocation +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.LocationContent -import com.soywiz.klock.DateTime -import com.soywiz.klock.TimeSpan import io.ktor.utils.io.core.Closeable import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlin.math.ceil val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L -class LiveLocation internal constructor( +class LiveLocationProvider internal constructor( private val requestsExecutor: TelegramBot, scope: CoroutineScope, autoCloseTimeDelay: Double, @@ -39,13 +41,13 @@ class LiveLocation internal constructor( get() = field || leftUntilCloseMillis.millisecondsLong < 0L private var message: ContentMessage = initMessage - val lastLocation: Location - get() = message.content.location + val lastLocation: LiveLocation + get() = message.content.location as LiveLocation suspend fun updateLocation( - location: Location, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null - ): Location { + ): LiveLocation { if (!isClosed) { message = requestsExecutor.editLiveLocation( message, @@ -73,24 +75,32 @@ suspend fun TelegramBot.startLiveLocation( latitude: Double, longitude: Double, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation { +): LiveLocationProvider { val liveTimeAsDouble = liveTimeMillis.toDouble() val locationMessage = execute( - SendLocation( + SendLiveLocation( chatId, latitude, longitude, - ceil(liveTimeAsDouble / 1000).toLong(), + ceil(liveTimeAsDouble / 1000).toInt(), + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) - return LiveLocation( + return LiveLocationProvider( this, scope, liveTimeAsDouble, @@ -104,35 +114,80 @@ suspend fun TelegramBot.startLiveLocation( latitude: Double, longitude: Double, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation = startLiveLocation( - scope, chat.id, latitude, longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup +): LiveLocationProvider = startLiveLocation( + scope, + chat.id, + latitude, + longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup ) suspend fun TelegramBot.startLiveLocation( scope: CoroutineScope, chatId: ChatId, - location: Location, + location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation = startLiveLocation( - scope, chatId, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup +): LiveLocationProvider = startLiveLocation( + scope, + chatId, + location.latitude, + location.longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup ) suspend fun TelegramBot.startLiveLocation( scope: CoroutineScope, chat: Chat, - location: Location, + location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -): LiveLocation = startLiveLocation( - scope, chat.id, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup +): LiveLocationProvider = startLiveLocation( + scope, + chat.id, + location.latitude, + location.longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup ) suspend inline fun TelegramBot.replyWithLiveLocation( @@ -141,15 +196,48 @@ suspend inline fun TelegramBot.replyWithLiveLocation( latitude: Double, longitude: Double, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = startLiveLocation(scope, to.chat, latitude, longitude, liveTimeMillis, disableNotification, to.messageId, replyMarkup) +) = startLiveLocation( + scope, + to.chat, + latitude, + longitude, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) suspend inline fun TelegramBot.replyWithLiveLocation( to: Message, scope: CoroutineScope, - location: Location, + location: StaticLocation, liveTimeMillis: Long = defaultLivePeriodDelayMillis, + initHorizontalAccuracy: Meters? = null, + initHeading: Degrees? = null, + initProximityAlertRadius: Meters? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = startLiveLocation(scope, to.chat, location, liveTimeMillis, disableNotification, to.messageId, replyMarkup) +) = startLiveLocation( + scope, + to.chat, + location, + liveTimeMillis, + initHorizontalAccuracy, + initHeading, + initProximityAlertRadius, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LogOut.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LogOut.kt new file mode 100644 index 0000000000..23d5c8daeb --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/LogOut.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.extensions.api + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.local.LogOut + +suspend inline fun TelegramBot.logOut() = execute(LogOut) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt index 8ef88449ad..e3f1dc9721 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt @@ -9,6 +9,7 @@ suspend fun TelegramBot.promoteChatMember( chatId: ChatIdentifier, userId: UserId, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -22,6 +23,7 @@ suspend fun TelegramBot.promoteChatMember( chatId, userId, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, @@ -37,6 +39,7 @@ suspend fun TelegramBot.promoteChatMember( chat: PublicChat, userId: UserId, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -49,6 +52,7 @@ suspend fun TelegramBot.promoteChatMember( chat.id, userId, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, @@ -63,6 +67,7 @@ suspend fun TelegramBot.promoteChatMember( chatId: ChatId, user: User, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -75,6 +80,7 @@ suspend fun TelegramBot.promoteChatMember( chatId, user.id, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, @@ -89,6 +95,7 @@ suspend fun TelegramBot.promoteChatMember( chat: PublicChat, user: User, untilDate: TelegramDate? = null, + isAnonymous: Boolean? = null, canChangeInfo: Boolean? = null, canPostMessages: Boolean? = null, canEditMessages: Boolean? = null, @@ -101,6 +108,7 @@ suspend fun TelegramBot.promoteChatMember( chat.id, user.id, untilDate, + isAnonymous, canChangeInfo, canPostMessages, canEditMessages, diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt index 74719e7281..5b98415738 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/UnbanChatMember.kt @@ -7,21 +7,25 @@ import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat suspend fun TelegramBot.unbanChatMember( chatId: ChatIdentifier, - userId: UserId -) = execute(UnbanChatMember(chatId, userId)) + userId: UserId, + onlyIfBanned: Boolean? = null +) = execute(UnbanChatMember(chatId, userId, onlyIfBanned)) suspend fun TelegramBot.unbanChatMember( chat: PublicChat, - userId: UserId -) = unbanChatMember(chat.id, userId) + userId: UserId, + onlyIfBanned: Boolean? = null +) = unbanChatMember(chat.id, userId, onlyIfBanned) suspend fun TelegramBot.unbanChatMember( chatId: ChatId, - user: User -) = unbanChatMember(chatId, user.id) + user: User, + onlyIfBanned: Boolean? = null +) = unbanChatMember(chatId, user.id, onlyIfBanned) suspend fun TelegramBot.unbanChatMember( chat: PublicChat, - user: User -) = unbanChatMember(chat.id, user.id) + user: User, + onlyIfBanned: Boolean? = null +) = unbanChatMember(chat.id, user.id, onlyIfBanned) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt index b2c9f7e06b..9a1977cc07 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/PinChatMessage.kt @@ -4,7 +4,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.chat.modify.PinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat +import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.pinChatMessage( @@ -14,7 +14,7 @@ suspend fun TelegramBot.pinChatMessage( ) = execute(PinChatMessage(chatId, messageId, disableNotification)) suspend fun TelegramBot.pinChatMessage( - chat: PublicChat, + chat: Chat, messageId: MessageIdentifier, disableNotification: Boolean = false ) = pinChatMessage(chat.id, messageId, disableNotification) @@ -22,8 +22,4 @@ suspend fun TelegramBot.pinChatMessage( suspend fun TelegramBot.pinChatMessage( message: Message, disableNotification: Boolean = false -) = if (message.chat is PublicChat) { - pinChatMessage(message.chat.id, message.messageId, disableNotification) -} else { - error("It is possible to pin messages only in non one-to-one chats") -} +) = pinChatMessage(message.chat.id, message.messageId, disableNotification) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt new file mode 100644 index 0000000000..3faa707bf9 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinAllChatMessages.kt @@ -0,0 +1,14 @@ +package dev.inmo.tgbotapi.extensions.api.chat.modify + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.modify.UnpinAllChatMessages +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat + +suspend fun TelegramBot.unpinAllChatMessages( + chatId: ChatIdentifier +) = execute(UnpinAllChatMessages(chatId)) + +suspend fun TelegramBot.unpinAllChatMessages( + chat: Chat +) = unpinAllChatMessages(chat.id) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt index de540d19d3..ada3cc7b95 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/modify/UnpinChatMessage.kt @@ -3,12 +3,21 @@ package dev.inmo.tgbotapi.extensions.api.chat.modify import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat +import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.unpinChatMessage( - chatId: ChatIdentifier -) = execute(UnpinChatMessage(chatId)) + chatId: ChatIdentifier, + messageId: MessageIdentifier? = null +) = execute(UnpinChatMessage(chatId, messageId)) suspend fun TelegramBot.unpinChatMessage( - chat: PublicChat -) = unpinChatMessage(chat.id) + chat: Chat, + messageId: MessageIdentifier? = null +) = unpinChatMessage(chat.id, messageId) + +suspend fun TelegramBot.unpinChatMessage( + message: Message +) = unpinChatMessage(message.chat.id, message.messageId) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt index 29b62ec4ff..2548f015a2 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditChatMessageLiveLocation.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.edit.LiveLocation.EditChatMessageLiveLocation import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.LiveLocation import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.LocationContent @@ -13,10 +14,13 @@ suspend fun TelegramBot.editLiveLocation( messageId: MessageIdentifier, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditChatMessageLiveLocation( - chatId, messageId, latitude, longitude, replyMarkup + chatId, messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup ) ) @@ -25,36 +29,42 @@ suspend fun TelegramBot.editLiveLocation( messageId: MessageIdentifier, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(chat.id, messageId, latitude, longitude, replyMarkup) +) = editLiveLocation(chat.id, messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup) suspend fun TelegramBot.editLiveLocation( message: ContentMessage, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(message.chat, message.messageId, latitude, longitude, replyMarkup) +) = editLiveLocation(message.chat, message.messageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup) suspend fun TelegramBot.editLiveLocation( chatId: ChatIdentifier, messageId: MessageIdentifier, - location: Location, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditChatMessageLiveLocation( - chatId, messageId, location.latitude, location.longitude, replyMarkup + chatId, messageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup ) ) suspend fun TelegramBot.editLiveLocation( chat: Chat, messageId: MessageIdentifier, - location: Location, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, replyMarkup) +) = editLiveLocation(chat.id, messageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup) suspend fun TelegramBot.editLiveLocation( message: ContentMessage, - location: Location, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, replyMarkup) +) = editLiveLocation(message.chat, message.messageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt index fc0520b248..9540b6a658 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/LiveLocation/EditInlineMessageLiveLocation.kt @@ -2,22 +2,25 @@ package dev.inmo.tgbotapi.extensions.api.edit.LiveLocation import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.LiveLocation.EditInlineMessageLiveLocation -import dev.inmo.tgbotapi.types.InlineMessageIdentifier -import dev.inmo.tgbotapi.types.Location +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup +import dev.inmo.tgbotapi.types.location.LiveLocation suspend fun TelegramBot.editLiveLocation( inlineMessageId: InlineMessageIdentifier, latitude: Double, longitude: Double, + horizontalAccuracy: Meters? = null, + heading: Degrees? = null, + proximityAlertRadius: Meters? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute( EditInlineMessageLiveLocation( - inlineMessageId, latitude, longitude, replyMarkup + inlineMessageId, latitude, longitude, horizontalAccuracy, heading, proximityAlertRadius, replyMarkup ) ) suspend fun TelegramBot.editLiveLocation( inlineMessageId: InlineMessageIdentifier, - location: Location, + location: LiveLocation, replyMarkup: InlineKeyboardMarkup? = null -) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, replyMarkup) +) = editLiveLocation(inlineMessageId, location.latitude, location.longitude, location.horizontalAccuracy, location.heading, location.proximityAlertRadius, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt index 3ee1097691..1becc8e0d3 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditChatMessageCaption.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.api.edit.caption import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption import dev.inmo.tgbotapi.types.ChatIdentifier @@ -37,3 +38,27 @@ suspend fun TelegramBot.editMessageCaption( ): ContentMessage where T : CaptionedInput, T : MediaContent { return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup) } + +suspend fun TelegramBot.editMessageCaption( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageCaption(chatId, messageId, entities, replyMarkup) +) + +suspend fun TelegramBot.editMessageCaption( + chat: Chat, + messageId: MessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageCaption(chat.id, messageId, entities, replyMarkup) + +suspend fun TelegramBot.editMessageCaption( + message: ContentMessage, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +): ContentMessage where T : CaptionedInput, T : MediaContent { + return editMessageCaption(message.chat.id, message.messageId, entities, replyMarkup) +} diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt index 29ca66bfbb..00df5eea1e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/caption/EditInlineMessageCaption.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.edit.caption +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.caption.EditInlineMessageCaption import dev.inmo.tgbotapi.types.InlineMessageIdentifier @@ -12,3 +13,9 @@ suspend fun TelegramBot.editMessageCaption( parseMode: ParseMode? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute(EditInlineMessageCaption(inlineMessageId, text, parseMode, replyMarkup)) + +suspend fun TelegramBot.editMessageCaption( + inlineMessageId: InlineMessageIdentifier, + entities: List, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageCaption(inlineMessageId, entities, replyMarkup)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt index 811a5f33d0..1e9f460310 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditChatMessageText.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.text.EditChatMessageText import dev.inmo.tgbotapi.types.ChatIdentifier @@ -36,4 +37,29 @@ suspend fun TelegramBot.editMessageText( parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = editMessageText(message.chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) \ No newline at end of file +) = editMessageText(message.chat.id, message.messageId, text, parseMode, disableWebPagePreview, replyMarkup) + +suspend fun TelegramBot.editMessageText( + chatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute( + EditChatMessageText(chatId, messageId, entities, disableWebPagePreview, replyMarkup) +) + +suspend fun TelegramBot.editMessageText( + chat: Chat, + messageId: MessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageText(chat.id, messageId, entities, disableWebPagePreview, replyMarkup) + +suspend fun TelegramBot.editMessageText( + message: ContentMessage, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = editMessageText(message.chat.id, message.messageId, entities, disableWebPagePreview, replyMarkup) \ No newline at end of file diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt index e21c30c03c..f100fa861e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/edit/text/EditInlineMessageText.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.edit.text +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.edit.text.EditInlineMessageText import dev.inmo.tgbotapi.types.InlineMessageIdentifier @@ -13,3 +14,10 @@ suspend fun TelegramBot.editMessageText( disableWebPagePreview: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute(EditInlineMessageText(inlineMessageId, text, parseMode, disableWebPagePreview, replyMarkup)) + +suspend fun TelegramBot.editMessageText( + inlineMessageId: InlineMessageIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + replyMarkup: InlineKeyboardMarkup? = null +) = execute(EditInlineMessageText(inlineMessageId, entities, disableWebPagePreview, replyMarkup)) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt new file mode 100644 index 0000000000..73874634de --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/CopyMessage.kt @@ -0,0 +1,150 @@ +package dev.inmo.tgbotapi.extensions.api.send + +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.send.CopyMessage +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.message.abstracts.Message + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + CopyMessage(fromChatId, toChatId, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChatId, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChat: Chat, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChatId, toChat.id, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChat: Chat, + messageId: MessageIdentifier, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChat.id, messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChatId: ChatIdentifier, + message: Message, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChatId, message.messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChat: Chat, + message: Message, + text: String? = null, + parseMode: ParseMode? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChat, message.messageId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + CopyMessage(fromChatId, toChatId, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChatId: ChatIdentifier, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChatId, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChatId: ChatIdentifier, + toChat: Chat, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChatId, toChat.id, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + fromChat: Chat, + toChat: Chat, + messageId: MessageIdentifier, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(fromChat.id, toChat.id, messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChatId: ChatIdentifier, + message: Message, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChatId, message.messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.copyMessage( + toChat: Chat, + message: Message, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = copyMessage(message.chat, toChat, message.messageId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt index 9b0f05be68..7edf1423e4 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendContact.kt @@ -14,10 +14,11 @@ suspend fun TelegramBot.sendContact( lastName: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendContact( - chatId, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup + chatId, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -26,10 +27,11 @@ suspend fun TelegramBot.sendContact( contact: Contact, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendContact( - chatId, contact, disableNotification, replyToMessageId, replyMarkup + chatId, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -40,9 +42,10 @@ suspend fun TelegramBot.sendContact( lastName: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( - chat.id, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, replyMarkup + chat.id, phoneNumber, firstName, lastName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendContact( @@ -50,9 +53,10 @@ suspend fun TelegramBot.sendContact( contact: Contact, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( - chat.id, contact, disableNotification, replyToMessageId, replyMarkup + chat.id, contact, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.reply( @@ -61,6 +65,7 @@ suspend inline fun TelegramBot.reply( firstName: String, lastName: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( to.chat, @@ -69,6 +74,7 @@ suspend inline fun TelegramBot.reply( lastName, disableNotification, to.messageId, + allowSendingWithoutReply, replyMarkup ) @@ -76,11 +82,13 @@ suspend inline fun TelegramBot.reply( to: Message, contact: Contact, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendContact( to.chat, contact, disableNotification, to.messageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt index b6afbe4374..250f55d88a 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendDice.kt @@ -14,9 +14,10 @@ suspend fun TelegramBot.sendDice( animationType: DiceAnimationType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendDice(chatId, animationType, disableNotification, replyToMessageId, replyMarkup) + SendDice(chatId, animationType, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendDice( @@ -24,12 +25,14 @@ suspend fun TelegramBot.sendDice( animationType: DiceAnimationType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, replyMarkup) +) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, animationType: DiceAnimationType? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendDice(to.chat, animationType, disableNotification, to.messageId, replyMarkup) +) = sendDice(to.chat, animationType, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt index b67be97035..7a98d1b72e 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendLocation.kt @@ -1,10 +1,12 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.send.SendLocation -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.requests.send.SendStaticLocation +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.Message suspend fun TelegramBot.sendLocation( @@ -15,7 +17,7 @@ suspend fun TelegramBot.sendLocation( replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendLocation( + SendStaticLocation( chatId, latitude, longitude, @@ -27,7 +29,7 @@ suspend fun TelegramBot.sendLocation( suspend fun TelegramBot.sendLocation( chatId: ChatIdentifier, - location: Location, + location: StaticLocation, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null @@ -58,7 +60,7 @@ suspend fun TelegramBot.sendLocation( suspend fun TelegramBot.sendLocation( chat: Chat, - location: Location, + location: StaticLocation, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, replyMarkup: KeyboardMarkup? = null @@ -71,6 +73,40 @@ suspend fun TelegramBot.sendLocation( replyMarkup ) +suspend fun TelegramBot.sendStaticLocation( + chatId: ChatIdentifier, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chatId, latitude, longitude, disableNotification, replyToMessageId, replyMarkup) + +suspend fun TelegramBot.sendStaticLocation( + chatId: ChatIdentifier, + location: StaticLocation, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup) + +suspend fun TelegramBot.sendStaticLocation( + chat: Chat, + latitude: Double, + longitude: Double, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chat.id, latitude, longitude, disableNotification, replyToMessageId, replyMarkup) + +suspend fun TelegramBot.sendStaticLocation( + chat: Chat, + location: StaticLocation, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, replyToMessageId, replyMarkup) + suspend inline fun TelegramBot.reply( to: Message, latitude: Double, @@ -88,7 +124,7 @@ suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply( to: Message, - location: Location, + location: StaticLocation, disableNotification: Boolean = false, replyMarkup: KeyboardMarkup? = null ) = sendLocation( diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt index 2519f6597c..ccfae79987 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendMessage.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.types.ChatIdentifier @@ -16,9 +17,10 @@ suspend fun TelegramBot.sendMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendTextMessage(chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) + SendTextMessage(chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendTextMessage( @@ -28,9 +30,10 @@ suspend fun TelegramBot.sendTextMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendMessage( - chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup + chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendMessage( @@ -40,8 +43,9 @@ suspend fun TelegramBot.sendMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) +) = sendMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendTextMessage( @@ -51,8 +55,54 @@ suspend fun TelegramBot.sendTextMessage( disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendTextMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, replyMarkup) +) = sendTextMessage(chat.id, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend fun TelegramBot.sendMessage( + chatId: ChatIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendTextMessage(chatId, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) + +suspend fun TelegramBot.sendTextMessage( + chatId: ChatIdentifier, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendMessage( + chatId, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend fun TelegramBot.sendMessage( + chat: Chat, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendMessage(chat.id, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + + +suspend fun TelegramBot.sendTextMessage( + chat: Chat, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendTextMessage(chat.id, entities, disableWebPagePreview, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -60,6 +110,7 @@ suspend inline fun TelegramBot.reply( parseMode: ParseMode? = null, disableWebPagePreview: Boolean? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendTextMessage( to.chat, @@ -68,5 +119,22 @@ suspend inline fun TelegramBot.reply( disableWebPagePreview, disableNotification, to.messageId, + allowSendingWithoutReply, + replyMarkup +) +suspend inline fun TelegramBot.reply( + to: Message, + entities: List, + disableWebPagePreview: Boolean? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendTextMessage( + to.chat, + entities, + disableWebPagePreview, + disableNotification, + to.messageId, + allowSendingWithoutReply, replyMarkup ) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt index 08495ad015..31cabb0734 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendVenue.kt @@ -2,9 +2,15 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendVenue -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.FoursquareId +import dev.inmo.tgbotapi.types.FoursquareType +import dev.inmo.tgbotapi.types.GooglePlaceId +import dev.inmo.tgbotapi.types.GooglePlaceType +import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.venue.Venue @@ -14,13 +20,29 @@ suspend fun TelegramBot.sendVenue( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chatId = chatId, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) ) @@ -30,38 +52,86 @@ suspend fun TelegramBot.sendVenue( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chatId = chat.id, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( chatId: ChatIdentifier, - location: Location, + location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chatId, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chatId = chatId, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( chat: Chat, - location: Location, + location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup + chatId = chat.id, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend fun TelegramBot.sendVenue( @@ -69,10 +139,16 @@ suspend fun TelegramBot.sendVenue( venue: Venue, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVenue( - chatId, venue, disableNotification, replyToMessageId, replyMarkup + chatId = chatId, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) ) @@ -81,9 +157,15 @@ suspend fun TelegramBot.sendVenue( venue: Venue, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - chat.id, venue, disableNotification, replyToMessageId, replyMarkup + chatId = chat.id, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = replyToMessageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( @@ -92,30 +174,68 @@ suspend inline fun TelegramBot.reply( longitude: Double, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, latitude, longitude, title, address, foursquareId, disableNotification, to.messageId, replyMarkup + chat = to.chat, + latitude = latitude, + longitude = longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( to: Message, - location: Location, + location: StaticLocation, title: String, address: String, - foursquareId: String? = null, + foursquareId: FoursquareId? = null, + foursquareType: FoursquareType? = null, + googlePlaceId: GooglePlaceId? = null, + googlePlaceType: GooglePlaceType? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, location, title, address, foursquareId, disableNotification, to.messageId, replyMarkup + chat = to.chat, + latitude = location.latitude, + longitude = location.longitude, + title = title, + address = address, + foursquareId = foursquareId, + foursquareType = foursquareType, + googlePlaceId = googlePlaceId, + googlePlaceType = googlePlaceType, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) suspend inline fun TelegramBot.reply( to: Message, venue: Venue, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVenue( - to.chat, venue, disableNotification, to.messageId, replyMarkup + chat = to.chat, + venue = venue, + disableNotification = disableNotification, + replyToMessageId = to.messageId, + allowSendingWithoutReply = allowSendingWithoutReply, + replyMarkup = replyMarkup ) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt index 82d17237b7..bc95b64ca3 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/games/SendGame.kt @@ -14,10 +14,11 @@ suspend fun TelegramBot.sendGame( gameShortName: String, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendGame( - chatId, gameShortName, disableNotification, replyToMessageId, replyMarkup + chatId, gameShortName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -26,9 +27,10 @@ suspend fun TelegramBot.sendGame( gameShortName: String, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - chat.id, gameShortName, disableNotification, replyToMessageId, replyMarkup + chat.id, gameShortName, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendGame( @@ -36,9 +38,10 @@ suspend fun TelegramBot.sendGame( game: Game, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - chatId, game.title, disableNotification, replyToMessageId, replyMarkup + chatId, game.title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendGame( @@ -46,32 +49,36 @@ suspend fun TelegramBot.sendGame( game: Game, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - chat.id, game.title, disableNotification, replyToMessageId, replyMarkup + chat.id, game.title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.replyWithGame( to: Message, gameShortName: String, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - to.chat, gameShortName, disableNotification, to.messageId, replyMarkup + to.chat, gameShortName, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.replyWithGame( to: Message, game: Game, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendGame( - to.chat, game.title, disableNotification, to.messageId, replyMarkup + to.chat, game.title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.reply( to: Message, game: Game, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithGame(to, game, disableNotification, replyMarkup) +) = replyWithGame(to, game, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt index 79f9ee41ab..95a4c4bcdc 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendAnimation @@ -22,6 +23,7 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendAnimation( @@ -35,6 +37,7 @@ suspend fun TelegramBot.sendAnimation( height, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -49,9 +52,10 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendAnimation( - chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup + chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendAnimation( @@ -65,8 +69,9 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup) +) = sendAnimation(chat.id, animation, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendAnimation( chat: Chat, @@ -78,8 +83,9 @@ suspend fun TelegramBot.sendAnimation( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup) +) = sendAnimation(chat.id, animation, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAnimation( to: Message, @@ -91,6 +97,7 @@ suspend inline fun TelegramBot.replyWithAnimation( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendAnimation( to.chat, @@ -103,6 +110,7 @@ suspend inline fun TelegramBot.replyWithAnimation( height, disableNotification, to.messageId, + allowSendingWithoutReply, replyMarkup ) @@ -115,8 +123,9 @@ suspend inline fun TelegramBot.replyWithAnimation( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, disableNotification, to.messageId, replyMarkup) +) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -127,5 +136,126 @@ suspend inline fun TelegramBot.reply( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithAnimation(to, animation, text, parseMode, duration, width, height, disableNotification, replyMarkup) +) = replyWithAnimation(to, animation, text, parseMode, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend fun TelegramBot.sendAnimation( + chatId: ChatIdentifier, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendAnimation( + chatId, + animation, + thumb, + entities, + duration, + width, + height, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend fun TelegramBot.sendAnimation( + chatId: ChatIdentifier, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + chatId, animation.fileId, animation.thumb ?.fileId, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend fun TelegramBot.sendAnimation( + chat: Chat, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(chat.id, animation, thumb, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend fun TelegramBot.sendAnimation( + chat: Chat, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(chat.id, animation, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation( + to.chat, + animation, + thumb, + entities, + duration, + width, + height, + disableNotification, + to.messageId, + allowSendingWithoutReply, + replyMarkup +) + +suspend inline fun TelegramBot.replyWithAnimation( + to: Message, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAnimation(to.chat, animation, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + animation: AnimationFile, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithAnimation(to, animation, entities, duration, width, height, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt index 0c9596f1f0..e6cfab19f9 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAudio.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendAudio @@ -8,7 +9,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.files.AnimationFile import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -23,6 +23,7 @@ suspend fun TelegramBot.sendAudio( title: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendAudio( @@ -36,6 +37,7 @@ suspend fun TelegramBot.sendAudio( title, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -51,8 +53,9 @@ suspend fun TelegramBot.sendAudio( title: String? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(chat.id, audio, thumb, text, parseMode, duration, performer, title, disableNotification, replyToMessageId, replyMarkup) +) = sendAudio(chat.id, audio, thumb, text, parseMode, duration, performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendAudio( chatId: ChatIdentifier, @@ -62,8 +65,9 @@ suspend fun TelegramBot.sendAudio( title: String? = audio.title, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(chatId, audio.fileId, audio.thumb ?.fileId, text, parseMode, audio.duration, audio.performer, title, disableNotification, replyToMessageId, replyMarkup) +) = sendAudio(chatId, audio.fileId, audio.thumb ?.fileId, text, parseMode, audio.duration, audio.performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendAudio( chat: Chat, @@ -73,8 +77,9 @@ suspend fun TelegramBot.sendAudio( title: String? = audio.title, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(chat.id, audio, text, parseMode, title, disableNotification, replyToMessageId, replyMarkup) +) = sendAudio(chat.id, audio, text, parseMode, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAudio( to: Message, @@ -86,8 +91,9 @@ suspend inline fun TelegramBot.replyWithAudio( performer: String? = null, title: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, thumb, text, parseMode, duration, performer, title, disableNotification, to.messageId, replyMarkup) +) = sendAudio(to.chat, audio, thumb, text, parseMode, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAudio( to: Message, @@ -96,8 +102,9 @@ suspend inline fun TelegramBot.replyWithAudio( parseMode: ParseMode? = null, title: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAudio(to.chat, audio, text, parseMode, title, disableNotification, to.messageId, replyMarkup) +) = sendAudio(to.chat, audio, text, parseMode, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -106,5 +113,104 @@ suspend inline fun TelegramBot.reply( parseMode: ParseMode? = null, title: String? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithAudio(to, audio, text, parseMode, title, disableNotification, replyMarkup) +) = replyWithAudio(to, audio, text, parseMode, title, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendAudio( + chatId: ChatIdentifier, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendAudio( + chatId, + audio, + thumb, + entities, + duration, + performer, + title, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendAudio( + chat: Chat, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(chat.id, audio, thumb, entities, duration, performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendAudio( + chatId: ChatIdentifier, + audio: AudioFile, + entities: List, + title: String? = audio.title, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(chatId, audio.fileId, audio.thumb ?.fileId, entities, audio.duration, audio.performer, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendAudio( + chat: Chat, + audio: AudioFile, + entities: List, + title: String? = audio.title, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(chat.id, audio, entities, title, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + performer: String? = null, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, thumb, entities, duration, performer, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithAudio( + to: Message, + audio: AudioFile, + entities: List, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendAudio(to.chat, audio, entities, title, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + audio: AudioFile, + entities: List, + title: String? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithAudio(to, audio, entities, title, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt index a1fca68afa..1fab4cc11b 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendDocument.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendDocument @@ -19,7 +20,9 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null ) = execute( SendDocument( chatId, @@ -29,7 +32,9 @@ suspend fun TelegramBot.sendDocument( parseMode, disableNotification, replyToMessageId, - replyMarkup + allowSendingWithoutReply, + replyMarkup, + disableContentTypeDetection ) ) @@ -41,8 +46,10 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(chat.id, document, thumb, text, parseMode, disableNotification, replyToMessageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, thumb, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend fun TelegramBot.sendDocument( chatId: ChatIdentifier, @@ -51,9 +58,11 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null ) = sendDocument( - chatId, document.fileId, document.thumb ?.fileId, text, parseMode, disableNotification, replyToMessageId, replyMarkup + chatId, document.fileId, document.thumb ?.fileId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection ) suspend fun TelegramBot.sendDocument( @@ -63,8 +72,10 @@ suspend fun TelegramBot.sendDocument( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(chat.id, document, text, parseMode, disableNotification, replyToMessageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.replyWithDocument( to: Message, @@ -73,8 +84,10 @@ suspend inline fun TelegramBot.replyWithDocument( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(to.chat, document, thumb, text, parseMode, disableNotification, to.messageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, thumb, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.replyWithDocument( to: Message, @@ -82,8 +95,10 @@ suspend inline fun TelegramBot.replyWithDocument( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = sendDocument(to.chat, document, text, parseMode, disableNotification, to.messageId, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) suspend inline fun TelegramBot.reply( to: Message, @@ -91,5 +106,99 @@ suspend inline fun TelegramBot.reply( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, - replyMarkup: KeyboardMarkup? = null -) = replyWithDocument(to, document, text, parseMode, disableNotification, replyMarkup) + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = replyWithDocument(to, document, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + + +suspend inline fun TelegramBot.sendDocument( + chatId: ChatIdentifier, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = execute( + SendDocument( + chatId, + document, + thumb, + entities, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup, + disableContentTypeDetection + ) +) + +suspend inline fun TelegramBot.sendDocument( + chat: Chat, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, thumb, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.sendDocument( + chatId: ChatIdentifier, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument( + chatId, document.fileId, document.thumb ?.fileId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection +) + +suspend inline fun TelegramBot.sendDocument( + chat: Chat, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(chat.id, document, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: InputFile, + thumb: InputFile? = null, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, thumb, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.replyWithDocument( + to: Message, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = sendDocument(to.chat, document, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) + +suspend inline fun TelegramBot.reply( + to: Message, + document: DocumentFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null, + disableContentTypeDetection: Boolean? = null +) = replyWithDocument(to, document, entities, disableNotification, allowSendingWithoutReply, replyMarkup, disableContentTypeDetection) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt index 03e5d13e3d..6a115897b8 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt @@ -17,10 +17,11 @@ suspend fun TelegramBot.sendMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendMediaGroup( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -32,9 +33,10 @@ suspend fun TelegramBot.sendMediaGroup( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendMediaGroup( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) /** @@ -44,10 +46,11 @@ suspend fun TelegramBot.sendPlaylist( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendPlaylist( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -58,9 +61,10 @@ suspend fun TelegramBot.sendPlaylist( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendPlaylist( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) /** @@ -70,10 +74,11 @@ suspend fun TelegramBot.sendDocumentsGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendDocumentsGroup( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -84,9 +89,10 @@ suspend fun TelegramBot.sendDocumentsGroup( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendDocumentsGroup( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) /** @@ -96,10 +102,11 @@ suspend fun TelegramBot.sendVisualMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = execute( SendVisualMediaGroup( - chatId, media, disableNotification, replyToMessageId + chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) @@ -110,37 +117,44 @@ suspend fun TelegramBot.sendVisualMediaGroup( chat: Chat, media: List, disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null ) = sendVisualMediaGroup( - chat.id, media, disableNotification, replyToMessageId + chat.id, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) +@RiskFeature(rawSendingMediaGroupsWarning) suspend inline fun TelegramBot.replyWithMediaGroup( to: Message, media: List, - disableNotification: Boolean = false -) = sendMediaGroup(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithPlaylist( to: Message, media: List, - disableNotification: Boolean = false -) = sendPlaylist(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendPlaylist(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithDocumentsGroup( to: Message, media: List, - disableNotification: Boolean = false -) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendDocumentsGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.replyWithVisualMediaGroup( to: Message, media: List, - disableNotification: Boolean = false -) = sendVisualMediaGroup(to.chat, media, disableNotification, to.messageId) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = sendVisualMediaGroup(to.chat, media, disableNotification, to.messageId, allowSendingWithoutReply) suspend inline fun TelegramBot.reply( to: Message, media: List, - disableNotification: Boolean = false -) = replyWithMediaGroup(to, media, disableNotification) + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null +) = replyWithMediaGroup(to, media, disableNotification, allowSendingWithoutReply) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt index 6f12590f0d..d4ee9ed59d 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendPhoto @@ -19,6 +20,7 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendPhoto( @@ -28,6 +30,7 @@ suspend fun TelegramBot.sendPhoto( parseMode, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -39,8 +42,9 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, fileId, caption, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendPhoto(chat.id, fileId, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendPhoto( chatId: ChatIdentifier, @@ -49,8 +53,9 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), caption, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendPhoto( chat: Chat, @@ -59,8 +64,9 @@ suspend fun TelegramBot.sendPhoto( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, photo, caption, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendPhoto(chat.id, photo, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( to: Message, @@ -68,8 +74,9 @@ suspend inline fun TelegramBot.replyWithPhoto( caption: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, fileId, caption, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendPhoto(to.chat, fileId, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( to: Message, @@ -77,8 +84,9 @@ suspend inline fun TelegramBot.replyWithPhoto( caption: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photo, caption, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendPhoto(to.chat, photo, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -86,5 +94,84 @@ suspend inline fun TelegramBot.reply( caption: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithPhoto(to, photo, caption, parseMode, disableNotification, replyMarkup) +) = replyWithPhoto(to, photo, caption, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendPhoto( + chatId: ChatIdentifier, + fileId: InputFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendPhoto( + chatId, + fileId, + entities, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendPhoto( + chat: Chat, + fileId: InputFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(chat.id, fileId, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendPhoto( + chatId: ChatIdentifier, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendPhoto( + chat: Chat, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(chat.id, photo, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + fileId: InputFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, fileId, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithPhoto( + to: Message, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendPhoto(to.chat, photo, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + photo: Photo, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithPhoto(to, photo, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt index 9e4b7aad50..9f7cac00f5 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt @@ -15,9 +15,10 @@ suspend fun TelegramBot.sendSticker( sticker: InputFile, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( - SendSticker(chatId, sticker, disableNotification, replyToMessageId, replyMarkup) + SendSticker(chatId, sticker, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendSticker( @@ -25,42 +26,48 @@ suspend fun TelegramBot.sendSticker( sticker: InputFile, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, replyMarkup) +) = sendSticker(chat.id, sticker, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendSticker( chatId: ChatIdentifier, sticker: Sticker, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(chatId, sticker.fileId, disableNotification, replyToMessageId, replyMarkup) +) = sendSticker(chatId, sticker.fileId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendSticker( chat: Chat, sticker: Sticker, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(chat, sticker.fileId, disableNotification, replyToMessageId, replyMarkup) +) = sendSticker(chat, sticker.fileId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithSticker( to: Message, sticker: InputFile, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(to.chat, sticker, disableNotification, to.messageId, replyMarkup) +) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithSticker( to: Message, sticker: Sticker, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendSticker(to.chat, sticker, disableNotification, to.messageId, replyMarkup) +) = sendSticker(to.chat, sticker, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, sticker: Sticker, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithSticker(to, sticker, disableNotification, replyMarkup) +) = replyWithSticker(to, sticker, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt index c58d9ca661..962b265ace 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVideo @@ -22,6 +23,7 @@ suspend fun TelegramBot.sendVideo( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVideo( @@ -36,6 +38,7 @@ suspend fun TelegramBot.sendVideo( null, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -47,8 +50,9 @@ suspend fun TelegramBot.sendVideo( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, video.duration, video.width, video.height, disableNotification, replyToMessageId, replyMarkup) +) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, video.duration, video.width, video.height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVideo( chat: Chat, @@ -61,8 +65,9 @@ suspend fun TelegramBot.sendVideo( height: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, replyMarkup) +) = sendVideo(chat.id, video, thumb, text, parseMode, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVideo( @@ -72,8 +77,9 @@ suspend fun TelegramBot.sendVideo( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, text, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendVideo(chat.id, video, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideo( to: Message, @@ -85,8 +91,9 @@ suspend inline fun TelegramBot.replyWithVideo( width: Int? = null, height: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, disableNotification, to.messageId, replyMarkup) +) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideo( to: Message, @@ -94,8 +101,9 @@ suspend inline fun TelegramBot.replyWithVideo( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, text, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendVideo(to.chat, video, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -103,5 +111,102 @@ suspend inline fun TelegramBot.reply( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVideo(to, video, text, parseMode, disableNotification, replyMarkup) +) = replyWithVideo(to, video, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendVideo( + chatId: ChatIdentifier, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVideo( + chatId, + video, + thumb, + entities, + duration, + width, + height, + null, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendVideo( + chatId: ChatIdentifier, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, entities, video.duration, video.width, video.height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendVideo( + chat: Chat, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(chat.id, video, thumb, entities, duration, width, height, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendVideo( + chat: Chat, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(chat.id, video, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: InputFile, + thumb: InputFile? = null, + entities: List, + duration: Long? = null, + width: Int? = null, + height: Int? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, thumb, entities, duration, width, height, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVideo( + to: Message, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVideo(to.chat, video, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + video: VideoFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithVideo(to, video, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt index 7eb6b9f4a5..7bebc92be5 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideoNote.kt @@ -5,10 +5,8 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVideoNote import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.files.VideoFile import dev.inmo.tgbotapi.types.files.VideoNoteFile import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -16,24 +14,22 @@ suspend fun TelegramBot.sendVideoNote( chatId: ChatIdentifier, videoNote: InputFile, thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVideoNote( chatId, videoNote, thumb, - text, - parseMode, duration, size, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -41,64 +37,58 @@ suspend fun TelegramBot.sendVideoNote( suspend fun TelegramBot.sendVideoNote( chatId: ChatIdentifier, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVideoNote( - chatId, videoNote.fileId, videoNote.thumb ?.fileId, text, parseMode, videoNote.duration, videoNote.width, disableNotification, replyToMessageId, replyMarkup + chatId, videoNote.fileId, videoNote.thumb ?.fileId, videoNote.duration, videoNote.width, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendVideoNote( chat: Chat, videoNote: InputFile, thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(chat.id, videoNote, thumb, text, parseMode, duration, size, disableNotification, replyToMessageId, replyMarkup) +) = sendVideoNote(chat.id, videoNote, thumb, duration, size, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVideoNote( chat: Chat, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(chat.id, videoNote, text, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendVideoNote(chat.id, videoNote, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideoNote( to: Message, videoNote: InputFile, thumb: InputFile? = null, - text: String? = null, - parseMode: ParseMode? = null, duration: Long? = null, size: Int? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(to.chat, videoNote, thumb, text, parseMode, duration, size, disableNotification, to.messageId, replyMarkup) +) = sendVideoNote(to.chat, videoNote, thumb, duration, size, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideoNote( to: Message, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideoNote(to.chat, videoNote, text, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendVideoNote(to.chat, videoNote, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, videoNote: VideoNoteFile, - text: String? = null, - parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVideoNote(to, videoNote, text, parseMode, disableNotification, replyMarkup) +) = replyWithVideoNote(to, videoNote, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt index 68c63a91fe..21b87b0e66 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVoice.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.media +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.send.media.SendVoice @@ -8,7 +9,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.files.VoiceFile import dev.inmo.tgbotapi.types.message.abstracts.Message @@ -20,6 +20,7 @@ suspend fun TelegramBot.sendVoice( duration: Long? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendVoice( @@ -30,6 +31,7 @@ suspend fun TelegramBot.sendVoice( duration, disableNotification, replyToMessageId, + allowSendingWithoutReply, replyMarkup ) ) @@ -42,8 +44,9 @@ suspend fun TelegramBot.sendVoice( duration: Long? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(chat.id, voice, text, parseMode, duration, disableNotification, replyToMessageId, replyMarkup) +) = sendVoice(chat.id, voice, text, parseMode, duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendVoice( chatId: ChatIdentifier, @@ -52,9 +55,10 @@ suspend fun TelegramBot.sendVoice( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendVoice( - chatId, voice.fileId, text, parseMode, voice.duration, disableNotification, replyToMessageId, replyMarkup + chatId, voice.fileId, text, parseMode, voice.duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendVoice( @@ -64,8 +68,9 @@ suspend fun TelegramBot.sendVoice( parseMode: ParseMode? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(chat.id, voice, text, parseMode, disableNotification, replyToMessageId, replyMarkup) +) = sendVoice(chat.id, voice, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVoice( to: Message, @@ -74,8 +79,9 @@ suspend inline fun TelegramBot.replyWithVoice( parseMode: ParseMode? = null, duration: Long? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, text, parseMode, duration, disableNotification, to.messageId, replyMarkup) +) = sendVoice(to.chat, voice, text, parseMode, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVoice( to: Message, @@ -83,8 +89,9 @@ suspend inline fun TelegramBot.replyWithVoice( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVoice(to.chat, voice, text, parseMode, disableNotification, to.messageId, replyMarkup) +) = sendVoice(to.chat, voice, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, @@ -92,5 +99,90 @@ suspend inline fun TelegramBot.reply( text: String? = null, parseMode: ParseMode? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = replyWithVoice(to, voice, text, parseMode, disableNotification, replyMarkup) +) = replyWithVoice(to, voice, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) + + +suspend inline fun TelegramBot.sendVoice( + chatId: ChatIdentifier, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendVoice( + chatId, + voice, + entities, + duration, + disableNotification, + replyToMessageId, + allowSendingWithoutReply, + replyMarkup + ) +) + +suspend inline fun TelegramBot.sendVoice( + chat: Chat, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(chat.id, voice, entities, duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.sendVoice( + chatId: ChatIdentifier, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice( + chatId, voice.fileId, entities, voice.duration, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.sendVoice( + chat: Chat, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(chat.id, voice, entities, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: InputFile, + entities: List, + duration: Long? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, entities, duration, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithVoice( + to: Message, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVoice(to.chat, voice, entities, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.reply( + to: Message, + voice: VoiceFile, + entities: List, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = replyWithVoice(to, voice, entities, disableNotification, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt index ee04707a50..3af85856f1 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/payments/SendInvoice.kt @@ -27,9 +27,10 @@ suspend fun TelegramBot.sendInvoice( priceDependOnShipAddress: Boolean = false, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null ) = execute( - SendInvoice(chatId, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, replyMarkup) + SendInvoice(chatId, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) suspend fun TelegramBot.sendInvoice( @@ -51,8 +52,9 @@ suspend fun TelegramBot.sendInvoice( priceDependOnShipAddress: Boolean = false, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = sendInvoice(user.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, replyMarkup) +) = sendInvoice(user.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithInvoice( to: Message, @@ -72,5 +74,6 @@ suspend inline fun TelegramBot.replyWithInvoice( shouldSendEmailToProvider: Boolean = false, priceDependOnShipAddress: Boolean = false, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: InlineKeyboardMarkup? = null -) = sendInvoice(to.chat.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, replyMarkup) +) = sendInvoice(to.chat.id, title, description, payload, providerToken, startParameter, currency, prices, providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt index 674214eef0..d95c63c464 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/polls/SendPoll.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.extensions.api.send.polls +import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.polls.SendQuizPoll import dev.inmo.tgbotapi.requests.send.polls.SendRegularPoll @@ -21,10 +22,11 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendRegularPoll( - chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup + chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) suspend fun TelegramBot.sendRegularPoll( @@ -38,8 +40,9 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup) +) = sendRegularPoll(chatId, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) suspend fun TelegramBot.sendRegularPoll( chat: Chat, @@ -51,9 +54,10 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendRegularPoll( - chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendRegularPoll( @@ -67,9 +71,10 @@ suspend fun TelegramBot.sendRegularPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendRegularPoll( - chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) @@ -85,10 +90,11 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = execute( SendQuizPoll( - chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) ) @@ -104,9 +110,10 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendQuizPoll( - chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendQuizPoll( @@ -122,9 +129,10 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendQuizPoll( - chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chatId, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend fun TelegramBot.sendQuizPoll( @@ -140,9 +148,83 @@ suspend fun TelegramBot.sendQuizPoll( closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendQuizPoll( - chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, replyMarkup + chat.id, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + + +suspend inline fun TelegramBot.sendQuizPoll( + chatId: ChatIdentifier, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendQuizPoll( + chatId, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup + ) +) + +suspend inline fun TelegramBot.sendQuizPoll( + chat: Chat, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chat.id, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.sendQuizPoll( + chatId: ChatIdentifier, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chatId, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup +) + +suspend inline fun TelegramBot.sendQuizPoll( + chat: Chat, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll( + chat.id, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup ) suspend inline fun TelegramBot.replyWithRegularPoll( @@ -154,8 +236,9 @@ suspend inline fun TelegramBot.replyWithRegularPoll( allowMultipleAnswers: Boolean = false, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(to.chat, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendRegularPoll(to.chat, question, options, isAnonymous, isClosed, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithRegularPoll( to: Message, @@ -167,8 +250,9 @@ suspend inline fun TelegramBot.replyWithRegularPoll( allowMultipleAnswers: Boolean = poll.allowMultipleAnswers, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendRegularPoll(to.chat, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendRegularPoll(to.chat, poll, isClosed, question, options, isAnonymous, allowMultipleAnswers, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, @@ -181,8 +265,9 @@ suspend inline fun TelegramBot.replyWithQuizPoll( parseMode: ParseMode? = null, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithQuizPoll( to: Message, @@ -196,6 +281,35 @@ suspend inline fun TelegramBot.replyWithQuizPoll( parseMode: ParseMode? = null, closeInfo: ScheduledCloseInfo? = null, disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, disableNotification, to.messageId, replyMarkup) +) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, explanation, parseMode, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) +suspend inline fun TelegramBot.replyWithQuizPoll( + to: Message, + question: String, + options: List, + correctOptionId: Int, + isAnonymous: Boolean = true, + isClosed: Boolean = false, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, question, options, correctOptionId, isAnonymous, isClosed, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) + +suspend inline fun TelegramBot.replyWithQuizPoll( + to: Message, + isClosed: Boolean = false, + quizPoll: QuizPoll, + question: String = quizPoll.question, + options: List = quizPoll.options.map { it.text }, + correctOptionId: Int = quizPoll.correctOptionId ?: error("Correct option ID must be provided by income QuizPoll or by developer"), + isAnonymous: Boolean = quizPoll.isAnonymous, + entities: List, + closeInfo: ScheduledCloseInfo? = null, + disableNotification: Boolean = false, + allowSendingWithoutReply: Boolean? = null, + replyMarkup: KeyboardMarkup? = null +) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt index 375d22301c..bf2730daae 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt @@ -10,11 +10,13 @@ import dev.inmo.tgbotapi.requests.webhook.SetWebhook */ suspend fun TelegramBot.setWebhookInfo( url: String, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ) = execute( SetWebhook( - url, maxAllowedConnections, allowedUpdates + url, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates ) ) @@ -24,11 +26,13 @@ suspend fun TelegramBot.setWebhookInfo( suspend fun TelegramBot.setWebhookInfo( url: String, certificate: FileId, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ) = execute( SetWebhook( - url, certificate, maxAllowedConnections, allowedUpdates + url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates ) ) @@ -38,10 +42,12 @@ suspend fun TelegramBot.setWebhookInfo( suspend fun TelegramBot.setWebhookInfo( url: String, certificate: MultipartFile, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ) = execute( SetWebhook( - url, certificate, maxAllowedConnections, allowedUpdates + url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates ) ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt index ad8ab08006..6add07d0b8 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SafelyShortcut.kt @@ -1,16 +1,18 @@ package dev.inmo.tgbotapi.extensions.utils +import dev.inmo.micro_utils.coroutines.ExceptionHandler import dev.inmo.tgbotapi.utils.* import kotlinx.coroutines.CoroutineScope /** - * Shortcut for [handleSafely]. It was created for more comfortable way of handling different things + * Shortcut for [dev.inmo.micro_utils.coroutines.safely]. It was created for more comfortable way of handling different things */ @PreviewFeature +@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely")) suspend inline fun safely( noinline onException: ExceptionHandler = { throw it }, noinline block: suspend CoroutineScope.() -> T -): T = handleSafely( +): T = dev.inmo.micro_utils.coroutines.safely( onException, block ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt index 091c0fec86..66283981a9 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Foursquare.kt @@ -1,21 +1,22 @@ package dev.inmo.tgbotapi.extensions.utils.extensions.venue import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.venue.Venue import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable val Venue.foursquare: Foursquare? - get() = foursquareId ?.let { + get() = foursquareId?.let { Foursquare(it, foursquareType) } fun Venue( - location: Location, + location: StaticLocation, title: String, address: String, foursquare: Foursquare -) = Venue(location, title, address, foursquare.id, foursquare.type) +) = Venue(location, title, address, foursquareId = foursquare.id, foursquareType = foursquare.type) @Serializable data class Foursquare( diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt new file mode 100644 index 0000000000..04ea6a6c62 --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/venue/Google.kt @@ -0,0 +1,27 @@ +package dev.inmo.tgbotapi.extensions.utils.extensions.venue + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.location.StaticLocation +import dev.inmo.tgbotapi.types.venue.Venue +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +val Venue.googlePlace: GooglePlace? + get() = googlePlaceId?.let { + GooglePlace(it, googlePlaceType) + } + +fun Venue( + location: StaticLocation, + title: String, + address: String, + googlePlace: GooglePlace +) = Venue(location, title, address, googlePlaceId = googlePlace.id, googlePlaceType = googlePlace.type) + +@Serializable +data class GooglePlace( + @SerialName(googlePlaceIdField) + val id: GooglePlaceId, + @SerialName(googlePlaceTypeField) + val type: GooglePlaceType? = null +) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt index 68fbaf58fb..a459574b13 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.fullEntitiesList fun createFormattedText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last, mode: ParseMode = MarkdownParseMode ): List { @@ -48,23 +48,23 @@ fun createFormattedText( fun createMarkdownText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownParseMode) -fun FullTextSourcesList.toMarkdownCaptions(): List = createMarkdownText( +fun TextSourcesList.toMarkdownCaptions(): List = createMarkdownText( this, captionLength.last ) fun CaptionedInput.toMarkdownCaptions(): List = fullEntitiesList().toMarkdownCaptions() -fun FullTextSourcesList.toMarkdownTexts(): List = createMarkdownText( +fun TextSourcesList.toMarkdownTexts(): List = createMarkdownText( this, textLength.last ) fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() -fun FullTextSourcesList.toMarkdownExplanations(): List = createMarkdownText( +fun TextSourcesList.toMarkdownExplanations(): List = createMarkdownText( this, explanationLimit.last ) @@ -72,23 +72,23 @@ fun ExplainedInput.toMarkdownExplanations(): List = fullEntitiesList().t fun createMarkdownV2Text( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, MarkdownV2ParseMode) -fun FullTextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( +fun TextSourcesList.toMarkdownV2Captions(): List = createMarkdownV2Text( this, captionLength.last ) fun CaptionedInput.toMarkdownV2Captions(): List = fullEntitiesList().toMarkdownV2Captions() -fun FullTextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( +fun TextSourcesList.toMarkdownV2Texts(): List = createMarkdownV2Text( this, textLength.last ) fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() -fun FullTextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( +fun TextSourcesList.toMarkdownV2Explanations(): List = createMarkdownV2Text( this, explanationLimit.last ) @@ -96,23 +96,23 @@ fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntitiesList() fun createHtmlText( - entities: FullTextSourcesList, + entities: TextSourcesList, partLength: Int = textLength.last ): List = createFormattedText(entities, partLength, HTMLParseMode) -fun FullTextSourcesList.toHtmlCaptions(): List = createHtmlText( +fun TextSourcesList.toHtmlCaptions(): List = createHtmlText( this, captionLength.last ) fun CaptionedInput.toHtmlCaptions(): List = fullEntitiesList().toHtmlCaptions() -fun FullTextSourcesList.toHtmlTexts(): List = createHtmlText( +fun TextSourcesList.toHtmlTexts(): List = createHtmlText( this, textLength.last ) fun TextContent.toHtmlTexts(): List = fullEntitiesList().toHtmlTexts() -fun FullTextSourcesList.toHtmlExplanations(): List = createHtmlText( +fun TextSourcesList.toHtmlExplanations(): List = createHtmlText( this, explanationLimit.last ) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt index 61169cc7f5..3a1e40f55f 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/PollCloseShortcuts.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts +import com.soywiz.klock.DateTime +import com.soywiz.klock.TimeSpan import dev.inmo.tgbotapi.types.LongSeconds import dev.inmo.tgbotapi.types.Seconds import dev.inmo.tgbotapi.types.polls.ApproximateScheduledCloseInfo import dev.inmo.tgbotapi.types.polls.ExactScheduledCloseInfo -import com.soywiz.klock.DateTime -import com.soywiz.klock.TimeSpan fun closePollExactAt( dateTime: DateTime diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt index aa4d9b225c..f3ba0f62e7 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/RequestsExecutor.kt @@ -1,15 +1,15 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.utils.handleSafely import kotlinx.coroutines.* fun RequestsExecutor.executeAsync( request: Request, scope: CoroutineScope ): Deferred = scope.async { - handleSafely { + safely { execute(request) } } @@ -29,7 +29,7 @@ suspend fun RequestsExecutor.executeUnsafe( var leftRetries = retries val exceptions = onAllFailed ?.let { mutableListOf() } do { - return handleSafely( + return safely ( { leftRetries-- delay(retriesDelay) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt index 69f4bc69f0..6d553cf32e 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/CommandsFilters.kt @@ -9,7 +9,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.fullEntitiesList import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow /** * Convert incoming [dev.inmo.tgbotapi.types.message.abstracts.ContentMessage.content] of diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt index 635d677f95..ab324e7771 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/InlineQueryUpdatesConversations.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.update.InlineQueryUpdate -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.Flow /** * @return Mapped [Flow] with [Pair]s. [Pair.first] in this pair will be [UpdateIdentifier]. It could be useful in diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index 03a16b401b..f6802145d1 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.bot.exceptions.RequestException import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates @@ -23,7 +25,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( var lastUpdateIdentifier: UpdateIdentifier? = null while (isActive) { - handleSafely( + safely( { e -> exceptionsHandler ?.invoke(e) if (e is RequestException) { @@ -52,7 +54,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( } } - handleSafely { + safely { for (update in updates) { updatesReceiver(update) diff --git a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt index 68594fca19..92c50173d4 100644 --- a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt +++ b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving +import dev.inmo.micro_utils.coroutines.ExceptionHandler +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.bot.RequestsExecutor import dev.inmo.tgbotapi.extensions.utils.nonstrictJsonFormat import dev.inmo.tgbotapi.extensions.utils.updates.flowsUpdatesFilter @@ -11,8 +13,6 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.UpdateDeserializationStrategy import dev.inmo.tgbotapi.updateshandlers.* import dev.inmo.tgbotapi.updateshandlers.webhook.WebhookPrivateKeyConfig -import dev.inmo.tgbotapi.utils.ExceptionHandler -import dev.inmo.tgbotapi.utils.handleSafely import io.ktor.application.call import io.ktor.request.receiveText import io.ktor.response.respond @@ -41,7 +41,7 @@ fun Route.includeWebhookHandlingInRoute( ) { val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block) post { - handleSafely( + safely( exceptionsHandler ?: {} ) { val asJson = diff --git a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt index 90be566896..2c70dd1c2b 100644 --- a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt +++ b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.types.files -import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import java.io.File import java.io.FileOutputStream