mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-21 15:53:47 +00:00
add support of createChatSubscriptionInviteLink and editChatSubscriptionInviteLink
This commit is contained in:
parent
228ecba6cc
commit
9c43fecf41
@ -5,6 +5,8 @@ import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||
import korlibs.time.TimeSpan
|
||||
import korlibs.time.days
|
||||
|
||||
public suspend fun TelegramBot.createChatInviteLinkUnlimited(
|
||||
chatId: ChatIdentifier,
|
||||
@ -81,3 +83,38 @@ public suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
|
||||
expiration: DateTime,
|
||||
name: String? = null,
|
||||
): ChatInviteLinkWithJoinRequest = createChatInviteLinkWithJoinRequest(chat.id, name, expiration.toTelegramDate())
|
||||
|
||||
|
||||
// Subscriptions
|
||||
|
||||
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
|
||||
chatId: ChatIdentifier,
|
||||
subscriptionPrice: UInt,
|
||||
subscriptionPeriod: TimeSpan = 30.days,
|
||||
name: String? = null,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
): ChatInviteLinkUnlimited = execute(CreateChatInviteLink.subscription(chatId, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp))
|
||||
|
||||
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
|
||||
chat: PublicChat,
|
||||
subscriptionPrice: UInt,
|
||||
subscriptionPeriod: TimeSpan = 30.days,
|
||||
name: String? = null,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chat.id, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp)
|
||||
|
||||
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
|
||||
chatId: ChatIdentifier,
|
||||
subscriptionPrice: UInt,
|
||||
subscriptionPeriod: TimeSpan = 30.days,
|
||||
name: String? = null,
|
||||
expirationUnixTimeStamp: DateTime,
|
||||
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chatId, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp.toTelegramDate())
|
||||
|
||||
public suspend fun TelegramBot.createChatSubscriptionInviteLink(
|
||||
chat: PublicChat,
|
||||
subscriptionPrice: UInt,
|
||||
subscriptionPeriod: TimeSpan = 30.days,
|
||||
name: String? = null,
|
||||
expirationUnixTimeStamp: DateTime,
|
||||
): ChatInviteLinkUnlimited = createChatSubscriptionInviteLink(chat.id, subscriptionPrice, subscriptionPeriod, name, expirationUnixTimeStamp)
|
@ -181,3 +181,30 @@ public suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
expiration: DateTime,
|
||||
name: String? = null,
|
||||
): ChatInviteLinkWithJoinRequest = editChatInviteLinkWithJoinRequest(chat.id, previousLink, name , expiration.toTelegramDate())
|
||||
|
||||
|
||||
// Subscriptions
|
||||
|
||||
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: String,
|
||||
name: String,
|
||||
): ChatInviteLinkUnlimited = execute(EditChatInviteLink.subscription(chatId, previousLink, name))
|
||||
|
||||
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
name: String,
|
||||
): ChatInviteLinkUnlimited = editChatSubscriptionInviteLink(chatId, previousLink.inviteLink, name)
|
||||
|
||||
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
|
||||
chat: PublicChat,
|
||||
previousLink: String,
|
||||
name: String,
|
||||
): ChatInviteLinkUnlimited = editChatSubscriptionInviteLink(chat.id, previousLink, name)
|
||||
|
||||
public suspend fun TelegramBot.editChatSubscriptionInviteLink(
|
||||
chat: PublicChat,
|
||||
previousLink: ChatInviteLink,
|
||||
name: String,
|
||||
): ChatInviteLinkUnlimited = editChatSubscriptionInviteLink(chat.id, previousLink, name)
|
||||
|
@ -1,9 +1,9 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.invite_links
|
||||
|
||||
import korlibs.time.DateTime
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.utils.TimeSpanAsSecondsSerializer
|
||||
import korlibs.time.TimeSpan
|
||||
import korlibs.time.days
|
||||
import kotlinx.serialization.*
|
||||
@ -12,11 +12,14 @@ sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInv
|
||||
val expirationUnixTimeStamp: TelegramDate?
|
||||
override val expireDate: DateTime?
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
|
||||
override fun method(): String = "createChatInviteLink"
|
||||
|
||||
sealed interface Subscription : CreateChatInviteLink<ChatInviteLinkUnlimited> {
|
||||
val subscriptionPeriod: TimeSpan
|
||||
val subscriptionPrice: UInt
|
||||
|
||||
override fun method(): String = "createChatSubscriptionInviteLink"
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ -52,7 +55,7 @@ sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInv
|
||||
expiration: DateTime,
|
||||
name: String? = null,
|
||||
) = withJoinRequest(chatId, name, expiration.toTelegramDate())
|
||||
fun paid(
|
||||
fun subscription(
|
||||
chatId: ChatIdentifier,
|
||||
subscriptionPrice: UInt,
|
||||
subscriptionPeriod: TimeSpan = 30.days,
|
||||
@ -63,7 +66,7 @@ sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInv
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITHOUT `member_limit`
|
||||
* Represent [request](https://core.telegram.org/bots/api#createchatinvitelink) WITHOUT `member_limit`
|
||||
* and `creates_join_request`
|
||||
*
|
||||
* @see CreateChatInviteLink.unlimited
|
||||
@ -86,7 +89,7 @@ data class CreateChatInviteLinkUnlimited(
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#createchatsubscriptioninvitelink] request
|
||||
* Represent [request](https://core.telegram.org/bots/api#createchatsubscriptioninvitelink)
|
||||
*
|
||||
* @see CreateChatInviteLink.unlimited
|
||||
* @see CreateChatInviteLinkWithLimitedMembers
|
||||
@ -102,6 +105,7 @@ data class CreateChatSubscriptionInviteLink(
|
||||
override val name: String? = null,
|
||||
@SerialName(subscriptionPeriodField)
|
||||
@EncodeDefault
|
||||
@Serializable(TimeSpanAsSecondsSerializer::class)
|
||||
override val subscriptionPeriod: TimeSpan = 30.days,
|
||||
@SerialName(expireDateField)
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
@ -113,7 +117,7 @@ data class CreateChatSubscriptionInviteLink(
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITH `member_limit`
|
||||
* Represent [request](https://core.telegram.org/bots/api#createchatinvitelink) WITH `member_limit`
|
||||
* and WITHOUT `creates_join_request`
|
||||
*
|
||||
* @see CreateChatInviteLink.withLimitedMembers
|
||||
@ -136,7 +140,7 @@ data class CreateChatInviteLinkWithLimitedMembers(
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITHOUT `member_limit`
|
||||
* Represent [request](https://core.telegram.org/bots/api#createchatinvitelink) WITHOUT `member_limit`
|
||||
* and WITH `creates_join_request`
|
||||
*
|
||||
* @see CreateChatInviteLink.withJoinRequest
|
||||
|
@ -12,6 +12,10 @@ sealed interface EditChatInviteLink<R : SecondaryChatInviteLink> : EditChatInvit
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
override fun method(): String = "editChatInviteLink"
|
||||
|
||||
sealed interface Subscription : EditChatInviteLink<ChatInviteLinkUnlimited> {
|
||||
override fun method(): String = "editChatSubscriptionInviteLink"
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun unlimited(
|
||||
chatId: ChatIdentifier,
|
||||
@ -51,6 +55,11 @@ sealed interface EditChatInviteLink<R : SecondaryChatInviteLink> : EditChatInvit
|
||||
expiration: DateTime,
|
||||
name: String? = null,
|
||||
) = withJoinRequest(chatId, inviteLink, name, expiration.toTelegramDate())
|
||||
fun subscription(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
name: String,
|
||||
) = EditChatSubscriptionInviteLink(chatId, inviteLink, name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,6 +88,28 @@ data class EditChatInviteLinkUnlimited(
|
||||
get() = ChatInviteLinkUnlimited.serializer()
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [request](https://core.telegram.org/bots/api#editchatsubscriptioninvitelink)
|
||||
*
|
||||
* @see EditChatInviteLink.subscription
|
||||
*/
|
||||
@Serializable
|
||||
data class EditChatSubscriptionInviteLink(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(nameField)
|
||||
override val name: String? = null,
|
||||
) : EditChatInviteLink.Subscription {
|
||||
override val expirationUnixTimeStamp: TelegramDate?
|
||||
get() = null
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkUnlimited>
|
||||
get() = ChatInviteLinkUnlimited.serializer()
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#editchatinvitelink] request WITH `member_limit`
|
||||
* and WITHOUT `creates_join_request`
|
||||
|
@ -0,0 +1,22 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
|
||||
import korlibs.time.TimeSpan
|
||||
import korlibs.time.seconds
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
object TimeSpanAsSecondsSerializer : KSerializer<TimeSpan> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = Long.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): TimeSpan {
|
||||
return decoder.decodeLong().seconds
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: TimeSpan) {
|
||||
encoder.encodeLong(value.inWholeSeconds)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user