mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-03-03 17:32:23 +00:00
add support of getChatGifts and getUserGifts
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.gifts
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.gifts.GetChatGifts
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.OwnedGifts
|
||||
import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceived
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
public suspend fun TelegramBot.getChatGifts(
|
||||
chatId: ChatIdentifier,
|
||||
excludeUnsaved: Boolean = false,
|
||||
excludeSaved: Boolean = false,
|
||||
excludeUnlimited: Boolean = false,
|
||||
excludeLimitedUpgradable: Boolean = false,
|
||||
excludeLimitedNonUpgradable: Boolean = false,
|
||||
excludeFromBlockchain: Boolean = false,
|
||||
excludeUnique: Boolean = false,
|
||||
sortByPrice: Boolean = false,
|
||||
offset: String? = null,
|
||||
limit: Int? = null
|
||||
): OwnedGifts<GiftSentOrReceived> = execute(
|
||||
GetChatGifts(
|
||||
chatId,
|
||||
excludeUnsaved,
|
||||
excludeSaved,
|
||||
excludeUnlimited,
|
||||
excludeLimitedUpgradable,
|
||||
excludeLimitedNonUpgradable,
|
||||
excludeFromBlockchain,
|
||||
excludeUnique,
|
||||
sortByPrice,
|
||||
offset,
|
||||
limit
|
||||
)
|
||||
)
|
||||
|
||||
public fun TelegramBot.getChatGiftsFlow(
|
||||
chatId: ChatIdentifier,
|
||||
excludeUnsaved: Boolean = false,
|
||||
excludeSaved: Boolean = false,
|
||||
excludeUnlimited: Boolean = false,
|
||||
excludeLimitedUpgradable: Boolean = false,
|
||||
excludeLimitedNonUpgradable: Boolean = false,
|
||||
excludeFromBlockchain: Boolean = false,
|
||||
excludeUnique: Boolean = false,
|
||||
sortByPrice: Boolean = false,
|
||||
initialOffset: String? = null,
|
||||
limit: Int? = null,
|
||||
onErrorContinueChecker: suspend (Throwable?) -> Boolean = { false }
|
||||
): Flow<OwnedGifts<GiftSentOrReceived>> = flow {
|
||||
var currentOffset = initialOffset
|
||||
do {
|
||||
val response = runCatching {
|
||||
getChatGifts(
|
||||
chatId,
|
||||
excludeUnsaved,
|
||||
excludeSaved,
|
||||
excludeUnlimited,
|
||||
excludeLimitedUpgradable,
|
||||
excludeLimitedNonUpgradable,
|
||||
excludeFromBlockchain,
|
||||
excludeUnique,
|
||||
sortByPrice,
|
||||
currentOffset,
|
||||
limit
|
||||
)
|
||||
}
|
||||
if (response.isSuccess) {
|
||||
val result = response.getOrThrow()
|
||||
emit(result)
|
||||
currentOffset = result.nextOffset
|
||||
} else {
|
||||
if (onErrorContinueChecker(response.exceptionOrNull())) {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
} while (currentOffset != null)
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.gifts
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.gifts.GetUserGifts
|
||||
import dev.inmo.tgbotapi.types.OwnedGifts
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceived
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
public suspend fun TelegramBot.getUserGifts(
|
||||
userId: UserId,
|
||||
excludeUnlimited: Boolean = false,
|
||||
excludeLimitedUpgradable: Boolean = false,
|
||||
excludeLimitedNonUpgradable: Boolean = false,
|
||||
excludeFromBlockchain: Boolean = false,
|
||||
excludeUnique: Boolean = false,
|
||||
sortByPrice: Boolean = false,
|
||||
offset: String? = null,
|
||||
limit: Int? = null
|
||||
): OwnedGifts<GiftSentOrReceived> = execute(
|
||||
GetUserGifts(
|
||||
userId,
|
||||
excludeUnlimited,
|
||||
excludeLimitedUpgradable,
|
||||
excludeLimitedNonUpgradable,
|
||||
excludeFromBlockchain,
|
||||
excludeUnique,
|
||||
sortByPrice,
|
||||
offset,
|
||||
limit
|
||||
)
|
||||
)
|
||||
|
||||
public fun TelegramBot.getUserGiftsFlow(
|
||||
userId: UserId,
|
||||
excludeUnlimited: Boolean = false,
|
||||
excludeLimitedUpgradable: Boolean = false,
|
||||
excludeLimitedNonUpgradable: Boolean = false,
|
||||
excludeFromBlockchain: Boolean = false,
|
||||
excludeUnique: Boolean = false,
|
||||
sortByPrice: Boolean = false,
|
||||
initialOffset: String? = null,
|
||||
limit: Int? = null,
|
||||
onErrorContinueChecker: suspend (Throwable?) -> Boolean = { false }
|
||||
): Flow<OwnedGifts<GiftSentOrReceived>> = flow {
|
||||
var currentOffset = initialOffset
|
||||
do {
|
||||
val response = runCatching {
|
||||
getUserGifts(
|
||||
userId,
|
||||
excludeUnlimited,
|
||||
excludeLimitedUpgradable,
|
||||
excludeLimitedNonUpgradable,
|
||||
excludeFromBlockchain,
|
||||
excludeUnique,
|
||||
sortByPrice,
|
||||
currentOffset,
|
||||
limit
|
||||
)
|
||||
}
|
||||
if (response.isSuccess) {
|
||||
val result = response.getOrThrow()
|
||||
emit(result)
|
||||
currentOffset = result.nextOffset
|
||||
} else {
|
||||
if (onErrorContinueChecker(response.exceptionOrNull())) {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
} while (currentOffset != null)
|
||||
}
|
||||
Reference in New Issue
Block a user