mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 09:07:12 +00:00
add Update#sourceUser method
This commit is contained in:
parent
0c1017901f
commit
919b1590e3
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user