mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-05 16:19:26 +00:00
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ out/
|
|||||||
local.properties
|
local.properties
|
||||||
kotlin-js-store/
|
kotlin-js-store/
|
||||||
secret.gradle
|
secret.gradle
|
||||||
|
.aider*
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
|
@@ -22,7 +22,7 @@ public suspend fun TelegramBot.sendGift(
|
|||||||
)
|
)
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
@GenerationVariant(
|
@GenerationVariant(
|
||||||
Gift::class,
|
Gift.Regular::class,
|
||||||
"id",
|
"id",
|
||||||
"gift"
|
"gift"
|
||||||
)
|
)
|
||||||
@@ -49,7 +49,7 @@ public suspend fun TelegramBot.sendGiftToChat(
|
|||||||
)
|
)
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
@GenerationVariant(
|
@GenerationVariant(
|
||||||
Gift::class,
|
Gift.Regular::class,
|
||||||
"id",
|
"id",
|
||||||
"gift"
|
"gift"
|
||||||
)
|
)
|
||||||
@@ -76,7 +76,7 @@ public suspend fun TelegramBot.sendGift(
|
|||||||
)
|
)
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
@GenerationVariant(
|
@GenerationVariant(
|
||||||
Gift::class,
|
Gift.Regular::class,
|
||||||
"id",
|
"id",
|
||||||
"gift"
|
"gift"
|
||||||
)
|
)
|
||||||
@@ -101,7 +101,7 @@ public suspend fun TelegramBot.sendGiftToChat(
|
|||||||
)
|
)
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
@GenerationVariant(
|
@GenerationVariant(
|
||||||
Gift::class,
|
Gift.Regular::class,
|
||||||
"id",
|
"id",
|
||||||
"gift"
|
"gift"
|
||||||
)
|
)
|
||||||
|
@@ -34,7 +34,7 @@ public suspend fun TelegramBot.sendGift(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGift(
|
public suspend fun TelegramBot.sendGift(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
): Boolean = sendGift(
|
): Boolean = sendGift(
|
||||||
@@ -43,7 +43,7 @@ public suspend fun TelegramBot.sendGift(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGift(
|
public suspend fun TelegramBot.sendGift(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
upgradableToUnique: Boolean,
|
upgradableToUnique: Boolean,
|
||||||
@@ -54,7 +54,7 @@ public suspend fun TelegramBot.sendGift(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGift(
|
public suspend fun TelegramBot.sendGift(
|
||||||
user: User,
|
user: User,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
): Boolean = sendGift(
|
): Boolean = sendGift(
|
||||||
@@ -63,7 +63,7 @@ public suspend fun TelegramBot.sendGift(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGift(
|
public suspend fun TelegramBot.sendGift(
|
||||||
user: User,
|
user: User,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
upgradableToUnique: Boolean,
|
upgradableToUnique: Boolean,
|
||||||
|
@@ -34,7 +34,7 @@ public suspend fun TelegramBot.sendGiftToChat(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGiftToChat(
|
public suspend fun TelegramBot.sendGiftToChat(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
): Boolean = sendGiftToChat(
|
): Boolean = sendGiftToChat(
|
||||||
@@ -43,7 +43,7 @@ public suspend fun TelegramBot.sendGiftToChat(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGiftToChat(
|
public suspend fun TelegramBot.sendGiftToChat(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
upgradableToUnique: Boolean,
|
upgradableToUnique: Boolean,
|
||||||
@@ -54,7 +54,7 @@ public suspend fun TelegramBot.sendGiftToChat(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGiftToChat(
|
public suspend fun TelegramBot.sendGiftToChat(
|
||||||
chat: PublicChat,
|
chat: PublicChat,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
): Boolean = sendGiftToChat(
|
): Boolean = sendGiftToChat(
|
||||||
@@ -63,7 +63,7 @@ public suspend fun TelegramBot.sendGiftToChat(
|
|||||||
|
|
||||||
public suspend fun TelegramBot.sendGiftToChat(
|
public suspend fun TelegramBot.sendGiftToChat(
|
||||||
chat: PublicChat,
|
chat: PublicChat,
|
||||||
gift: Gift,
|
gift: Gift.Regular,
|
||||||
text: String,
|
text: String,
|
||||||
parseMode: ParseMode?,
|
parseMode: ParseMode?,
|
||||||
upgradableToUnique: Boolean,
|
upgradableToUnique: Boolean,
|
||||||
|
@@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.utils.BuiltinMimeTypes
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlin.jvm.JvmInline
|
import kotlin.jvm.JvmInline
|
||||||
|
|
||||||
|
|
||||||
typealias ForwardSignature = String
|
typealias ForwardSignature = String
|
||||||
typealias ForwardSenderName = String
|
typealias ForwardSenderName = String
|
||||||
typealias AuthorSignature = ForwardSignature
|
typealias AuthorSignature = ForwardSignature
|
||||||
@@ -506,9 +507,19 @@ const val creatorField = "creator"
|
|||||||
const val subscriptionPeriodField = "subscription_period"
|
const val subscriptionPeriodField = "subscription_period"
|
||||||
const val subscriptionPriceField = "subscription_price"
|
const val subscriptionPriceField = "subscription_price"
|
||||||
const val copyTextField = "copy_text"
|
const val copyTextField = "copy_text"
|
||||||
|
|
||||||
const val isPublicField = "is_public"
|
const val isPublicField = "is_public"
|
||||||
|
|
||||||
const val giftField = "gift"
|
const val giftField = "gift"
|
||||||
const val giftsField = "gifts"
|
const val giftsField = "gifts"
|
||||||
|
const val rarityPerMilleField = "rarity_per_mille"
|
||||||
|
const val acceptedGiftTypesField = "accepted_gift_types"
|
||||||
|
const val ownedGiftIdField = "owned_gift_id"
|
||||||
|
const val convertStarCountField = "convert_star_count"
|
||||||
|
const val prepaidUpgradeStarCountField = "prepaid_upgrade_star_count"
|
||||||
|
const val canBeUpgradedField = "can_be_upgraded"
|
||||||
|
const val isPrivateField = "is_private"
|
||||||
|
const val transferStarCountField = "transfer_star_count"
|
||||||
|
|
||||||
const val pointField = "point"
|
const val pointField = "point"
|
||||||
const val xShiftField = "x_shift"
|
const val xShiftField = "x_shift"
|
||||||
@@ -684,6 +695,22 @@ const val upgradeStarCountField = "upgrade_star_count"
|
|||||||
const val payToUpgradeField = "pay_for_upgrade"
|
const val payToUpgradeField = "pay_for_upgrade"
|
||||||
const val paidMediaField = "paid_media"
|
const val paidMediaField = "paid_media"
|
||||||
|
|
||||||
|
const val centerColorField = "center_color"
|
||||||
|
const val edgeColorField = "edge_color"
|
||||||
|
const val symbolColorField = "symbol_color"
|
||||||
|
const val textColorField = "text_color"
|
||||||
|
|
||||||
|
const val baseNameField = "base_name"
|
||||||
|
const val numberField = "number"
|
||||||
|
const val modelField = "model"
|
||||||
|
const val symbolField = "symbol"
|
||||||
|
const val backdropField = "backdrop"
|
||||||
|
|
||||||
|
const val unlimitedGiftsField = "unlimited_gifts"
|
||||||
|
const val limitedGiftsField = "limited_gifts"
|
||||||
|
const val uniqueGiftsField = "unique_gifts"
|
||||||
|
const val premiumSubscriptionField = "premium_subscription"
|
||||||
|
|
||||||
const val businessConnectionIdField = "business_connection_id"
|
const val businessConnectionIdField = "business_connection_id"
|
||||||
const val businessIntroField = "business_intro"
|
const val businessIntroField = "business_intro"
|
||||||
const val businessLocationField = "business_location"
|
const val businessLocationField = "business_location"
|
||||||
|
@@ -5,11 +5,11 @@ import dev.inmo.tgbotapi.types.business_connection.BusinessIntro
|
|||||||
import dev.inmo.tgbotapi.types.business_connection.BusinessLocation
|
import dev.inmo.tgbotapi.types.business_connection.BusinessLocation
|
||||||
import dev.inmo.tgbotapi.types.business_connection.BusinessOpeningHours
|
import dev.inmo.tgbotapi.types.business_connection.BusinessOpeningHours
|
||||||
import dev.inmo.tgbotapi.types.colors.ColorId
|
import dev.inmo.tgbotapi.types.colors.ColorId
|
||||||
|
import dev.inmo.tgbotapi.types.gifts.AcceptedGiftTypes
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
||||||
import dev.inmo.tgbotapi.types.reactions.Reaction
|
import dev.inmo.tgbotapi.types.reactions.Reaction
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import korlibs.time.DateTime
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
@@ -21,6 +21,8 @@ data class ExtendedChannelChatImpl(
|
|||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
@SerialName(titleField)
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
|
@SerialName(acceptedGiftTypesField)
|
||||||
|
override val acceptedGiftTypes: AcceptedGiftTypes,
|
||||||
@SerialName(usernameField)
|
@SerialName(usernameField)
|
||||||
override val username: Username? = null,
|
override val username: Username? = null,
|
||||||
@SerialName(activeUsernamesField)
|
@SerialName(activeUsernamesField)
|
||||||
@@ -57,9 +59,7 @@ data class ExtendedChannelChatImpl(
|
|||||||
@SerialName(hasVisibleHistoryField)
|
@SerialName(hasVisibleHistoryField)
|
||||||
override val newMembersSeeHistory: Boolean = false,
|
override val newMembersSeeHistory: Boolean = false,
|
||||||
@SerialName(maxReactionCountField)
|
@SerialName(maxReactionCountField)
|
||||||
override val maxReactionsCount: Int = 3,
|
override val maxReactionsCount: Int = 3
|
||||||
@SerialName(canSendGiftsField)
|
|
||||||
override val canReceiveGifts: Boolean = false,
|
|
||||||
) : ExtendedChannelChat
|
) : ExtendedChannelChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -100,8 +100,8 @@ data class ExtendedGroupChatImpl(
|
|||||||
override val newMembersSeeHistory: Boolean = false,
|
override val newMembersSeeHistory: Boolean = false,
|
||||||
@SerialName(maxReactionCountField)
|
@SerialName(maxReactionCountField)
|
||||||
override val maxReactionsCount: Int = 3,
|
override val maxReactionsCount: Int = 3,
|
||||||
@SerialName(canSendGiftsField)
|
@SerialName(acceptedGiftTypesField)
|
||||||
override val canReceiveGifts: Boolean = false,
|
override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(),
|
||||||
) : ExtendedGroupChat
|
) : ExtendedGroupChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -150,8 +150,8 @@ data class ExtendedPrivateChatImpl(
|
|||||||
override val personalChat: PreviewChannelChat? = null,
|
override val personalChat: PreviewChannelChat? = null,
|
||||||
@SerialName(maxReactionCountField)
|
@SerialName(maxReactionCountField)
|
||||||
override val maxReactionsCount: Int = 3,
|
override val maxReactionsCount: Int = 3,
|
||||||
@SerialName(canSendGiftsField)
|
@SerialName(acceptedGiftTypesField)
|
||||||
override val canReceiveGifts: Boolean = false,
|
override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(),
|
||||||
) : ExtendedPrivateChat
|
) : ExtendedPrivateChat
|
||||||
|
|
||||||
typealias ExtendedUser = ExtendedPrivateChatImpl
|
typealias ExtendedUser = ExtendedPrivateChatImpl
|
||||||
@@ -218,8 +218,8 @@ data class ExtendedSupergroupChatImpl(
|
|||||||
override val customEmojiStickerSetName: StickerSetName? = null,
|
override val customEmojiStickerSetName: StickerSetName? = null,
|
||||||
@SerialName(maxReactionCountField)
|
@SerialName(maxReactionCountField)
|
||||||
override val maxReactionsCount: Int = 3,
|
override val maxReactionsCount: Int = 3,
|
||||||
@SerialName(canSendGiftsField)
|
@SerialName(acceptedGiftTypesField)
|
||||||
override val canReceiveGifts: Boolean = false,
|
override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(),
|
||||||
) : ExtendedSupergroupChat
|
) : ExtendedSupergroupChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -284,8 +284,8 @@ data class ExtendedForumChatImpl(
|
|||||||
override val customEmojiStickerSetName: StickerSetName? = null,
|
override val customEmojiStickerSetName: StickerSetName? = null,
|
||||||
@SerialName(maxReactionCountField)
|
@SerialName(maxReactionCountField)
|
||||||
override val maxReactionsCount: Int = 3,
|
override val maxReactionsCount: Int = 3,
|
||||||
@SerialName(canSendGiftsField)
|
@SerialName(acceptedGiftTypesField)
|
||||||
override val canReceiveGifts: Boolean = false,
|
override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(),
|
||||||
) : ExtendedForumChat
|
) : ExtendedForumChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -320,8 +320,8 @@ data class ExtendedBot(
|
|||||||
override val maxReactionsCount: Int = 3,
|
override val maxReactionsCount: Int = 3,
|
||||||
@SerialName(hasMainWebAppField)
|
@SerialName(hasMainWebAppField)
|
||||||
val hasMainWebApp: Boolean = false,
|
val hasMainWebApp: Boolean = false,
|
||||||
@SerialName(canSendGiftsField)
|
@SerialName(acceptedGiftTypesField)
|
||||||
override val canReceiveGifts: Boolean = false,
|
override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(),
|
||||||
) : Bot(), ExtendedChat {
|
) : Bot(), ExtendedChat {
|
||||||
@SerialName(isBotField)
|
@SerialName(isBotField)
|
||||||
private val isBot = true
|
private val isBot = true
|
||||||
@@ -351,6 +351,6 @@ data class UnknownExtendedChat(
|
|||||||
override val profileBackgroundCustomEmojiId: CustomEmojiId? = null
|
override val profileBackgroundCustomEmojiId: CustomEmojiId? = null
|
||||||
@SerialName(maxReactionCountField)
|
@SerialName(maxReactionCountField)
|
||||||
override val maxReactionsCount: Int = 3
|
override val maxReactionsCount: Int = 3
|
||||||
@SerialName(canSendGiftsField)
|
@SerialName(acceptedGiftTypesField)
|
||||||
override val canReceiveGifts: Boolean = false
|
override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes()
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.types.business_connection.BusinessIntro
|
|||||||
import dev.inmo.tgbotapi.types.business_connection.BusinessLocation
|
import dev.inmo.tgbotapi.types.business_connection.BusinessLocation
|
||||||
import dev.inmo.tgbotapi.types.business_connection.BusinessOpeningHours
|
import dev.inmo.tgbotapi.types.business_connection.BusinessOpeningHours
|
||||||
import dev.inmo.tgbotapi.types.colors.ColorId
|
import dev.inmo.tgbotapi.types.colors.ColorId
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
import dev.inmo.tgbotapi.types.gifts.AcceptedGiftTypes
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
||||||
import dev.inmo.tgbotapi.types.reactions.Reaction
|
import dev.inmo.tgbotapi.types.reactions.Reaction
|
||||||
@@ -20,10 +20,18 @@ sealed interface ExtendedChat : Chat {
|
|||||||
val profileBackgroundCustomEmojiId: CustomEmojiId?
|
val profileBackgroundCustomEmojiId: CustomEmojiId?
|
||||||
val maxReactionsCount: Int
|
val maxReactionsCount: Int
|
||||||
|
|
||||||
/**
|
val acceptedGiftTypes: AcceptedGiftTypes
|
||||||
* Represent `can_send_gifts` field
|
|
||||||
*/
|
@Deprecated(
|
||||||
|
message = "Telegram Bot API v9.0 introduced the new field, `acceptedGiftTypes`, to allow granular" +
|
||||||
|
" control over which types of gifts user, bot, or chat can accept.",
|
||||||
|
replaceWith = ReplaceWith("acceptedGiftTypes.uniqueGifts || acceptedGiftTypes.unlimitedGifts || acceptedGiftTypes.limitedGifts || acceptedGiftTypes.premiumSubscription")
|
||||||
|
)
|
||||||
val canReceiveGifts: Boolean
|
val canReceiveGifts: Boolean
|
||||||
|
get() = acceptedGiftTypes.uniqueGifts ||
|
||||||
|
acceptedGiftTypes.unlimitedGifts ||
|
||||||
|
acceptedGiftTypes.limitedGifts ||
|
||||||
|
acceptedGiftTypes.premiumSubscription
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable(ExtendedChatSerializer.Companion::class)
|
@Serializable(ExtendedChatSerializer.Companion::class)
|
||||||
@@ -63,6 +71,7 @@ sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername, Ex
|
|||||||
sealed interface ExtendedPublicChat : ExtendedChat, PublicChat, ExtendedNonBotChat {
|
sealed interface ExtendedPublicChat : ExtendedChat, PublicChat, ExtendedNonBotChat {
|
||||||
val description: String
|
val description: String
|
||||||
val inviteLink: String?
|
val inviteLink: String?
|
||||||
|
|
||||||
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
|
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
|
||||||
val pinnedMessage: Message?
|
val pinnedMessage: Message?
|
||||||
val membersHidden: Boolean
|
val membersHidden: Boolean
|
||||||
|
@@ -0,0 +1,21 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.gifts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.limitedGiftsField
|
||||||
|
import dev.inmo.tgbotapi.types.premiumSubscriptionField
|
||||||
|
import dev.inmo.tgbotapi.types.uniqueGiftsField
|
||||||
|
import dev.inmo.tgbotapi.types.unlimitedGiftsField
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class AcceptedGiftTypes(
|
||||||
|
@SerialName(unlimitedGiftsField)
|
||||||
|
val unlimitedGifts: Boolean = false,
|
||||||
|
@SerialName(limitedGiftsField)
|
||||||
|
val limitedGifts: Boolean = false,
|
||||||
|
@SerialName(uniqueGiftsField)
|
||||||
|
val uniqueGifts: Boolean = false,
|
||||||
|
@SerialName(premiumSubscriptionField)
|
||||||
|
val premiumSubscription: Boolean = false
|
||||||
|
)
|
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.gifts
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.files.Sticker
|
import dev.inmo.tgbotapi.types.files.Sticker
|
||||||
|
import dev.inmo.tgbotapi.types.gifts.unique.UniqueGiftBackdrop
|
||||||
|
import dev.inmo.tgbotapi.types.gifts.unique.UniqueGiftModel
|
||||||
|
import dev.inmo.tgbotapi.types.gifts.unique.UniqueGiftSymbol
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@@ -11,55 +14,133 @@ import kotlinx.serialization.encoding.Encoder
|
|||||||
|
|
||||||
@Serializable(Gift.Companion::class)
|
@Serializable(Gift.Companion::class)
|
||||||
sealed interface Gift {
|
sealed interface Gift {
|
||||||
val id: GiftId
|
@Serializable(Regular.Companion::class)
|
||||||
val sticker: Sticker
|
sealed interface Regular : Gift {
|
||||||
val starCount: Int
|
val id: GiftId
|
||||||
val totalCount: Int?
|
val sticker: Sticker
|
||||||
val upgradeStarCount: Int?
|
val starCount: Int
|
||||||
val remainingCount: Int?
|
val totalCount: Int?
|
||||||
|
val upgradeStarCount: Int?
|
||||||
|
val remainingCount: Int?
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Unlimited(
|
data class Unlimited(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: GiftId,
|
override val id: GiftId,
|
||||||
@SerialName(stickerField)
|
@SerialName(stickerField)
|
||||||
override val sticker: Sticker,
|
override val sticker: Sticker,
|
||||||
@SerialName(starCountField)
|
@SerialName(starCountField)
|
||||||
override val starCount: Int,
|
override val starCount: Int,
|
||||||
@SerialName(upgradeStarCountField)
|
@SerialName(upgradeStarCountField)
|
||||||
override val upgradeStarCount: Int? = null
|
override val upgradeStarCount: Int? = null
|
||||||
) : Gift {
|
) : Regular {
|
||||||
override val totalCount: Int?
|
override val totalCount: Int?
|
||||||
get() = null
|
get() = null
|
||||||
override val remainingCount: Int?
|
override val remainingCount: Int?
|
||||||
get() = null
|
get() = null
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Limited(
|
||||||
|
@SerialName(idField)
|
||||||
|
override val id: GiftId,
|
||||||
|
@SerialName(stickerField)
|
||||||
|
override val sticker: Sticker,
|
||||||
|
@SerialName(starCountField)
|
||||||
|
override val starCount: Int,
|
||||||
|
@SerialName(totalCountField)
|
||||||
|
override val totalCount: Int,
|
||||||
|
@SerialName(remainingCountField)
|
||||||
|
override val remainingCount: Int,
|
||||||
|
@SerialName(upgradeStarCountField)
|
||||||
|
override val upgradeStarCount: Int? = null,
|
||||||
|
) : Regular
|
||||||
|
|
||||||
|
companion object : KSerializer<Regular> {
|
||||||
|
@Serializable
|
||||||
|
@Suppress("propertyName")
|
||||||
|
private data class RegularGiftSurrogate(
|
||||||
|
val id: GiftId,
|
||||||
|
val sticker: Sticker,
|
||||||
|
val star_count: Int,
|
||||||
|
val total_count: Int? = null,
|
||||||
|
val remaining_count: Int? = null,
|
||||||
|
val upgrade_star_count: Int? = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
override val descriptor: SerialDescriptor
|
||||||
|
get() = RegularGiftSurrogate.serializer().descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): Regular {
|
||||||
|
val surrogate = RegularGiftSurrogate.serializer().deserialize(decoder)
|
||||||
|
|
||||||
|
return if (surrogate.total_count != null && surrogate.remaining_count != null) {
|
||||||
|
Limited(
|
||||||
|
id = surrogate.id,
|
||||||
|
sticker = surrogate.sticker,
|
||||||
|
starCount = surrogate.star_count,
|
||||||
|
totalCount = surrogate.total_count,
|
||||||
|
remainingCount = surrogate.remaining_count,
|
||||||
|
upgradeStarCount = surrogate.upgrade_star_count,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Unlimited(
|
||||||
|
id = surrogate.id,
|
||||||
|
sticker = surrogate.sticker,
|
||||||
|
starCount = surrogate.star_count,
|
||||||
|
upgradeStarCount = surrogate.upgrade_star_count,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: Regular) {
|
||||||
|
val surrogate = RegularGiftSurrogate(
|
||||||
|
id = value.id,
|
||||||
|
sticker = value.sticker,
|
||||||
|
star_count = value.starCount,
|
||||||
|
total_count = value.totalCount,
|
||||||
|
remaining_count = value.remainingCount,
|
||||||
|
upgrade_star_count = value.upgradeStarCount
|
||||||
|
)
|
||||||
|
RegularGiftSurrogate.serializer().serialize(encoder, surrogate)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Limited(
|
data class Unique(
|
||||||
@SerialName(idField)
|
@SerialName(baseNameField)
|
||||||
override val id: GiftId,
|
val baseName: String,
|
||||||
@SerialName(stickerField)
|
@SerialName(nameField)
|
||||||
override val sticker: Sticker,
|
val name: String,
|
||||||
@SerialName(starCountField)
|
@SerialName(numberField)
|
||||||
override val starCount: Int,
|
val number: Int,
|
||||||
@SerialName(totalCountField)
|
@SerialName(modelField)
|
||||||
override val totalCount: Int,
|
val model: UniqueGiftModel,
|
||||||
@SerialName(remainingCountField)
|
@SerialName(symbolField)
|
||||||
override val remainingCount: Int,
|
val symbol: UniqueGiftSymbol,
|
||||||
@SerialName(upgradeStarCountField)
|
@SerialName(backdropField)
|
||||||
override val upgradeStarCount: Int? = null,
|
val backdrop: UniqueGiftBackdrop
|
||||||
) : Gift
|
) : Gift
|
||||||
|
|
||||||
companion object : KSerializer<Gift> {
|
companion object : KSerializer<Gift> {
|
||||||
@Serializable
|
@Serializable
|
||||||
private data class GiftSurrogate(
|
@Suppress("unused", "propertyName")
|
||||||
val id: GiftId,
|
private class GiftSurrogate(
|
||||||
val sticker: Sticker,
|
// regular gift fields
|
||||||
val star_count: Int,
|
val id: GiftId?,
|
||||||
|
val sticker: Sticker?,
|
||||||
|
val star_count: Int?,
|
||||||
val total_count: Int? = null,
|
val total_count: Int? = null,
|
||||||
val remaining_count: Int? = null,
|
val remaining_count: Int? = null,
|
||||||
val upgrade_star_count: Int? = null,
|
val upgrade_star_count: Int? = null,
|
||||||
|
// unique gift fields
|
||||||
|
val base_name: String? = null,
|
||||||
|
val name: String? = null,
|
||||||
|
val number: Int? = null,
|
||||||
|
val model: UniqueGiftModel? = null,
|
||||||
|
val symbol: UniqueGiftSymbol? = null,
|
||||||
|
val backdrop: UniqueGiftBackdrop? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
override val descriptor: SerialDescriptor
|
override val descriptor: SerialDescriptor
|
||||||
@@ -68,33 +149,37 @@ sealed interface Gift {
|
|||||||
override fun deserialize(decoder: Decoder): Gift {
|
override fun deserialize(decoder: Decoder): Gift {
|
||||||
val surrogate = GiftSurrogate.serializer().deserialize(decoder)
|
val surrogate = GiftSurrogate.serializer().deserialize(decoder)
|
||||||
|
|
||||||
return if (surrogate.total_count != null && surrogate.remaining_count != null) {
|
return if (surrogate.base_name != null && surrogate.name != null && surrogate.number != null && surrogate.model != null && surrogate.symbol != null && surrogate.backdrop != null) {
|
||||||
Limited(
|
Unique(
|
||||||
id = surrogate.id,
|
baseName = surrogate.base_name,
|
||||||
sticker = surrogate.sticker,
|
name = surrogate.name,
|
||||||
starCount = surrogate.star_count,
|
number = surrogate.number,
|
||||||
totalCount = surrogate.total_count,
|
model = surrogate.model,
|
||||||
remainingCount = surrogate.remaining_count,
|
symbol = surrogate.symbol,
|
||||||
upgradeStarCount = surrogate.upgrade_star_count,
|
backdrop = surrogate.backdrop,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Unlimited(
|
decoder.decodeSerializableValue(Regular.serializer())
|
||||||
id = surrogate.id,
|
|
||||||
sticker = surrogate.sticker,
|
|
||||||
starCount = surrogate.star_count,
|
|
||||||
upgradeStarCount = surrogate.upgrade_star_count,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serialize(encoder: Encoder, value: Gift) {
|
override fun serialize(
|
||||||
|
encoder: Encoder,
|
||||||
|
value: Gift
|
||||||
|
) {
|
||||||
val surrogate = GiftSurrogate(
|
val surrogate = GiftSurrogate(
|
||||||
id = value.id,
|
id = (value as? Regular)?.id,
|
||||||
sticker = value.sticker,
|
sticker = (value as? Regular)?.sticker,
|
||||||
star_count = value.starCount,
|
star_count = (value as? Regular)?.starCount,
|
||||||
total_count = value.totalCount,
|
total_count = (value as? Regular.Limited)?.totalCount,
|
||||||
remaining_count = value.remainingCount,
|
remaining_count = (value as? Regular.Limited)?.remainingCount,
|
||||||
upgrade_star_count = value.upgradeStarCount
|
upgrade_star_count = (value as? Regular)?.upgradeStarCount,
|
||||||
|
base_name = (value as? Unique)?.baseName,
|
||||||
|
name = (value as? Unique)?.name,
|
||||||
|
number = (value as? Unique)?.number,
|
||||||
|
model = (value as? Unique)?.model,
|
||||||
|
symbol = (value as? Unique)?.symbol,
|
||||||
|
backdrop = (value as? Unique)?.backdrop,
|
||||||
)
|
)
|
||||||
GiftSurrogate.serializer().serialize(encoder, surrogate)
|
GiftSurrogate.serializer().serialize(encoder, surrogate)
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,72 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.gifts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.RawMessageEntities
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
|
||||||
|
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
sealed interface GiftInfo {
|
||||||
|
val ownedGiftId: GiftId?
|
||||||
|
val gift: Gift
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Regular(
|
||||||
|
@SerialName(giftField)
|
||||||
|
override val gift: Gift.Regular,
|
||||||
|
@SerialName(ownedGiftIdField)
|
||||||
|
override val ownedGiftId: GiftId? = null,
|
||||||
|
@SerialName(convertStarCountField)
|
||||||
|
val convertStarCount: Int? = null,
|
||||||
|
@SerialName(prepaidUpgradeStarCountField)
|
||||||
|
val prepaidUpgradeStarCount: Int? = null,
|
||||||
|
@SerialName(canBeUpgradedField)
|
||||||
|
val canBeUpgraded: Boolean = false,
|
||||||
|
@SerialName(textField)
|
||||||
|
val text: String? = null,
|
||||||
|
@SerialName(entitiesField)
|
||||||
|
val entities: RawMessageEntities = emptyList(),
|
||||||
|
@SerialName(isPrivateField)
|
||||||
|
val isPrivate: Boolean = false
|
||||||
|
) : GiftInfo {
|
||||||
|
companion object {
|
||||||
|
@JvmName("PublicConstructor")
|
||||||
|
operator fun invoke(
|
||||||
|
gift: Gift.Regular,
|
||||||
|
ownedGiftId: GiftId? = null,
|
||||||
|
convertStarCount: Int? = null,
|
||||||
|
prepaidUpgradeStarCount: Int? = null,
|
||||||
|
canBeUpgraded: Boolean = false,
|
||||||
|
text: String? = null,
|
||||||
|
textSources: TextSourcesList = emptyList(),
|
||||||
|
position: Int,
|
||||||
|
isPrivate: Boolean = false
|
||||||
|
) = Regular(
|
||||||
|
gift,
|
||||||
|
ownedGiftId,
|
||||||
|
convertStarCount,
|
||||||
|
prepaidUpgradeStarCount,
|
||||||
|
canBeUpgraded,
|
||||||
|
text,
|
||||||
|
textSources.toRawMessageEntities(position),
|
||||||
|
isPrivate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Unique(
|
||||||
|
@SerialName(giftField)
|
||||||
|
override val gift: Gift.Unique,
|
||||||
|
@SerialName(originField)
|
||||||
|
val origin: String? = null,
|
||||||
|
@SerialName(ownedGiftIdField)
|
||||||
|
override val ownedGiftId: GiftId? = null,
|
||||||
|
@SerialName(transferStarCountField)
|
||||||
|
val transferStarCount: Int? = null
|
||||||
|
): GiftInfo
|
||||||
|
}
|
@@ -7,5 +7,5 @@ import kotlinx.serialization.Serializable
|
|||||||
@Serializable
|
@Serializable
|
||||||
data class Gifts(
|
data class Gifts(
|
||||||
@SerialName(giftsField)
|
@SerialName(giftsField)
|
||||||
val gifts: List<Gift>
|
val gifts: List<Gift.Regular>
|
||||||
)
|
)
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.gifts.unique
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.colorsField
|
||||||
|
import dev.inmo.tgbotapi.types.nameField
|
||||||
|
import dev.inmo.tgbotapi.types.rarityPerMilleField
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UniqueGiftBackdrop(
|
||||||
|
@SerialName(nameField)
|
||||||
|
val name: String,
|
||||||
|
@SerialName(colorsField)
|
||||||
|
val colors: UniqueGiftBackdropColors,
|
||||||
|
@SerialName(rarityPerMilleField)
|
||||||
|
val rarityPerMille: Int
|
||||||
|
)
|
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.gifts.unique
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.centerColorField
|
||||||
|
import dev.inmo.tgbotapi.types.edgeColorField
|
||||||
|
import dev.inmo.tgbotapi.types.symbolColorField
|
||||||
|
import dev.inmo.tgbotapi.types.textColorField
|
||||||
|
import dev.inmo.tgbotapi.utils.RGBColor
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UniqueGiftBackdropColors(
|
||||||
|
@SerialName(centerColorField)
|
||||||
|
val centerColor: RGBColor,
|
||||||
|
@SerialName(edgeColorField)
|
||||||
|
val edgeColor: RGBColor,
|
||||||
|
@SerialName(symbolColorField)
|
||||||
|
val symbolColor: RGBColor,
|
||||||
|
@SerialName(textColorField)
|
||||||
|
val textColor: RGBColor
|
||||||
|
)
|
@@ -0,0 +1,19 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.gifts.unique
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.files.Sticker
|
||||||
|
import dev.inmo.tgbotapi.types.nameField
|
||||||
|
import dev.inmo.tgbotapi.types.rarityPerMilleField
|
||||||
|
import dev.inmo.tgbotapi.types.stickerField
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UniqueGiftModel(
|
||||||
|
@SerialName(nameField)
|
||||||
|
val name: String,
|
||||||
|
@SerialName(stickerField)
|
||||||
|
val sticker: Sticker,
|
||||||
|
@SerialName(rarityPerMilleField)
|
||||||
|
val rarityPerMille: Int
|
||||||
|
)
|
@@ -0,0 +1,19 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.gifts.unique
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.files.Sticker
|
||||||
|
import dev.inmo.tgbotapi.types.nameField
|
||||||
|
import dev.inmo.tgbotapi.types.rarityPerMilleField
|
||||||
|
import dev.inmo.tgbotapi.types.stickerField
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UniqueGiftSymbol(
|
||||||
|
@SerialName(nameField)
|
||||||
|
val name: String,
|
||||||
|
@SerialName(stickerField)
|
||||||
|
val sticker: Sticker,
|
||||||
|
@SerialName(rarityPerMilleField)
|
||||||
|
val rarityPerMille: Int
|
||||||
|
)
|
@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.dice.Dice
|
|||||||
import dev.inmo.tgbotapi.types.files.*
|
import dev.inmo.tgbotapi.types.files.*
|
||||||
import dev.inmo.tgbotapi.types.files.Sticker
|
import dev.inmo.tgbotapi.types.files.Sticker
|
||||||
import dev.inmo.tgbotapi.types.games.RawGame
|
import dev.inmo.tgbotapi.types.games.RawGame
|
||||||
|
import dev.inmo.tgbotapi.types.gifts.GiftInfo
|
||||||
import dev.inmo.tgbotapi.types.giveaway.*
|
import dev.inmo.tgbotapi.types.giveaway.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.GiveawayContent
|
import dev.inmo.tgbotapi.types.message.content.GiveawayContent
|
||||||
import dev.inmo.tgbotapi.types.location.Location
|
import dev.inmo.tgbotapi.types.location.Location
|
||||||
@@ -110,6 +111,7 @@ internal data class RawMessage(
|
|||||||
private val is_from_offline: Boolean = false,
|
private val is_from_offline: Boolean = false,
|
||||||
|
|
||||||
private val paid_star_count: Int? = null,
|
private val paid_star_count: Int? = null,
|
||||||
|
private val paid_message_price_changed: PaidMessagePriceChanged? = null,
|
||||||
|
|
||||||
// Voice Chat Service Messages
|
// Voice Chat Service Messages
|
||||||
private val video_chat_scheduled: VideoChatScheduled? = null,
|
private val video_chat_scheduled: VideoChatScheduled? = null,
|
||||||
@@ -163,7 +165,8 @@ internal data class RawMessage(
|
|||||||
private val giveaway_winners: GiveawayPublicResults? = null,
|
private val giveaway_winners: GiveawayPublicResults? = null,
|
||||||
private val giveaway_completed: GiveawayPrivateResults? = null,
|
private val giveaway_completed: GiveawayPrivateResults? = null,
|
||||||
|
|
||||||
private val paid_message_price_changed: PaidMessagePriceChanged? = null
|
// Gifts
|
||||||
|
private val gift: GiftInfo? = null,
|
||||||
) {
|
) {
|
||||||
private val checkedFrom = from ?.takeIf { !it.isFakeTelegramUser() }
|
private val checkedFrom = from ?.takeIf { !it.isFakeTelegramUser() }
|
||||||
private val content: MessageContent? by lazy {
|
private val content: MessageContent? by lazy {
|
||||||
|
@@ -60,7 +60,7 @@ sealed interface TransactionPartner {
|
|||||||
@SerialName(paidMediaPayloadField)
|
@SerialName(paidMediaPayloadField)
|
||||||
val paidMediaPayload: PaidMediaPayload? = null,
|
val paidMediaPayload: PaidMediaPayload? = null,
|
||||||
@SerialName(giftField)
|
@SerialName(giftField)
|
||||||
val gift: Gift? = null
|
val gift: Gift.Regular? = null
|
||||||
) : TransactionPartner, SubscriptionPeriodInfo {
|
) : TransactionPartner, SubscriptionPeriodInfo {
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
override val type: String = Companion.type
|
override val type: String = Companion.type
|
||||||
@@ -75,7 +75,7 @@ sealed interface TransactionPartner {
|
|||||||
@SerialName(chatField)
|
@SerialName(chatField)
|
||||||
val chat: PreviewChat,
|
val chat: PreviewChat,
|
||||||
@SerialName(giftField)
|
@SerialName(giftField)
|
||||||
val gift: Gift? = null
|
val gift: Gift.Regular? = null
|
||||||
) : TransactionPartner {
|
) : TransactionPartner {
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
override val type: String = Companion.type
|
override val type: String = Companion.type
|
||||||
@@ -150,7 +150,7 @@ sealed interface TransactionPartner {
|
|||||||
val subscription_period: TimeSpan? = null,
|
val subscription_period: TimeSpan? = null,
|
||||||
val paid_media: List<PaidMedia>? = null,
|
val paid_media: List<PaidMedia>? = null,
|
||||||
val paid_media_payload: PaidMediaPayload? = null,
|
val paid_media_payload: PaidMediaPayload? = null,
|
||||||
val gift: Gift? = null,
|
val gift: Gift.Regular? = null,
|
||||||
val request_count: Int? = null,
|
val request_count: Int? = null,
|
||||||
val sponsor_user: PreviewBot? = null,
|
val sponsor_user: PreviewBot? = null,
|
||||||
val commission_per_mille: Int? = null,
|
val commission_per_mille: Int? = null,
|
||||||
|
Reference in New Issue
Block a user