mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
fixes in classcasts, withContentOrNull and withContentOrThrow
This commit is contained in:
parent
542079f4bf
commit
4b89563cff
@ -46,6 +46,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMember
|
|||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
||||||
|
@ -46,6 +46,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMember
|
|||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.AudioMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.DocumentMediaGroupContent
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
@file:Suppress("UNCHECKED_CAST")
|
||||||
|
|
||||||
|
package dev.inmo.tgbotapi.extensions.utils
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> ContentMessage<*>.withContentOrNull() = if (content is T) { this as ContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> ContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> CommonMessage<*>.withContentOrNull() = if (content is T) { this as CommonMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> CommonMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> PossiblySentViaBotCommonMessage<*>.withContentOrNull() = if (content is T) { this as PossiblySentViaBotCommonMessage<T>
|
||||||
|
} else { null }
|
||||||
|
inline fun <reified T : MessageContent> PossiblySentViaBotCommonMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> ChannelContentMessage<*>.withContentOrNull() = if (content is T) { this as ChannelContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> ChannelContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> PrivateContentMessage<*>.withContentOrNull() = if (content is T) { this as PrivateContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> PrivateContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> PublicContentMessage<*>.withContentOrNull() = if (content is T) { this as PublicContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> PublicContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> GroupContentMessage<*>.withContentOrNull() = if (content is T) { this as GroupContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> GroupContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> FromChannelGroupContentMessage<*>.withContentOrNull() = if (content is T) { this as FromChannelGroupContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> FromChannelGroupContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> AnonymousGroupContentMessage<*>.withContentOrNull() = if (content is T) { this as AnonymousGroupContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> AnonymousGroupContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.withContentOrNull() = if (content is T) { this as CommonGroupContentMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MessageContent> CommonGroupContentMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
||||||
|
|
||||||
|
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.withContentOrNull() = if (content is T) { this as MediaGroupMessage<T> } else { null }
|
||||||
|
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.withContentOrThrow() = withContentOrNull<T>()!!
|
Loading…
Reference in New Issue
Block a user