1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

Merge pull request #422 from eboshare/0.35.1

Add Update#sourceUser method
This commit is contained in:
InsanusMokrassar 2021-06-30 10:39:00 +06:00 committed by GitHub
commit 9e82211473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 9 deletions

View File

@ -1,11 +1,11 @@
package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.types.CallbackQueryIdentifier
import dev.inmo.tgbotapi.types.User
sealed interface CallbackQuery {
sealed interface CallbackQuery : FromUser {
val id: CallbackQueryIdentifier
val user: User
val chatInstance: String
}

View File

@ -5,4 +5,4 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
data class LeftChatMember(
val user: User
): CommonEvent
) : CommonEvent

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types.payments
import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.payments.abstracts.*
import kotlinx.serialization.SerialName
@ -11,7 +12,7 @@ data class PreCheckoutQuery(
@SerialName(idField)
val id: PreCheckoutQueryId,
@SerialName(fromField)
val user: User,
override val user: User,
@SerialName(currencyField)
override val currency: Currency,
@SerialName(totalAmountField)
@ -22,4 +23,4 @@ data class PreCheckoutQuery(
val shippingOptionId: ShippingOptionIdentifier? = null,
@SerialName(orderInfoField)
val orderInfo: OrderInfo? = null
) : Currencied, Amounted
) : Currencied, Amounted, FromUser

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types.payments
import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -9,9 +10,9 @@ data class ShippingQuery(
@SerialName(idField)
val id: ShippingQueryIdentifier,
@SerialName(fromField)
val user: User,
override val user: User,
@SerialName(invoicePayloadField)
val invoicePayload: InvoicePayload,
@SerialName(shippingAddressField)
val shippingAddress: ShippingAddress
)
) : FromUser

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types.polls
import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -9,7 +10,7 @@ data class PollAnswer(
@SerialName(pollIdField)
val pollId: PollIdentifier,
@SerialName(userField)
val user: User,
override val user: User,
@SerialName(optionIdsField)
val chosen: List<Int>
)
) : FromUser

View File

@ -3,6 +3,7 @@
package dev.inmo.tgbotapi.extensions.utils
import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData
import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.requests.send.payments.SendInvoice
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.CallbackQuery.*
@ -3096,3 +3097,12 @@ inline fun CommonSendInvoiceData.asInputInvoiceMessageContent(): InputInvoiceMes
@PreviewFeature
inline fun CommonSendInvoiceData.requireInputInvoiceMessageContent(): InputInvoiceMessageContent =
this as InputInvoiceMessageContent
@PreviewFeature
inline fun <T> Any.whenFromUser(block: (FromUser) -> T) = asFromUser() ?.let(block)
@PreviewFeature
inline fun Any.asFromUser(): FromUser? = this as? FromUser
@PreviewFeature
inline fun Any.requireFromUser(): FromUser = this as FromUser

View File

@ -1,6 +1,10 @@
package dev.inmo.tgbotapi.extensions.utils.extensions
import dev.inmo.tgbotapi.extensions.utils.asFromUser
import dev.inmo.tgbotapi.extensions.utils.asFromUserMessage
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 +28,6 @@ fun Update.sourceChat(): Chat? = when (this) {
is ShippingQueryUpdate -> data.user
else -> null
}
@PreviewFeature
fun Update.sourceUser(): User? = data.asFromUser()?.user ?: sourceChat()?.asUser()