diff --git a/.gitignore b/.gitignore index d344e95940..72f7a6bb59 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ out/ local.properties kotlin-js-store/ secret.gradle +.aider* diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 32949f9ccb..e6045a9835 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME 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 diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGift.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGift.kt index bdce832604..74670ce2bc 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGift.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGift.kt @@ -22,7 +22,7 @@ public suspend fun TelegramBot.sendGift( ) userId: UserId, @GenerationVariant( - Gift::class, + Gift.Regular::class, "id", "gift" ) @@ -49,7 +49,7 @@ public suspend fun TelegramBot.sendGiftToChat( ) chatId: ChatIdentifier, @GenerationVariant( - Gift::class, + Gift.Regular::class, "id", "gift" ) @@ -76,7 +76,7 @@ public suspend fun TelegramBot.sendGift( ) userId: UserId, @GenerationVariant( - Gift::class, + Gift.Regular::class, "id", "gift" ) @@ -101,7 +101,7 @@ public suspend fun TelegramBot.sendGiftToChat( ) chatId: ChatIdentifier, @GenerationVariant( - Gift::class, + Gift.Regular::class, "id", "gift" ) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftGeneratedVariation.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftGeneratedVariation.kt index 9340e8ef2d..c9aedeaa49 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftGeneratedVariation.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftGeneratedVariation.kt @@ -34,7 +34,7 @@ public suspend fun TelegramBot.sendGift( public suspend fun TelegramBot.sendGift( userId: UserId, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, ): Boolean = sendGift( @@ -43,7 +43,7 @@ public suspend fun TelegramBot.sendGift( public suspend fun TelegramBot.sendGift( userId: UserId, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, upgradableToUnique: Boolean, @@ -54,7 +54,7 @@ public suspend fun TelegramBot.sendGift( public suspend fun TelegramBot.sendGift( user: User, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, ): Boolean = sendGift( @@ -63,7 +63,7 @@ public suspend fun TelegramBot.sendGift( public suspend fun TelegramBot.sendGift( user: User, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, upgradableToUnique: Boolean, diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftToChatGeneratedVariation.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftToChatGeneratedVariation.kt index 9761fdd0fd..17028861d1 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftToChatGeneratedVariation.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/SendGiftToChatGeneratedVariation.kt @@ -34,7 +34,7 @@ public suspend fun TelegramBot.sendGiftToChat( public suspend fun TelegramBot.sendGiftToChat( chatId: ChatIdentifier, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, ): Boolean = sendGiftToChat( @@ -43,7 +43,7 @@ public suspend fun TelegramBot.sendGiftToChat( public suspend fun TelegramBot.sendGiftToChat( chatId: ChatIdentifier, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, upgradableToUnique: Boolean, @@ -54,7 +54,7 @@ public suspend fun TelegramBot.sendGiftToChat( public suspend fun TelegramBot.sendGiftToChat( chat: PublicChat, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, ): Boolean = sendGiftToChat( @@ -63,7 +63,7 @@ public suspend fun TelegramBot.sendGiftToChat( public suspend fun TelegramBot.sendGiftToChat( chat: PublicChat, - gift: Gift, + gift: Gift.Regular, text: String, parseMode: ParseMode?, upgradableToUnique: Boolean, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index bd92cfd9fb..bfb847d309 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.utils.BuiltinMimeTypes import kotlinx.serialization.Serializable import kotlin.jvm.JvmInline + typealias ForwardSignature = String typealias ForwardSenderName = String typealias AuthorSignature = ForwardSignature @@ -506,9 +507,19 @@ const val creatorField = "creator" const val subscriptionPeriodField = "subscription_period" const val subscriptionPriceField = "subscription_price" const val copyTextField = "copy_text" + const val isPublicField = "is_public" + const val giftField = "gift" 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 xShiftField = "x_shift" @@ -684,6 +695,22 @@ const val upgradeStarCountField = "upgrade_star_count" const val payToUpgradeField = "pay_for_upgrade" 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 businessIntroField = "business_intro" const val businessLocationField = "business_location" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index fe3e1e760e..a2b0dd6cda 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -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.BusinessOpeningHours 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.TelegramBotAPIMessageDeserializeOnlySerializer import dev.inmo.tgbotapi.types.reactions.Reaction import dev.inmo.tgbotapi.utils.RiskFeature -import korlibs.time.DateTime import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject @@ -21,6 +21,8 @@ data class ExtendedChannelChatImpl( override val id: ChatId, @SerialName(titleField) override val title: String, + @SerialName(acceptedGiftTypesField) + override val acceptedGiftTypes: AcceptedGiftTypes, @SerialName(usernameField) override val username: Username? = null, @SerialName(activeUsernamesField) @@ -57,9 +59,7 @@ data class ExtendedChannelChatImpl( @SerialName(hasVisibleHistoryField) override val newMembersSeeHistory: Boolean = false, @SerialName(maxReactionCountField) - override val maxReactionsCount: Int = 3, - @SerialName(canSendGiftsField) - override val canReceiveGifts: Boolean = false, + override val maxReactionsCount: Int = 3 ) : ExtendedChannelChat @Serializable @@ -100,8 +100,8 @@ data class ExtendedGroupChatImpl( override val newMembersSeeHistory: Boolean = false, @SerialName(maxReactionCountField) override val maxReactionsCount: Int = 3, - @SerialName(canSendGiftsField) - override val canReceiveGifts: Boolean = false, + @SerialName(acceptedGiftTypesField) + override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(), ) : ExtendedGroupChat @Serializable @@ -150,8 +150,8 @@ data class ExtendedPrivateChatImpl( override val personalChat: PreviewChannelChat? = null, @SerialName(maxReactionCountField) override val maxReactionsCount: Int = 3, - @SerialName(canSendGiftsField) - override val canReceiveGifts: Boolean = false, + @SerialName(acceptedGiftTypesField) + override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(), ) : ExtendedPrivateChat typealias ExtendedUser = ExtendedPrivateChatImpl @@ -218,8 +218,8 @@ data class ExtendedSupergroupChatImpl( override val customEmojiStickerSetName: StickerSetName? = null, @SerialName(maxReactionCountField) override val maxReactionsCount: Int = 3, - @SerialName(canSendGiftsField) - override val canReceiveGifts: Boolean = false, + @SerialName(acceptedGiftTypesField) + override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(), ) : ExtendedSupergroupChat @Serializable @@ -284,8 +284,8 @@ data class ExtendedForumChatImpl( override val customEmojiStickerSetName: StickerSetName? = null, @SerialName(maxReactionCountField) override val maxReactionsCount: Int = 3, - @SerialName(canSendGiftsField) - override val canReceiveGifts: Boolean = false, + @SerialName(acceptedGiftTypesField) + override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(), ) : ExtendedForumChat @Serializable @@ -320,8 +320,8 @@ data class ExtendedBot( override val maxReactionsCount: Int = 3, @SerialName(hasMainWebAppField) val hasMainWebApp: Boolean = false, - @SerialName(canSendGiftsField) - override val canReceiveGifts: Boolean = false, + @SerialName(acceptedGiftTypesField) + override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes(), ) : Bot(), ExtendedChat { @SerialName(isBotField) private val isBot = true @@ -351,6 +351,6 @@ data class UnknownExtendedChat( override val profileBackgroundCustomEmojiId: CustomEmojiId? = null @SerialName(maxReactionCountField) override val maxReactionsCount: Int = 3 - @SerialName(canSendGiftsField) - override val canReceiveGifts: Boolean = false + @SerialName(acceptedGiftTypesField) + override val acceptedGiftTypes: AcceptedGiftTypes = AcceptedGiftTypes() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt index a66675f745..fc6bd47080 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt @@ -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.BusinessOpeningHours 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.TelegramBotAPIMessageDeserializeOnlySerializer import dev.inmo.tgbotapi.types.reactions.Reaction @@ -20,10 +20,18 @@ sealed interface ExtendedChat : Chat { val profileBackgroundCustomEmojiId: CustomEmojiId? val maxReactionsCount: Int - /** - * Represent `can_send_gifts` field - */ + val acceptedGiftTypes: AcceptedGiftTypes + + @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 + get() = acceptedGiftTypes.uniqueGifts || + acceptedGiftTypes.unlimitedGifts || + acceptedGiftTypes.limitedGifts || + acceptedGiftTypes.premiumSubscription } @Serializable(ExtendedChatSerializer.Companion::class) @@ -63,6 +71,7 @@ sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername, Ex sealed interface ExtendedPublicChat : ExtendedChat, PublicChat, ExtendedNonBotChat { val description: String val inviteLink: String? + @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) val pinnedMessage: Message? val membersHidden: Boolean diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/AcceptedGiftTypes.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/AcceptedGiftTypes.kt new file mode 100644 index 0000000000..8d0b4cb92c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/AcceptedGiftTypes.kt @@ -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 +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gift.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gift.kt index cdf71fd8e5..3ff24910ed 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gift.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gift.kt @@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.gifts import dev.inmo.tgbotapi.types.* 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.SerialName import kotlinx.serialization.Serializable @@ -11,55 +14,133 @@ import kotlinx.serialization.encoding.Encoder @Serializable(Gift.Companion::class) sealed interface Gift { - val id: GiftId - val sticker: Sticker - val starCount: Int - val totalCount: Int? - val upgradeStarCount: Int? - val remainingCount: Int? + @Serializable(Regular.Companion::class) + sealed interface Regular : Gift { + val id: GiftId + val sticker: Sticker + val starCount: Int + val totalCount: Int? + val upgradeStarCount: Int? + val remainingCount: Int? - @Serializable - data class Unlimited( - @SerialName(idField) - override val id: GiftId, - @SerialName(stickerField) - override val sticker: Sticker, - @SerialName(starCountField) - override val starCount: Int, - @SerialName(upgradeStarCountField) - override val upgradeStarCount: Int? = null - ) : Gift { - override val totalCount: Int? - get() = null - override val remainingCount: Int? - get() = null + @Serializable + data class Unlimited( + @SerialName(idField) + override val id: GiftId, + @SerialName(stickerField) + override val sticker: Sticker, + @SerialName(starCountField) + override val starCount: Int, + @SerialName(upgradeStarCountField) + override val upgradeStarCount: Int? = null + ) : Regular { + override val totalCount: Int? + get() = null + override val remainingCount: Int? + 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 { + @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 - 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, + data class Unique( + @SerialName(baseNameField) + val baseName: String, + @SerialName(nameField) + val name: String, + @SerialName(numberField) + val number: Int, + @SerialName(modelField) + val model: UniqueGiftModel, + @SerialName(symbolField) + val symbol: UniqueGiftSymbol, + @SerialName(backdropField) + val backdrop: UniqueGiftBackdrop ) : Gift companion object : KSerializer { @Serializable - private data class GiftSurrogate( - val id: GiftId, - val sticker: Sticker, - val star_count: Int, + @Suppress("unused", "propertyName") + private class GiftSurrogate( + // regular gift fields + 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, + // 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 @@ -68,33 +149,37 @@ sealed interface Gift { override fun deserialize(decoder: Decoder): Gift { val surrogate = GiftSurrogate.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, + return if (surrogate.base_name != null && surrogate.name != null && surrogate.number != null && surrogate.model != null && surrogate.symbol != null && surrogate.backdrop != null) { + Unique( + baseName = surrogate.base_name, + name = surrogate.name, + number = surrogate.number, + model = surrogate.model, + symbol = surrogate.symbol, + backdrop = surrogate.backdrop, ) } else { - Unlimited( - id = surrogate.id, - sticker = surrogate.sticker, - starCount = surrogate.star_count, - upgradeStarCount = surrogate.upgrade_star_count, - ) + decoder.decodeSerializableValue(Regular.serializer()) } } - override fun serialize(encoder: Encoder, value: Gift) { + override fun serialize( + encoder: Encoder, + value: Gift + ) { val surrogate = GiftSurrogate( - id = value.id, - sticker = value.sticker, - star_count = value.starCount, - total_count = value.totalCount, - remaining_count = value.remainingCount, - upgrade_star_count = value.upgradeStarCount + id = (value as? Regular)?.id, + sticker = (value as? Regular)?.sticker, + star_count = (value as? Regular)?.starCount, + total_count = (value as? Regular.Limited)?.totalCount, + remaining_count = (value as? Regular.Limited)?.remainingCount, + 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) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/GiftInfo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/GiftInfo.kt new file mode 100644 index 0000000000..676a179281 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/GiftInfo.kt @@ -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 +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gifts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gifts.kt index 07ae5c6fd1..e403a48d25 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gifts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/Gifts.kt @@ -7,5 +7,5 @@ import kotlinx.serialization.Serializable @Serializable data class Gifts( @SerialName(giftsField) - val gifts: List + val gifts: List ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftBackdrop.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftBackdrop.kt new file mode 100644 index 0000000000..2cf5b14930 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftBackdrop.kt @@ -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 +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftBackdropColors.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftBackdropColors.kt new file mode 100644 index 0000000000..d2acfdb353 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftBackdropColors.kt @@ -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 +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftModel.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftModel.kt new file mode 100644 index 0000000000..28e3820c57 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftModel.kt @@ -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 +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftSymbol.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftSymbol.kt new file mode 100644 index 0000000000..0c322ee19b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/unique/UniqueGiftSymbol.kt @@ -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 +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 735ab56944..fa09324f73 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.Sticker 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.message.content.GiveawayContent import dev.inmo.tgbotapi.types.location.Location @@ -110,6 +111,7 @@ internal data class RawMessage( private val is_from_offline: Boolean = false, private val paid_star_count: Int? = null, + private val paid_message_price_changed: PaidMessagePriceChanged? = null, // Voice Chat Service Messages private val video_chat_scheduled: VideoChatScheduled? = null, @@ -163,7 +165,8 @@ internal data class RawMessage( private val giveaway_winners: GiveawayPublicResults? = 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 content: MessageContent? by lazy { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/stars/TransactionPartner.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/stars/TransactionPartner.kt index d9dfe04f4c..ea7263dae4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/stars/TransactionPartner.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/payments/stars/TransactionPartner.kt @@ -60,7 +60,7 @@ sealed interface TransactionPartner { @SerialName(paidMediaPayloadField) val paidMediaPayload: PaidMediaPayload? = null, @SerialName(giftField) - val gift: Gift? = null + val gift: Gift.Regular? = null ) : TransactionPartner, SubscriptionPeriodInfo { @EncodeDefault override val type: String = Companion.type @@ -75,7 +75,7 @@ sealed interface TransactionPartner { @SerialName(chatField) val chat: PreviewChat, @SerialName(giftField) - val gift: Gift? = null + val gift: Gift.Regular? = null ) : TransactionPartner { @EncodeDefault override val type: String = Companion.type @@ -150,7 +150,7 @@ sealed interface TransactionPartner { val subscription_period: TimeSpan? = null, val paid_media: List? = null, val paid_media_payload: PaidMediaPayload? = null, - val gift: Gift? = null, + val gift: Gift.Regular? = null, val request_count: Int? = null, val sponsor_user: PreviewBot? = null, val commission_per_mille: Int? = null,