mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
fix of #273
This commit is contained in:
parent
a35fb40a66
commit
450c7e6474
@ -4,6 +4,8 @@
|
||||
|
||||
* `Core`:
|
||||
* Fix of [#272](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/272)
|
||||
* `Utils`:
|
||||
* Fix of [#273](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/273)
|
||||
|
||||
## 0.32.0
|
||||
|
||||
|
@ -5,6 +5,17 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <reified T : MessageContent> CommonMessage<*>.withContent() = if (content is T) {
|
||||
this as CommonMessage<T>
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <reified T : MessageContent> CommonMessage<*>.requireWithContent() = this as CommonMessage<T>
|
||||
|
||||
/**
|
||||
* Simple factory to convert [ContentMessage] to a [CommonMessage]
|
||||
*/
|
||||
|
@ -9,6 +9,21 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <reified T : MessageContent> ContentMessage<*>.withContent() = if (content is T) {
|
||||
this as ContentMessage<T>
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <reified T : MessageContent> ContentMessage<*>.requireWithContent() = this as ContentMessage<T>
|
||||
|
||||
private inline fun <reified T : MessageContent> Flow<ContentMessage<*>>.withContentType() = mapNotNull {
|
||||
it.withContent<T>()
|
||||
}
|
||||
|
||||
@Deprecated("This method will be removed in next major update")
|
||||
fun <T : MessageContent> Flow<ContentMessage<*>>.withContentType(contentType: KClass<T>) = mapNotNull {
|
||||
if (contentType.isInstance(it.content)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@ -18,19 +33,19 @@ fun <T : MessageContent> Flow<ContentMessage<*>>.withContentType(contentType: KC
|
||||
}
|
||||
}
|
||||
|
||||
fun Flow<ContentMessage<*>>.onlyAnimationContentMessages() = withContentType(AnimationContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyAudioContentMessages() = withContentType(AudioContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyContactContentMessages() = withContentType(ContactContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyDiceContentMessages() = withContentType(DiceContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyDocumentContentMessages() = withContentType(DocumentContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyGameContentMessages() = withContentType(GameContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyInvoiceContentMessages() = withContentType(InvoiceContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyLocationContentMessages() = withContentType(LocationContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyPhotoContentMessages() = withContentType(PhotoContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyPollContentMessages() = withContentType(PollContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyStickerContentMessages() = withContentType(StickerContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyTextContentMessages() = withContentType(TextContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyVenueContentMessages() = withContentType(VenueContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyVideoContentMessages() = withContentType(VideoContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyVideoNoteContentMessages() = withContentType(VideoNoteContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyVoiceContentMessages() = withContentType(VoiceContent::class)
|
||||
fun Flow<ContentMessage<*>>.onlyAnimationContentMessages() = withContentType<AnimationContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyAudioContentMessages() = withContentType<AudioContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyContactContentMessages() = withContentType<ContactContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyDiceContentMessages() = withContentType<DiceContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyDocumentContentMessages() = withContentType<DocumentContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyGameContentMessages() = withContentType<GameContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyInvoiceContentMessages() = withContentType<InvoiceContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyLocationContentMessages() = withContentType<LocationContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyPhotoContentMessages() = withContentType<PhotoContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyPollContentMessages() = withContentType<PollContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyStickerContentMessages() = withContentType<StickerContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyTextContentMessages() = withContentType<TextContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyVenueContentMessages() = withContentType<VenueContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyVideoContentMessages() = withContentType<VideoContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyVideoNoteContentMessages() = withContentType<VideoNoteContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyVoiceContentMessages() = withContentType<VoiceContent>()
|
||||
|
Loading…
Reference in New Issue
Block a user