1
0
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:
2026-02-20 17:05:51 +06:00
parent 83b4d2155f
commit f10cfdbe1e
8 changed files with 258 additions and 650 deletions

View File

@@ -1197,6 +1197,20 @@ public final class dev/inmo/tgbotapi/extensions/api/gifts/GetAvailableGiftsKt {
public static final fun getAvailableGifts (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class dev/inmo/tgbotapi/extensions/api/gifts/GetChatGiftsKt {
public static final fun getChatGifts (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/ChatIdentifier;ZZZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun getChatGifts$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/ChatIdentifier;ZZZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun getChatGiftsFlow (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/ChatIdentifier;ZZZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
public static synthetic fun getChatGiftsFlow$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/ChatIdentifier;ZZZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow;
}
public final class dev/inmo/tgbotapi/extensions/api/gifts/GetUserGiftsKt {
public static final fun getUserGifts (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;ZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun getUserGifts$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;ZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun getUserGiftsFlow (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;ZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
public static synthetic fun getUserGiftsFlow$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;ZZZZZZLjava/lang/String;Ljava/lang/Integer;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow;
}
public final class dev/inmo/tgbotapi/extensions/api/gifts/GiftPremiumSubscriptionKt {
public static final fun giftPremiumSubscription (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;IILdev/inmo/tgbotapi/types/message/textsources/TextSource;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun giftPremiumSubscription (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/IdChatIdentifier;IILjava/lang/String;Ldev/inmo/tgbotapi/types/message/ParseMode;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;

View File

@@ -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)
}

View File

@@ -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)
}