mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
refactor of contentConverter
This commit is contained in:
parent
2a33b22afb
commit
5a192b00d4
@ -7,7 +7,7 @@
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Serialization`: `1.2.2` -> `1.3.0`
|
||||
* `MicroUtils`: `0.5.28` -> `0.7.0`
|
||||
* `MicroUtils`: `0.5.28` -> `0.7.1`
|
||||
* `Klock`: `2.4.3` -> `2.4.5`
|
||||
* `Core`:
|
||||
* `PayInlineKeyboardButton#pay` now is deprecated
|
||||
|
@ -16,6 +16,7 @@ import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
||||
|
||||
@ -54,19 +55,17 @@ private suspend fun <O> BehaviourContext.waitCommonMessage(
|
||||
|
||||
internal inline fun <reified T : MessageContent> contentConverter(
|
||||
noinline mapper: CommonMessageToContentMapper<T>? = null
|
||||
): suspend CommonMessage<MessageContent>.() -> T? = {
|
||||
): suspend CommonMessage<MessageContent>.() -> T? = mapper ?.let {
|
||||
{
|
||||
if (content is T) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val message = (this as CommonMessage<T>)
|
||||
if (mapper == null) {
|
||||
message.content
|
||||
} else {
|
||||
safelyWithoutExceptions { mapper(message) }
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
} ?: { content as? T }
|
||||
|
||||
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitContent(
|
||||
count: Int = 1,
|
||||
|
Loading…
Reference in New Issue
Block a user