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