mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 03:28:44 +00:00
start implementation of paid invitation links
This commit is contained in:
parent
dfecf93dd5
commit
228ecba6cc
@ -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`
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user