mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
chat invite links update
This commit is contained in:
parent
20b1645935
commit
10c62bf2c7
@ -7,6 +7,14 @@
|
||||
* `Klock`: `2.4.6` -> `2.4.7`
|
||||
* `Ktor`: `1.6.4` -> `1.6.5`
|
||||
* `MicroUtils`: `0.7.3` -> `0.8.0`
|
||||
* `Core`:
|
||||
* Replacement of simple `CreateChatInviteLink` and `EditChatInviteLink` with several new:
|
||||
* `CreateChatInviteLinkSimple`
|
||||
* `CreateChatInviteLinkWithLimitedMembers`
|
||||
* `CreateChatInviteLinkWithJoinRequest`
|
||||
* `EditChatInviteLinkSimple`
|
||||
* `EditChatInviteLinkWithLimitedMembers`
|
||||
* `EditChatInviteLinkWithJoinRequest`
|
||||
|
||||
## 0.36.1
|
||||
|
||||
|
@ -6,26 +6,66 @@ import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLink(
|
||||
suspend fun TelegramBot.createChatInviteLinkUnlimited(
|
||||
chatId: ChatIdentifier,
|
||||
expiration: TelegramDate? = null,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = execute(CreateChatInviteLink(chatId, expiration, membersLimit))
|
||||
expiration: TelegramDate? = null
|
||||
) = execute(CreateChatInviteLink.unlimited(chatId, expiration))
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLink(
|
||||
suspend fun TelegramBot.createChatInviteLinkUnlimited(
|
||||
chat: PublicChat,
|
||||
expiration: TelegramDate? = null,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = createChatInviteLink(chat.id, expiration, membersLimit)
|
||||
) = createChatInviteLinkUnlimited(chat.id, expiration)
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLink(
|
||||
suspend fun TelegramBot.createChatInviteLinkUnlimited(
|
||||
chatId: ChatIdentifier,
|
||||
expiration: DateTime
|
||||
) = createChatInviteLinkUnlimited(chatId, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkUnlimited(
|
||||
chat: PublicChat,
|
||||
expiration: DateTime
|
||||
) = createChatInviteLinkUnlimited(chat.id, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: TelegramDate? = null
|
||||
) = execute(CreateChatInviteLink.withLimitedMembers(chatId, membersLimit, expiration))
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
|
||||
chat: PublicChat,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: TelegramDate? = null,
|
||||
) = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, expiration)
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime,
|
||||
) = createChatInviteLinkWithLimitedMembers(chatId, membersLimit, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkWithLimitedMembers(
|
||||
chat: PublicChat,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime,
|
||||
) = createChatInviteLinkWithLimitedMembers(chat.id, membersLimit, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
expiration: TelegramDate? = null
|
||||
) = execute(CreateChatInviteLink.withJoinRequest(chatId, expiration))
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
|
||||
chat: PublicChat,
|
||||
expiration: TelegramDate? = null,
|
||||
) = createChatInviteLinkWithJoinRequest(chat.id, expiration)
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
expiration: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = createChatInviteLink(chatId, expiration.toTelegramDate(), membersLimit)
|
||||
) = createChatInviteLinkWithJoinRequest(chatId, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.createChatInviteLink(
|
||||
suspend fun TelegramBot.createChatInviteLinkWithJoinRequest(
|
||||
chat: PublicChat,
|
||||
expiration: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = createChatInviteLink(chat.id, expiration.toTelegramDate(), membersLimit)
|
||||
) = createChatInviteLinkWithJoinRequest(chat.id, expiration.toTelegramDate())
|
||||
|
@ -6,58 +6,154 @@ import dev.inmo.tgbotapi.requests.chat.invite_links.EditChatInviteLink
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: String,
|
||||
expiration: TelegramDate? = null,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = execute(EditChatInviteLink(chatId, previousLink, expiration, membersLimit))
|
||||
expiration: TelegramDate? = null
|
||||
) = execute(EditChatInviteLink.unlimited(chatId, previousLink, expiration))
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chat: PublicChat,
|
||||
previousLink: String,
|
||||
expiration: TelegramDate? = null,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = editChatInviteLink(chat.id, previousLink, expiration, membersLimit)
|
||||
) = editChatInviteLinkUnlimited(chat.id, previousLink, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: String,
|
||||
expiration: DateTime
|
||||
) = editChatInviteLinkUnlimited(chatId, previousLink, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chat: PublicChat,
|
||||
previousLink: String,
|
||||
expiration: DateTime
|
||||
) = editChatInviteLinkUnlimited(chat.id, previousLink, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: String,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: TelegramDate? = null
|
||||
) = execute(EditChatInviteLink.withLimitedMembers(chatId, previousLink, membersLimit, expiration))
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chat: PublicChat,
|
||||
previousLink: String,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: TelegramDate? = null,
|
||||
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: String,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime,
|
||||
) = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chat: PublicChat,
|
||||
previousLink: String,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime,
|
||||
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: String,
|
||||
expiration: TelegramDate? = null
|
||||
) = execute(EditChatInviteLink.withJoinRequest(chatId, previousLink, expiration))
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chat: PublicChat,
|
||||
previousLink: String,
|
||||
expiration: TelegramDate? = null,
|
||||
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: String,
|
||||
expiration: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = editChatInviteLink(chatId, previousLink, expiration.toTelegramDate(), membersLimit)
|
||||
) = editChatInviteLinkWithJoinRequest(chatId, previousLink, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chat: PublicChat,
|
||||
previousLink: String,
|
||||
expiration: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
) = editChatInviteLink(chat.id, previousLink, expiration.toTelegramDate(), membersLimit)
|
||||
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
chat: ChatIdentifier,
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
|
||||
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||
expiration: TelegramDate? = null
|
||||
) = editChatInviteLinkUnlimited(chatId, previousLink.inviteLink, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
chat: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: DateTime,
|
||||
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chat: PublicChat,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
|
||||
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||
expiration: TelegramDate? = null,
|
||||
) = editChatInviteLinkUnlimited(chat.id, previousLink, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLink(
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: DateTime
|
||||
) = editChatInviteLinkUnlimited(chatId, previousLink, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkUnlimited(
|
||||
chat: PublicChat,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: DateTime
|
||||
) = editChatInviteLinkUnlimited(chat.id, previousLink, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: TelegramDate? = null
|
||||
) = editChatInviteLinkWithLimitedMembers(chatId, previousLink.inviteLink, membersLimit, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chat: PublicChat,
|
||||
previousLink: ChatInviteLink,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: TelegramDate? = null,
|
||||
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime,
|
||||
) = editChatInviteLinkWithLimitedMembers(chatId, previousLink, membersLimit, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithLimitedMembers(
|
||||
chat: PublicChat,
|
||||
previousLink: ChatInviteLink,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime,
|
||||
) = editChatInviteLinkWithLimitedMembers(chat.id, previousLink, membersLimit, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: TelegramDate? = null
|
||||
) = editChatInviteLinkWithJoinRequest(chatId, previousLink.inviteLink, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chat: PublicChat,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: TelegramDate? = null,
|
||||
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, expiration)
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: DateTime,
|
||||
) = editChatInviteLinkWithJoinRequest(chatId, previousLink, expiration.toTelegramDate())
|
||||
|
||||
suspend fun TelegramBot.editChatInviteLinkWithJoinRequest(
|
||||
chat: PublicChat,
|
||||
previousLink: ChatInviteLink,
|
||||
expiration: DateTime,
|
||||
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||
) = editChatInviteLinkWithJoinRequest(chat.id, previousLink, expiration.toTelegramDate())
|
||||
|
@ -5,16 +5,26 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
|
||||
interface ChatInviteLinkRequest : SimpleRequest<CommonInviteLink> {
|
||||
interface ChatInviteLinkRequest<R : SecondaryChatInviteLink> : SimpleRequest<R> {
|
||||
val chatId: ChatIdentifier
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<CommonInviteLink>
|
||||
get() = CommonInviteLink.serializer()
|
||||
}
|
||||
interface KnownChatInviteLinkRequest : ChatInviteLinkRequest {
|
||||
|
||||
interface KnownChatInviteLinkRequest<R : SecondaryChatInviteLink> : ChatInviteLinkRequest<R> {
|
||||
val inviteLink: String
|
||||
}
|
||||
interface EditChatInviteLinkRequest : ChatInviteLinkRequest {
|
||||
val expireDate: DateTime?
|
||||
val membersLimit: MembersLimit?
|
||||
|
||||
interface LimitedMembersChatInviteLinkRequest : ChatInviteLinkRequest<ChatInviteLinkWithLimitedMembers> {
|
||||
val membersLimit: MembersLimit
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkWithLimitedMembers>
|
||||
get() = ChatInviteLinkWithLimitedMembers.serializer()
|
||||
}
|
||||
|
||||
interface WithJoinRequestChatInviteLinkRequest : ChatInviteLinkRequest<ChatInviteLinkWithJoinRequest> {
|
||||
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkWithJoinRequest>
|
||||
get() = ChatInviteLinkWithJoinRequest.serializer()
|
||||
}
|
||||
|
||||
interface EditChatInviteLinkRequest<R : SecondaryChatInviteLink> : ChatInviteLinkRequest<R> {
|
||||
val expireDate: DateTime?
|
||||
}
|
||||
|
@ -1,31 +1,108 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.invite_links
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
sealed interface CreateChatInviteLink<R : SecondaryChatInviteLink> : EditChatInviteLinkRequest<R> {
|
||||
val expirationUnixTimeStamp: TelegramDate?
|
||||
override val expireDate: DateTime?
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
override fun method(): String = "createChatInviteLink"
|
||||
|
||||
companion object {
|
||||
fun unlimited(
|
||||
chatId: ChatIdentifier,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) = CreateChatInviteLinkUnlimited(chatId, expirationUnixTimeStamp)
|
||||
fun withLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
membersLimit: MembersLimit,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) = CreateChatInviteLinkWithLimitedMembers(chatId, membersLimit, expirationUnixTimeStamp)
|
||||
fun withJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) = CreateChatInviteLinkWithJoinRequest(chatId, expirationUnixTimeStamp)
|
||||
fun unlimited(
|
||||
chatId: ChatIdentifier,
|
||||
expiration: DateTime? = null,
|
||||
) = unlimited(chatId, expiration?.toTelegramDate())
|
||||
fun withLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime? = null,
|
||||
) = withLimitedMembers(chatId, membersLimit, expiration?.toTelegramDate())
|
||||
fun withJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
expiration: DateTime? = null,
|
||||
) = withJoinRequest(chatId, expiration?.toTelegramDate())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITHOUT `member_limit`
|
||||
* and `creates_join_request`
|
||||
*
|
||||
* @see CreateChatInviteLink.unlimited
|
||||
* @see CreateChatInviteLinkWithLimitedMembers
|
||||
* @see CreateChatInviteLinkWithJoinRequest
|
||||
*/
|
||||
@Serializable
|
||||
data class CreateChatInviteLink(
|
||||
data class CreateChatInviteLinkUnlimited(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(expireDateField)
|
||||
private val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : EditChatInviteLinkRequest {
|
||||
override val expireDate: DateTime?
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) : CreateChatInviteLink<ChatInviteLinkUnlimited> {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "createChatInviteLink"
|
||||
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkUnlimited>
|
||||
get() = ChatInviteLinkUnlimited.serializer()
|
||||
}
|
||||
|
||||
fun CreateChatInviteLink(
|
||||
chatId: ChatId,
|
||||
expireDate: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
): CreateChatInviteLink = CreateChatInviteLink(
|
||||
chatId, expireDate.toTelegramDate(), membersLimit
|
||||
)
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITH `member_limit`
|
||||
* and WITHOUT `creates_join_request`
|
||||
*
|
||||
* @see CreateChatInviteLink.withLimitedMembers
|
||||
* @see CreateChatInviteLinkUnlimited
|
||||
* @see CreateChatInviteLinkWithJoinRequest
|
||||
*/
|
||||
@Serializable
|
||||
data class CreateChatInviteLinkWithLimitedMembers(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit,
|
||||
@SerialName(expireDateField)
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) : CreateChatInviteLink<ChatInviteLinkWithLimitedMembers>, LimitedMembersChatInviteLinkRequest {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#createchatinvitelink] request WITHOUT `member_limit`
|
||||
* and WITH `creates_join_request`
|
||||
*
|
||||
* @see CreateChatInviteLink.withJoinRequest
|
||||
* @see CreateChatInviteLinkUnlimited
|
||||
* @see CreateChatInviteLinkWithLimitedMembers
|
||||
*/
|
||||
@Serializable
|
||||
data class CreateChatInviteLinkWithJoinRequest(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(expireDateField)
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) : CreateChatInviteLink<ChatInviteLinkWithJoinRequest>, WithJoinRequestChatInviteLinkRequest {
|
||||
@Required
|
||||
@SerialName(createsJoinRequestField)
|
||||
private val createsJoinRequest: Boolean = true
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -1,35 +1,122 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.invite_links
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.KnownChatInviteLinkRequest
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
sealed interface EditChatInviteLink<R : SecondaryChatInviteLink> : EditChatInviteLinkRequest<R>, KnownChatInviteLinkRequest<R> {
|
||||
val expirationUnixTimeStamp: TelegramDate?
|
||||
override val expireDate: DateTime?
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
override fun method(): String = "editChatInviteLink"
|
||||
|
||||
companion object {
|
||||
fun unlimited(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) = EditChatInviteLinkUnlimited(chatId, inviteLink, expirationUnixTimeStamp)
|
||||
fun withLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
membersLimit: MembersLimit,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) = EditChatInviteLinkWithLimitedMembers(chatId, inviteLink, membersLimit, expirationUnixTimeStamp)
|
||||
fun withJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) = EditChatInviteLinkWithJoinRequest(chatId, inviteLink, expirationUnixTimeStamp)
|
||||
fun unlimited(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
expiration: DateTime? = null,
|
||||
) = unlimited(chatId, inviteLink, expiration ?.toTelegramDate())
|
||||
fun withLimitedMembers(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
membersLimit: MembersLimit,
|
||||
expiration: DateTime? = null,
|
||||
) = withLimitedMembers(chatId, inviteLink, membersLimit, expiration ?.toTelegramDate())
|
||||
fun withJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
expiration: DateTime? = null,
|
||||
) = withJoinRequest(chatId, inviteLink, expiration ?.toTelegramDate())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#editchatinvitelink] request WITHOUT `member_limit`
|
||||
* and `creates_join_request`
|
||||
*
|
||||
* @see EditChatInviteLink.unlimited
|
||||
* @see EditChatInviteLinkWithLimitedMembers
|
||||
* @see EditChatInviteLinkWithJoinRequest
|
||||
*/
|
||||
@Serializable
|
||||
data class EditChatInviteLink(
|
||||
data class EditChatInviteLinkUnlimited(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(expireDateField)
|
||||
private val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : EditChatInviteLinkRequest, KnownChatInviteLinkRequest {
|
||||
override val expireDate: DateTime?
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) : EditChatInviteLink<ChatInviteLinkUnlimited> {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "editChatInviteLink"
|
||||
override val resultDeserializer: DeserializationStrategy<ChatInviteLinkUnlimited>
|
||||
get() = ChatInviteLinkUnlimited.serializer()
|
||||
}
|
||||
|
||||
fun EditChatInviteLink(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
expireDate: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
): EditChatInviteLink = EditChatInviteLink(
|
||||
chatId, inviteLink, expireDate.toTelegramDate(), membersLimit
|
||||
)
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#editchatinvitelink] request WITH `member_limit`
|
||||
* and WITHOUT `creates_join_request`
|
||||
*
|
||||
* @see EditChatInviteLink.withLimitedMembers
|
||||
* @see EditChatInviteLinkUnlimited
|
||||
* @see EditChatInviteLinkWithJoinRequest
|
||||
*/
|
||||
@Serializable
|
||||
data class EditChatInviteLinkWithLimitedMembers(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit,
|
||||
@SerialName(expireDateField)
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) : EditChatInviteLink<ChatInviteLinkWithLimitedMembers>,
|
||||
LimitedMembersChatInviteLinkRequest {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent [https://core.telegram.org/bots/api#editchatinvitelink] request WITHOUT `member_limit`
|
||||
* and WITH `creates_join_request`
|
||||
*
|
||||
* @see EditChatInviteLink.withJoinRequest
|
||||
* @see EditChatInviteLinkUnlimited
|
||||
* @see EditChatInviteLinkWithLimitedMembers
|
||||
*/
|
||||
@Serializable
|
||||
data class EditChatInviteLinkWithJoinRequest(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(expireDateField)
|
||||
override val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
) : EditChatInviteLink<ChatInviteLinkWithJoinRequest>,
|
||||
WithJoinRequestChatInviteLinkRequest {
|
||||
@Required
|
||||
@SerialName(createsJoinRequestField)
|
||||
private val createsJoinRequest: Boolean = true
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
@ -10,9 +10,11 @@ data class RevokeChatInviteLink(
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String
|
||||
) : KnownChatInviteLinkRequest {
|
||||
) : KnownChatInviteLinkRequest<SecondaryChatInviteLink> {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
override val resultDeserializer: DeserializationStrategy<SecondaryChatInviteLink>
|
||||
get() = SecondaryChatInviteLink.serializer()
|
||||
|
||||
override fun method(): String = "revokeChatInviteLink"
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.WithUser
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
@ -20,7 +21,11 @@ private data class RawChatInviteLink(
|
||||
@SerialName(expireDateField)
|
||||
val expirationDateTime: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
val membersLimit: MembersLimit ?= null
|
||||
val membersLimit: MembersLimit ?= null,
|
||||
@SerialName(createsJoinRequestField)
|
||||
val createsJoinRequest: Boolean? = null,
|
||||
@SerialName(pendingJoinRequestCountField)
|
||||
val pendingJoinRequestCount: MembersLimit ?= null
|
||||
)
|
||||
|
||||
private fun ChatInviteLink.toRawChatInviteLink() = RawChatInviteLink(
|
||||
@ -29,17 +34,36 @@ private fun ChatInviteLink.toRawChatInviteLink() = RawChatInviteLink(
|
||||
isPrimary,
|
||||
isRevoked,
|
||||
expirationDateTime ?.toTelegramDate(),
|
||||
membersLimit
|
||||
(this as? ChatInviteLinkWithLimitedMembers) ?.membersLimit,
|
||||
this is ChatInviteLinkWithJoinRequest,
|
||||
(this as? ChatInviteLinkWithJoinRequest) ?.leftToReview
|
||||
)
|
||||
|
||||
@Serializable(ChatInviteLinkSerializer::class)
|
||||
sealed class ChatInviteLink {
|
||||
abstract val inviteLink: String
|
||||
abstract val creator: User
|
||||
abstract val isPrimary: Boolean
|
||||
abstract val isRevoked: Boolean
|
||||
abstract val expirationDateTime: DateTime?
|
||||
abstract val membersLimit: MembersLimit?
|
||||
sealed interface ChatInviteLink : WithUser {
|
||||
val inviteLink: String
|
||||
val creator: User
|
||||
val isPrimary: Boolean
|
||||
get() = this is PrimaryInviteLink
|
||||
val isRevoked: Boolean
|
||||
val expirationDateTime: DateTime?
|
||||
|
||||
override val user: User
|
||||
get() = creator
|
||||
|
||||
companion object {
|
||||
fun serializer(): KSerializer<ChatInviteLink> = ChatInviteLinkSerializer
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable(ChatInviteLinkSerializer::class)
|
||||
sealed interface SecondaryChatInviteLink : ChatInviteLink {
|
||||
override val isPrimary: Boolean
|
||||
get() = false
|
||||
|
||||
companion object {
|
||||
fun serializer(): KSerializer<SecondaryChatInviteLink> = ChatInviteLinkSerializer as KSerializer<SecondaryChatInviteLink>
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@ -52,17 +76,47 @@ data class PrimaryInviteLink(
|
||||
override val isRevoked: Boolean = false,
|
||||
@SerialName(expireDateField)
|
||||
private val expireDate: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : ChatInviteLink() {
|
||||
override val isPrimary: Boolean
|
||||
get() = true
|
||||
) : ChatInviteLink {
|
||||
override val expirationDateTime: DateTime?
|
||||
get() = expireDate ?.asDate
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CommonInviteLink(
|
||||
data class ChatInviteLinkWithJoinRequest(
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(creatorField)
|
||||
override val creator: User,
|
||||
@SerialName(pendingJoinRequestCountField)
|
||||
val leftToReview: Int,
|
||||
@SerialName(isRevokedField)
|
||||
override val isRevoked: Boolean = false,
|
||||
@SerialName(expireDateField)
|
||||
private val expireDate: TelegramDate? = null
|
||||
) : SecondaryChatInviteLink {
|
||||
override val expirationDateTime: DateTime?
|
||||
get() = expireDate ?.asDate
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ChatInviteLinkWithLimitedMembers(
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(creatorField)
|
||||
override val creator: User,
|
||||
@SerialName(memberLimitField)
|
||||
val membersLimit: MembersLimit,
|
||||
@SerialName(isRevokedField)
|
||||
override val isRevoked: Boolean = false,
|
||||
@SerialName(expireDateField)
|
||||
private val expireDate: TelegramDate? = null,
|
||||
) : SecondaryChatInviteLink {
|
||||
override val expirationDateTime: DateTime?
|
||||
get() = expireDate ?.asDate
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ChatInviteLinkUnlimited(
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(creatorField)
|
||||
@ -71,11 +125,7 @@ data class CommonInviteLink(
|
||||
override val isRevoked: Boolean = false,
|
||||
@SerialName(expireDateField)
|
||||
private val expireDate: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : ChatInviteLink() {
|
||||
override val isPrimary: Boolean
|
||||
get() = false
|
||||
) : SecondaryChatInviteLink {
|
||||
override val expirationDateTime: DateTime?
|
||||
get() = expireDate ?.asDate
|
||||
}
|
||||
@ -89,11 +139,21 @@ object ChatInviteLinkSerializer : KSerializer<ChatInviteLink> {
|
||||
val deserializedRaw = RawChatInviteLink.serializer().deserialize(decoder)
|
||||
return deserializedRaw.run {
|
||||
when {
|
||||
deserializedRaw.isPrimary -> PrimaryInviteLink(
|
||||
inviteLink, creator, isRevoked, expirationDateTime, membersLimit
|
||||
isPrimary -> PrimaryInviteLink(
|
||||
inviteLink, creator, isRevoked, expirationDateTime
|
||||
)
|
||||
else -> CommonInviteLink(
|
||||
inviteLink, creator, isRevoked, expirationDateTime, membersLimit
|
||||
createsJoinRequest == true -> {
|
||||
ChatInviteLinkWithJoinRequest(
|
||||
inviteLink, creator, pendingJoinRequestCount ?: 0, isRevoked, expirationDateTime
|
||||
)
|
||||
}
|
||||
membersLimit != null -> {
|
||||
ChatInviteLinkWithLimitedMembers(
|
||||
inviteLink, creator, membersLimit, isRevoked, expirationDateTime
|
||||
)
|
||||
}
|
||||
else -> ChatInviteLinkUnlimited(
|
||||
inviteLink, creator, isRevoked, expirationDateTime
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -177,6 +177,8 @@ const val messageAutoDeleteTimeField = "message_auto_delete_time"
|
||||
const val isPrimaryField = "is_primary"
|
||||
const val isRevokedField = "is_revoked"
|
||||
const val expireDateField = "expire_date"
|
||||
const val createsJoinRequestField = "creates_join_request"
|
||||
const val pendingJoinRequestCountField = "pending_join_request_count"
|
||||
const val memberLimitField = "member_limit"
|
||||
|
||||
const val requestContactField = "request_contact"
|
||||
|
Loading…
Reference in New Issue
Block a user