1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

add Update#sourceUser method

This commit is contained in:
vasya 2021-06-28 20:30:12 +03:00
parent 0c1017901f
commit 919b1590e3

View File

@ -1,6 +1,8 @@
package dev.inmo.tgbotapi.extensions.utils.extensions
import dev.inmo.tgbotapi.extensions.utils.asUser
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.update.*
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
@ -24,3 +26,20 @@ fun Update.sourceChat(): Chat? = when (this) {
is ShippingQueryUpdate -> data.user
else -> null
}
@PreviewFeature
fun Update.sourceUser(): User? = when (this) {
is MediaGroupUpdate -> when (this) {
is SentMediaGroupUpdate -> data.chat?.asUser()
is EditMediaGroupUpdate -> data.chat.asUser()
else -> null
}
is BaseMessageUpdate -> data.chat.asUser()
is InlineQueryUpdate -> data.from
is ChosenInlineResultUpdate -> data.user
is CallbackQueryUpdate -> data.user
is PreCheckoutQueryUpdate -> data.user
is PollAnswerUpdate -> data.user
is ShippingQueryUpdate -> data.user
else -> null
}