2021-01-25 04:43:51 +00:00
|
|
|
package dev.inmo.tgbotapi.extensions.api.passport
|
|
|
|
|
|
|
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
|
|
|
import dev.inmo.tgbotapi.requests.SetPassportDataErrors
|
2021-04-28 13:59:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.User
|
|
|
|
import dev.inmo.tgbotapi.types.UserId
|
2021-01-25 04:43:51 +00:00
|
|
|
import dev.inmo.tgbotapi.types.message.PassportMessage
|
|
|
|
import dev.inmo.tgbotapi.types.passport.PassportData
|
|
|
|
import dev.inmo.tgbotapi.types.passport.PassportElementError
|
2021-01-28 11:08:25 +00:00
|
|
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement
|
2021-01-25 04:43:51 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.passport.Decryptor
|
|
|
|
|
|
|
|
suspend fun TelegramBot.setPassportDataErrors(
|
|
|
|
userId: UserId,
|
|
|
|
errors: List<PassportElementError>
|
|
|
|
) = execute(SetPassportDataErrors(userId, errors))
|
|
|
|
suspend fun TelegramBot.setPassportDataErrors(
|
|
|
|
user: User,
|
|
|
|
errors: List<PassportElementError>
|
|
|
|
) = setPassportDataErrors(user.id, errors)
|
|
|
|
|
|
|
|
suspend fun TelegramBot.setPassportDataErrors(
|
|
|
|
userId: UserId,
|
|
|
|
passportData: PassportData,
|
|
|
|
decryptor: Decryptor,
|
|
|
|
mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError
|
|
|
|
): Boolean = setPassportDataErrors(
|
|
|
|
userId,
|
|
|
|
passportData.data.map { decryptor.mapper(it) }.also {
|
|
|
|
if (it.isEmpty()) {
|
|
|
|
return@setPassportDataErrors false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
suspend fun TelegramBot.setPassportDataErrors(
|
|
|
|
user: User,
|
|
|
|
passportData: PassportData,
|
|
|
|
decryptor: Decryptor,
|
|
|
|
mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError
|
|
|
|
) = setPassportDataErrors(user.id, passportData, decryptor, mapper)
|
|
|
|
|
|
|
|
suspend fun TelegramBot.setPassportDataErrors(
|
|
|
|
passportMessage: PassportMessage,
|
|
|
|
decryptor: Decryptor,
|
|
|
|
mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError
|
|
|
|
) = setPassportDataErrors(passportMessage.user, passportMessage.passportData, decryptor, mapper)
|