diff --git a/CHANGELOG.md b/CHANGELOG.md index 491ddf25e6..42534de13f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,12 +49,28 @@ * `closePollExactAfter` * `closePollAfter` +### 0.27.8 + +* `TelegramBotAPI`: + * `UnknownUpdateType` was renamed to `UnknownUpdate` + * Refactoring and optimization of `FlowsUpdatesFilter` + * `Venue` type was replaced to a new package: `com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue` + * `Venue` type now implements `Locationed` and delegate realisation to its `location` field + * `FoursquareId` and `FoursquareType` typealiases were added +* `TelegramBotAPI-extensions-utils`: + * Several new functions `makeLinkToMessage` was added + * `Foursquare` data class was added + * Extension `Venue#foursquare` was added + * Factory function `Venue` with `Foursquare` parameter was added + ### 0.27.7 * `TelegramBotAPI`: * Operator function `unaryPlus` was added to `RowBuilder`. Now it is possible to write `row { +button }` * Function `flatMatrix` was added for single-row columns * Operator extension `RowBuilder#plus` was added to be able to write things like `row { this + button }` +* `TelegramBotAPI-extensions-api`: + * Extensions `RequestsExecutor#sendVenue` with `Location` args were added * `TelegramBotAPI-extensions-utils`: * Function `InlineKeyboardMarkup` for flat keyboards was added * Function `ReplyKeyboardMarkup` for flat keyboards was added diff --git a/README.md b/README.md index 642b9d1811..ab6fe369ba 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,7 @@ | Common info | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI.svg?branch=master)](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) | | -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| Useful links | • [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) | -| | • [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) | -| | • [![Chat in Telegram](badges/chat.svg)](https://teleg.one/InMoTelegramBotAPI) | -| | • [![KDocs](badges/kdocs.svg)](https://tgbotapi.inmo.dev/docs/index.html) | +| Useful links | [![Chat in Telegram](badges/chat.svg)](https://teleg.one/InMoTelegramBotAPI) [![KDocs](badges/kdocs.svg)](https://tgbotapi.inmo.dev/docs/index.html) [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/), [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) | | TelegramBotAPI status | [![Download](https://api.bintray.com/packages/insanusmokrassar/StandardRepository/TelegramBotAPI/images/download.svg)](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI) | | TelegramBotAPI Extensions status | [![Download](https://api.bintray.com/packages/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-api/images/download.svg)](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-api/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-api) | | TelegramBotAPI Util Extensions status | [![Download](https://api.bintray.com/packages/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-utils/images/download.svg)](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI-extensions-utils/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.insanusmokrassar/TelegramBotAPI-extensions-utils) | diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendVenue.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendVenue.kt index 4f358d4ad3..f29e72b7cf 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendVenue.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendVenue.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendVenue import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue suspend fun RequestsExecutor.sendVenue( chatId: ChatIdentifier, @@ -36,6 +37,32 @@ suspend fun RequestsExecutor.sendVenue( chat.id, latitude, longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup ) +suspend fun RequestsExecutor.sendVenue( + chatId: ChatIdentifier, + location: Location, + title: String, + address: String, + foursquareId: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVenue( + chatId, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendVenue( + chat: Chat, + location: Location, + title: String, + address: String, + foursquareId: String? = null, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendVenue( + chat.id, location.latitude, location.longitude, title, address, foursquareId, disableNotification, replyToMessageId, replyMarkup +) + suspend fun RequestsExecutor.sendVenue( chatId: ChatIdentifier, venue: Venue, diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt index 4c05dc0a95..a27034cf96 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt @@ -76,7 +76,7 @@ fun RequestsExecutor.startGettingFlowsUpdates( timeoutSeconds: Seconds = 30, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), exceptionsHandler: (suspend (Exception) -> Unit)? = null, - flowsUpdatesFilterUpdatesKeeperCount: Int = 64, + flowsUpdatesFilterUpdatesKeeperCount: Int = 100, flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {} ): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply { flowUpdatesPreset() diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/extensions/venue/Foursquare.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/extensions/venue/Foursquare.kt new file mode 100644 index 0000000000..aa95e3ad40 --- /dev/null +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/extensions/venue/Foursquare.kt @@ -0,0 +1,26 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.extensions.venue + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +val Venue.foursquare: Foursquare? + get() = foursquareId ?.let { + Foursquare(it, foursquareType) + } + +fun Venue( + location: Location, + title: String, + address: String, + foursquare: Foursquare +) = Venue(location, title, address, foursquare.id, foursquare.type) + +@Serializable +data class Foursquare( + @SerialName(foursquareIdField) + val id: FoursquareId, + @SerialName(foursquareTypeField) + val type: FoursquareType? = null +) diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt index 1bd86d26d5..3959d7a9b2 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/formatting/LinksFormatting.kt @@ -1,8 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.formatting -import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.* -import com.github.insanusmokrassar.TelegramBotAPI.types.StickerSetName import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat @@ -14,6 +13,14 @@ fun makeLinkToMessage( username: String, messageId: MessageIdentifier ): String = "$internalLinkBeginning/$username/$messageId" +fun makeLinkToMessage( + username: Username, + messageId: MessageIdentifier +): String = makeLinkToMessage(username.username, messageId) +fun makeLinkToMessage( + chat: UsernameChat, + messageId: MessageIdentifier +): String? = chat.username ?.let { makeLinkToMessage(it, messageId) } private val linkIdRedundantPartRegex = Regex("^-100") private val usernameBeginSymbolRegex = Regex("^@") diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/MediaGroupsShortcuts.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/MediaGroupsShortcuts.kt index ea2fc6bfb8..208a7904b9 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/MediaGroupsShortcuts.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/shortcuts/MediaGroupsShortcuts.kt @@ -4,7 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendMediaG import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.SentMediaGroupUpdate val List.forwardInfo: ForwardInfo? diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/InlineKeyboardMarkup.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/InlineKeyboardMarkup.kt index 9752514036..af50542ebf 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/InlineKeyboardMarkup.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/InlineKeyboardMarkup.kt @@ -1,8 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.types.buttons -import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.InlineKeyboardButton -import com.github.insanusmokrassar.TelegramBotAPI.utils.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.utils.flatMatrix fun InlineKeyboardMarkup( vararg buttons: InlineKeyboardButton diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt index 473bc131ce..161543c25f 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.types.buttons -import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.ReplyKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardButton +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.ReplyKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.utils.flatMatrix fun ReplyKeyboardMarkup( diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/BaseMessagesUpdatesConversations.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/BaseMessagesUpdatesConversations.kt index 1280b4a397..493fae288f 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/BaseMessagesUpdatesConversations.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/BaseMessagesUpdatesConversations.kt @@ -3,25 +3,19 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.* import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.mapNotNull +import kotlinx.coroutines.flow.filterIsInstance -fun Flow.onlyBaseMessageUpdates(): Flow = mapNotNull { - it as? BaseMessageUpdate -} +fun Flow.onlyBaseMessageUpdates(): Flow = filterIsInstance() /** * Converts flow to [Flow] of [BaseSentMessageUpdate] */ -fun Flow.onlySentMessageUpdates(): Flow = mapNotNull { - it as? BaseSentMessageUpdate -} +fun Flow.onlySentMessageUpdates(): Flow = filterIsInstance() /** * Converts flow to [Flow] of [BaseSentMessageUpdate] */ -fun Flow.onlyEditMessageUpdates(): Flow = mapNotNull { - it as? BaseEditMessageUpdate -} +fun Flow.onlyEditMessageUpdates(): Flow = filterIsInstance() /** * Converts flow to [Flow] of [MediaGroupUpdate]. Please, remember that it could be either [EditMediaGroupUpdate] @@ -30,20 +24,14 @@ fun Flow.onlyEditMessageUpdates(): Flow.onlyMediaGroupsUpdates(): Flow = mapNotNull { - it as? MediaGroupUpdate -} +fun Flow.onlyMediaGroupsUpdates(): Flow = filterIsInstance() /** * Converts flow to [Flow] of [SentMediaGroupUpdate] */ -fun Flow.onlySentMediaGroupUpdates(): Flow = mapNotNull { - it as? SentMediaGroupUpdate -} +fun Flow.onlySentMediaGroupUpdates(): Flow = filterIsInstance() /** * Converts flow to [Flow] of [EditMediaGroupUpdate] */ -fun Flow.onlyEditMediaGroupUpdates(): Flow = mapNotNull { - it as? EditMediaGroupUpdate -} +fun Flow.onlyEditMediaGroupUpdates(): Flow = filterIsInstance() diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt index 08d3cb7b77..f7fd6cbad2 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/FlowsUpdatesFactory.kt @@ -8,7 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFi * @see flowsUpdatesFilter */ inline fun flowsUpdatesFilter( - internalChannelsSizes: Int = 64, + internalChannelsSizes: Int = 100, block: FlowsUpdatesFilter.() -> Unit ): FlowsUpdatesFilter { val filter = FlowsUpdatesFilter(internalChannelsSizes) diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/LongPolling.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/LongPolling.kt index 10d9003d61..6fbd655048 100644 --- a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/LongPolling.kt +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/LongPolling.kt @@ -76,7 +76,7 @@ fun RequestsExecutor.startGettingFlowsUpdatesByLongPolling( timeoutSeconds: Seconds = 30, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), exceptionsHandler: ExceptionHandler? = null, - flowsUpdatesFilterUpdatesKeeperCount: Int = 64, + flowsUpdatesFilterUpdatesKeeperCount: Int = 100, flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {} ): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply { flowUpdatesPreset() diff --git a/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt b/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt index ef379eb7be..0434a385c9 100644 --- a/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt +++ b/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt @@ -18,7 +18,8 @@ import io.ktor.request.receiveText import io.ktor.response.respond import io.ktor.routing.* import io.ktor.server.engine.* -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt index 18e3931cfe..1ca4c91d01 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendVenue.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.VenueContent +import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 2fb043f7bd..f1ad390052 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -22,6 +22,8 @@ typealias PollIdentifier = String typealias StickerSetName = String typealias FileUniqueId = String typealias DiceResult = Int +typealias FoursquareId = String +typealias FoursquareType = String typealias Seconds = Int typealias LongSeconds = Long diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Venue.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Venue.kt index ee6928b46c..6d6adef5e5 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Venue.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Venue.kt @@ -1,19 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CommonVenueData -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable +import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue -@Serializable -data class Venue( - @SerialName(locationField) - val location: Location, - @SerialName(titleField) - override val title: String, - @SerialName(addressField) - override val address: String, - @SerialName(foursquareIdField) - override val foursquareId: String? = null, - @SerialName(foursquareTypeField) - override val foursquareType: String? = null -) : CommonVenueData +@Deprecated("Replaced", ReplaceWith("Venue", "com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue")) +typealias Venue = Venue diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt index 15bea82224..3d1ecb22f1 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt @@ -3,7 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage import com.soywiz.klock.DateTime diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt index 08c2b32bab..357aa57d97 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt @@ -3,7 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.FromUserMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.SuccessfulPaymentInfo diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 92ef9049ea..5786d90b4b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -20,6 +20,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.Success import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice import com.github.insanusmokrassar.TelegramBotAPI.types.payments.SuccessfulPayment import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll +import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlin.reflect.KClass diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/VenueContent.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/VenueContent.kt index 27a191cf55..a95e1797c9 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/VenueContent.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/VenueContent.kt @@ -2,10 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendVenue -import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent +import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue data class VenueContent( val venue: Venue diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt index 809c0ea145..b5e7f8f395 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt @@ -9,7 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuer import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll import com.github.insanusmokrassar.TelegramBotAPI.types.polls.PollAnswer -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdate import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField import kotlinx.serialization.* @@ -57,7 +57,7 @@ internal data class RawUpdate constructor( pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query) poll != null -> PollUpdate(updateId, poll) poll_answer != null -> PollAnswerUpdate(updateId, poll_answer) - else -> UnknownUpdateType( + else -> UnknownUpdate( updateId, raw.toString(), raw @@ -66,7 +66,7 @@ internal data class RawUpdate constructor( } catch (e: Error) { when (e) { is SerializationException, - is NotImplementedError -> UnknownUpdateType( + is NotImplementedError -> UnknownUpdate( updateId, raw.toString(), raw diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt index 874d3860fc..24be238958 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/abstracts/Update.kt @@ -12,11 +12,13 @@ interface Update { val data: Any } -data class UnknownUpdateType( +data class UnknownUpdate( override val updateId: UpdateIdentifier, override val data: String, val rawJson: JsonElement ) : Update +@Deprecated("Renamed", ReplaceWith("UnknownUpdate")) +typealias UnknownUpdateType = UnknownUpdate internal object UpdateSerializerWithoutSerialization : KSerializer { override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/venue/Venue.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/venue/Venue.kt new file mode 100644 index 0000000000..9b3565e05d --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/venue/Venue.kt @@ -0,0 +1,21 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.venue + +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CommonVenueData +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Locationed +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class Venue( + @SerialName(locationField) + val location: Location, + @SerialName(titleField) + override val title: String, + @SerialName(addressField) + override val address: String, + @SerialName(foursquareIdField) + override val foursquareId: FoursquareId? = null, + @SerialName(foursquareTypeField) + override val foursquareType: FoursquareType? = null +) : CommonVenueData, Locationed by location diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt index 052e1a8f03..dc95e3a6ea 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt @@ -1,74 +1,41 @@ package com.github.insanusmokrassar.TelegramBotAPI.updateshandlers +import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdate import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import kotlinx.coroutines.channels.BroadcastChannel -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.asFlow - -@Suppress("EXPERIMENTAL_API_USAGE") -private fun BroadcastChannel.createUpdateReceiver(): UpdateReceiver = ::send +import kotlinx.coroutines.flow.* @Suppress("EXPERIMENTAL_API_USAGE", "unused") class FlowsUpdatesFilter( - broadcastChannelsSize: Int = 64 + broadcastChannelsSize: Int = 100 ): UpdatesFilter { - private val messageChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val messageMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val editedMessageChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val editedMessageMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val channelPostChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val channelPostMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val editedChannelPostChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val editedChannelPostMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val chosenInlineResultChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val inlineQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val callbackQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val shippingQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val preCheckoutQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val pollChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val pollAnswerChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) - private val unknownUpdateChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) + private val updatesReceivingChannel = BroadcastChannel(broadcastChannelsSize) + @Suppress("MemberVisibilityCanBePrivate") + val allUpdatesFlow: Flow = updatesReceivingChannel.asFlow() override val allowedUpdates: List - get() = filter.allowedUpdates - override val asUpdateReceiver: UpdateReceiver - get() = filter.asUpdateReceiver + get() = ALL_UPDATES_LIST + override val asUpdateReceiver: UpdateReceiver = { + updatesReceivingChannel.send(it) + } - val filter = SimpleUpdatesFilter( - messageChannel.createUpdateReceiver(), - messageMediaGroupChannel.createUpdateReceiver(), - editedMessageChannel.createUpdateReceiver(), - editedMessageMediaGroupChannel.createUpdateReceiver(), - channelPostChannel.createUpdateReceiver(), - channelPostMediaGroupChannel.createUpdateReceiver(), - editedChannelPostChannel.createUpdateReceiver(), - editedChannelPostMediaGroupChannel.createUpdateReceiver(), - chosenInlineResultChannel.createUpdateReceiver(), - inlineQueryChannel.createUpdateReceiver(), - callbackQueryChannel.createUpdateReceiver(), - shippingQueryChannel.createUpdateReceiver(), - preCheckoutQueryChannel.createUpdateReceiver(), - pollChannel.createUpdateReceiver(), - pollAnswerChannel.createUpdateReceiver(), - unknownUpdateChannel.createUpdateReceiver() - ) - - val messageFlow: Flow = messageChannel.asFlow() - val messageMediaGroupFlow: Flow = messageMediaGroupChannel.asFlow() - val editedMessageFlow: Flow = editedMessageChannel.asFlow() - val editedMessageMediaGroupFlow: Flow = editedMessageMediaGroupChannel.asFlow() - val channelPostFlow: Flow = channelPostChannel.asFlow() - val channelPostMediaGroupFlow: Flow = channelPostMediaGroupChannel.asFlow() - val editedChannelPostFlow: Flow = editedChannelPostChannel.asFlow() - val editedChannelPostMediaGroupFlow: Flow = editedChannelPostMediaGroupChannel.asFlow() - val chosenInlineResultFlow: Flow = chosenInlineResultChannel.asFlow() - val inlineQueryFlow: Flow = inlineQueryChannel.asFlow() - val callbackQueryFlow: Flow = callbackQueryChannel.asFlow() - val shippingQueryFlow: Flow = shippingQueryChannel.asFlow() - val preCheckoutQueryFlow: Flow = preCheckoutQueryChannel.asFlow() - val pollFlow: Flow = pollChannel.asFlow() - val pollAnswerFlow: Flow = pollAnswerChannel.asFlow() - val unknownUpdateTypeFlow: Flow = unknownUpdateChannel.asFlow() + val messageFlow: Flow = allUpdatesFlow.filterIsInstance() + val messageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + val editedMessageFlow: Flow = allUpdatesFlow.filterIsInstance() + val editedMessageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + val channelPostFlow: Flow = allUpdatesFlow.filterIsInstance() + val channelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + val editedChannelPostFlow: Flow = allUpdatesFlow.filterIsInstance() + val editedChannelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + val chosenInlineResultFlow: Flow = allUpdatesFlow.filterIsInstance() + val inlineQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + val callbackQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + val shippingQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + val preCheckoutQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + val pollFlow: Flow = allUpdatesFlow.filterIsInstance() + val pollAnswerFlow: Flow = allUpdatesFlow.filterIsInstance() + val unknownUpdateTypeFlow: Flow = allUpdatesFlow.filterIsInstance() } \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt index 868484ccb1..a36789497b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt @@ -3,7 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.updateshandlers import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* -import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdateType +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UnknownUpdate import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update typealias UpdateReceiver = suspend (T) -> Unit @@ -29,7 +29,7 @@ data class SimpleUpdatesFilter( private val preCheckoutQueryCallback: UpdateReceiver? = null, private val pollUpdateCallback: UpdateReceiver? = null, private val pollAnswerUpdateCallback: UpdateReceiver? = null, - private val unknownUpdateTypeCallback: UpdateReceiver? = null + private val unknownUpdateTypeCallback: UpdateReceiver? = null ) : UpdatesFilter { override val asUpdateReceiver: UpdateReceiver = this::invoke override val allowedUpdates = listOfNotNull( @@ -83,7 +83,7 @@ data class SimpleUpdatesFilter( is PreCheckoutQueryUpdate -> preCheckoutQueryCallback ?.invoke(update) is PollUpdate -> pollUpdateCallback ?.invoke(update) is PollAnswerUpdate -> pollAnswerUpdateCallback ?.invoke(update) - is UnknownUpdateType -> unknownUpdateTypeCallback ?.invoke(update) + is UnknownUpdate -> unknownUpdateTypeCallback ?.invoke(update) } } } @@ -101,7 +101,7 @@ fun createSimpleUpdateFilter( preCheckoutQueryCallback: UpdateReceiver? = null, pollCallback: UpdateReceiver? = null, pollAnswerCallback: UpdateReceiver? = null, - unknownCallback: UpdateReceiver? = null + unknownCallback: UpdateReceiver? = null ): UpdatesFilter = SimpleUpdatesFilter( messageCallback = messageCallback, messageMediaGroupCallback = mediaGroupCallback, diff --git a/gradle.properties b/gradle.properties index 3194ec89b8..37399e77c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ ktor_version=1.3.2 javax_activation_version=1.1.1 library_group=com.github.insanusmokrassar -library_version=0.27.7 +library_version=0.27.8 gradle_bintray_plugin_version=1.8.4