mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 03:28:44 +00:00
commit
8d9ebb754b
16
CHANGELOG.md
16
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
|
||||
|
@ -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) |
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
)
|
@ -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("^@")
|
||||
|
@ -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<MediaGroupMessage>.forwardInfo: ForwardInfo?
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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<Update>.onlyBaseMessageUpdates(): Flow<BaseMessageUpdate> = mapNotNull {
|
||||
it as? BaseMessageUpdate
|
||||
}
|
||||
fun Flow<Update>.onlyBaseMessageUpdates(): Flow<BaseMessageUpdate> = filterIsInstance()
|
||||
|
||||
/**
|
||||
* Converts flow to [Flow] of [BaseSentMessageUpdate]
|
||||
*/
|
||||
fun Flow<BaseMessageUpdate>.onlySentMessageUpdates(): Flow<BaseSentMessageUpdate> = mapNotNull {
|
||||
it as? BaseSentMessageUpdate
|
||||
}
|
||||
fun Flow<BaseMessageUpdate>.onlySentMessageUpdates(): Flow<BaseSentMessageUpdate> = filterIsInstance()
|
||||
|
||||
/**
|
||||
* Converts flow to [Flow] of [BaseSentMessageUpdate]
|
||||
*/
|
||||
fun Flow<BaseMessageUpdate>.onlyEditMessageUpdates(): Flow<BaseEditMessageUpdate> = mapNotNull {
|
||||
it as? BaseEditMessageUpdate
|
||||
}
|
||||
fun Flow<BaseMessageUpdate>.onlyEditMessageUpdates(): Flow<BaseEditMessageUpdate> = filterIsInstance()
|
||||
|
||||
/**
|
||||
* Converts flow to [Flow] of [MediaGroupUpdate]. Please, remember that it could be either [EditMediaGroupUpdate]
|
||||
@ -30,20 +24,14 @@ fun Flow<BaseMessageUpdate>.onlyEditMessageUpdates(): Flow<BaseEditMessageUpdate
|
||||
* @see onlySentMediaGroupUpdates
|
||||
* @see onlyEditMediaGroupUpdates
|
||||
*/
|
||||
fun Flow<BaseMessageUpdate>.onlyMediaGroupsUpdates(): Flow<MediaGroupUpdate> = mapNotNull {
|
||||
it as? MediaGroupUpdate
|
||||
}
|
||||
fun Flow<BaseMessageUpdate>.onlyMediaGroupsUpdates(): Flow<MediaGroupUpdate> = filterIsInstance()
|
||||
|
||||
/**
|
||||
* Converts flow to [Flow] of [SentMediaGroupUpdate]
|
||||
*/
|
||||
fun Flow<MediaGroupUpdate>.onlySentMediaGroupUpdates(): Flow<SentMediaGroupUpdate> = mapNotNull {
|
||||
it as? SentMediaGroupUpdate
|
||||
}
|
||||
fun Flow<MediaGroupUpdate>.onlySentMediaGroupUpdates(): Flow<SentMediaGroupUpdate> = filterIsInstance()
|
||||
|
||||
/**
|
||||
* Converts flow to [Flow] of [EditMediaGroupUpdate]
|
||||
*/
|
||||
fun Flow<MediaGroupUpdate>.onlyEditMediaGroupUpdates(): Flow<EditMediaGroupUpdate> = mapNotNull {
|
||||
it as? EditMediaGroupUpdate
|
||||
}
|
||||
fun Flow<MediaGroupUpdate>.onlyEditMediaGroupUpdates(): Flow<EditMediaGroupUpdate> = filterIsInstance()
|
||||
|
@ -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)
|
||||
|
@ -76,7 +76,7 @@ fun RequestsExecutor.startGettingFlowsUpdatesByLongPolling(
|
||||
timeoutSeconds: Seconds = 30,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||
flowsUpdatesFilterUpdatesKeeperCount: Int = 64,
|
||||
flowsUpdatesFilterUpdatesKeeperCount: Int = 100,
|
||||
flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {}
|
||||
): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply {
|
||||
flowUpdatesPreset()
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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<ContentMessage<VenueContent>>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<Update> {
|
||||
override val descriptor: SerialDescriptor = JsonElementSerializer.descriptor
|
||||
|
@ -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
|
@ -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 <T> BroadcastChannel<T>.createUpdateReceiver(): UpdateReceiver<T> = ::send
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
@Suppress("EXPERIMENTAL_API_USAGE", "unused")
|
||||
class FlowsUpdatesFilter(
|
||||
broadcastChannelsSize: Int = 64
|
||||
broadcastChannelsSize: Int = 100
|
||||
): UpdatesFilter {
|
||||
private val messageChannel: BroadcastChannel<MessageUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val messageMediaGroupChannel: BroadcastChannel<MessageMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val editedMessageChannel: BroadcastChannel<EditMessageUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val editedMessageMediaGroupChannel: BroadcastChannel<EditMessageMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val channelPostChannel: BroadcastChannel<ChannelPostUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val channelPostMediaGroupChannel: BroadcastChannel<ChannelPostMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val editedChannelPostChannel: BroadcastChannel<EditChannelPostUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val editedChannelPostMediaGroupChannel: BroadcastChannel<EditChannelPostMediaGroupUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val chosenInlineResultChannel: BroadcastChannel<ChosenInlineResultUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val inlineQueryChannel: BroadcastChannel<InlineQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val callbackQueryChannel: BroadcastChannel<CallbackQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val shippingQueryChannel: BroadcastChannel<ShippingQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val preCheckoutQueryChannel: BroadcastChannel<PreCheckoutQueryUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val pollChannel: BroadcastChannel<PollUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val pollAnswerChannel: BroadcastChannel<PollAnswerUpdate> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val unknownUpdateChannel: BroadcastChannel<Update> = BroadcastChannel(broadcastChannelsSize)
|
||||
private val updatesReceivingChannel = BroadcastChannel<Update>(broadcastChannelsSize)
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val allUpdatesFlow: Flow<Update> = updatesReceivingChannel.asFlow()
|
||||
|
||||
override val allowedUpdates: List<String>
|
||||
get() = filter.allowedUpdates
|
||||
override val asUpdateReceiver: UpdateReceiver<Update>
|
||||
get() = filter.asUpdateReceiver
|
||||
get() = ALL_UPDATES_LIST
|
||||
override val asUpdateReceiver: UpdateReceiver<Update> = {
|
||||
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<MessageUpdate> = messageChannel.asFlow()
|
||||
val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate> = messageMediaGroupChannel.asFlow()
|
||||
val editedMessageFlow: Flow<EditMessageUpdate> = editedMessageChannel.asFlow()
|
||||
val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate> = editedMessageMediaGroupChannel.asFlow()
|
||||
val channelPostFlow: Flow<ChannelPostUpdate> = channelPostChannel.asFlow()
|
||||
val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate> = channelPostMediaGroupChannel.asFlow()
|
||||
val editedChannelPostFlow: Flow<EditChannelPostUpdate> = editedChannelPostChannel.asFlow()
|
||||
val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate> = editedChannelPostMediaGroupChannel.asFlow()
|
||||
val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate> = chosenInlineResultChannel.asFlow()
|
||||
val inlineQueryFlow: Flow<InlineQueryUpdate> = inlineQueryChannel.asFlow()
|
||||
val callbackQueryFlow: Flow<CallbackQueryUpdate> = callbackQueryChannel.asFlow()
|
||||
val shippingQueryFlow: Flow<ShippingQueryUpdate> = shippingQueryChannel.asFlow()
|
||||
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = preCheckoutQueryChannel.asFlow()
|
||||
val pollFlow: Flow<PollUpdate> = pollChannel.asFlow()
|
||||
val pollAnswerFlow: Flow<PollAnswerUpdate> = pollAnswerChannel.asFlow()
|
||||
val unknownUpdateTypeFlow: Flow<Update> = unknownUpdateChannel.asFlow()
|
||||
val messageFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val editedMessageFlow: Flow<EditMessageUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val channelPostFlow: Flow<ChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val editedChannelPostFlow: Flow<EditChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val inlineQueryFlow: Flow<InlineQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val callbackQueryFlow: Flow<CallbackQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val shippingQueryFlow: Flow<ShippingQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val pollFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val pollAnswerFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
val unknownUpdateTypeFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
|
||||
}
|
@ -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<T> = suspend (T) -> Unit
|
||||
@ -29,7 +29,7 @@ data class SimpleUpdatesFilter(
|
||||
private val preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||
private val pollUpdateCallback: UpdateReceiver<PollUpdate>? = null,
|
||||
private val pollAnswerUpdateCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||
private val unknownUpdateTypeCallback: UpdateReceiver<UnknownUpdateType>? = null
|
||||
private val unknownUpdateTypeCallback: UpdateReceiver<UnknownUpdate>? = null
|
||||
) : UpdatesFilter {
|
||||
override val asUpdateReceiver: UpdateReceiver<Update> = 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<PreCheckoutQueryUpdate>? = null,
|
||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||
unknownCallback: UpdateReceiver<UnknownUpdateType>? = null
|
||||
unknownCallback: UpdateReceiver<UnknownUpdate>? = null
|
||||
): UpdatesFilter = SimpleUpdatesFilter(
|
||||
messageCallback = messageCallback,
|
||||
messageMediaGroupCallback = mediaGroupCallback,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user