1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-21 15:53:47 +00:00

start implementation of paid invitation links

This commit is contained in:
InsanusMokrassar 2024-08-14 20:05:17 +06:00
parent dfecf93dd5
commit 228ecba6cc
2 changed files with 43 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import korlibs.time.DateTime
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.requests.chat.abstracts.*
import dev.inmo.tgbotapi.types.*
import korlibs.time.TimeSpan
import korlibs.time.days
import kotlinx.serialization.*
sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInviteLinkRequest<R> {
@ -12,6 +14,11 @@ sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInv
get() = expirationUnixTimeStamp ?.asDate
override fun method(): String = "createChatInviteLink"
sealed interface Subscription : CreateChatInviteLink<ChatInviteLinkUnlimited> {
val subscriptionPeriod: TimeSpan
val subscriptionPrice: UInt
}
companion object {
fun unlimited(
chatId: ChatIdentifier,
@ -45,6 +52,13 @@ sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInv
expiration: DateTime,
name: String? = null,
) = withJoinRequest(chatId, name, expiration.toTelegramDate())
fun paid(
chatId: ChatIdentifier,
subscriptionPrice: UInt,
subscriptionPeriod: TimeSpan = 30.days,
name: String? = null,
expirationUnixTimeStamp: TelegramDate? = null,
) = CreateChatSubscriptionInviteLink(chatId, subscriptionPrice, name, subscriptionPeriod, expirationUnixTimeStamp)
}
}
@ -71,6 +85,33 @@ data class CreateChatInviteLinkUnlimited(
get() = ChatInviteLinkUnlimited.serializer()
}
/**
* Represent [https://core.telegram.org/bots/api#createchatsubscriptioninvitelink] request
*
* @see CreateChatInviteLink.unlimited
* @see CreateChatInviteLinkWithLimitedMembers
* @see CreateChatInviteLinkWithJoinRequest
*/
@Serializable
data class CreateChatSubscriptionInviteLink(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(subscriptionPriceField)
override val subscriptionPrice: UInt,
@SerialName(nameField)
override val name: String? = null,
@SerialName(subscriptionPeriodField)
@EncodeDefault
override val subscriptionPeriod: TimeSpan = 30.days,
@SerialName(expireDateField)
override val expirationUnixTimeStamp: TelegramDate? = null,
) : CreateChatInviteLink.Subscription {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkUnlimited>
get() = ChatInviteLinkUnlimited.serializer()
}
/**
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITH `member_limit`
* and WITHOUT `creates_join_request`

View File

@ -457,6 +457,8 @@ const val permissionsField = "permissions"
const val typeField = "type"
const val valueField = "value"
const val creatorField = "creator"
const val subscriptionPeriodField = "subscription_period"
const val subscriptionPriceField = "subscription_price"
const val pointField = "point"
const val xShiftField = "x_shift"