1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 09:07:12 +00:00

fill api of chat invite links

This commit is contained in:
InsanusMokrassar 2021-03-11 21:25:11 +06:00
parent 36202133a1
commit 65cba0f014
7 changed files with 133 additions and 11 deletions

View File

@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.DeserializationStrategy
interface ChatInviteLinkRequest : SimpleRequest<CommonInviteLink> {
val chatId: ChatId
val chatId: ChatIdentifier
override val resultDeserializer: DeserializationStrategy<CommonInviteLink>
get() = CommonInviteLink.serializer()

View File

@ -8,14 +8,14 @@ import kotlinx.serialization.*
@Serializable
data class CreateChatInviteLink(
@SerialName(chatIdField)
override val chatId: ChatId,
override val chatId: ChatIdentifier,
@SerialName(expireDateField)
private val expirationUnixTimeStamp: UnixTimeStamp? = null,
private val expirationUnixTimeStamp: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : EditChatInviteLinkRequest {
override val expireDate: DateTime?
get() = expirationUnixTimeStamp ?.seconds ?.let { DateTime(it.milliseconds) }
get() = expirationUnixTimeStamp ?.asDate
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
@ -27,5 +27,5 @@ fun CreateChatInviteLink(
expireDate: DateTime,
membersLimit: MembersLimit? = null
): CreateChatInviteLink = CreateChatInviteLink(
chatId, expireDate.unixMillisDouble.milliseconds.seconds.toLong(), membersLimit
chatId, expireDate.toTelegramDate(), membersLimit
)

View File

@ -9,16 +9,16 @@ import kotlinx.serialization.*
@Serializable
data class EditChatInviteLink(
@SerialName(chatIdField)
override val chatId: ChatId,
override val chatId: ChatIdentifier,
@SerialName(inviteLinkField)
override val inviteLink: String,
@SerialName(expireDateField)
private val expirationUnixTimeStamp: UnixTimeStamp? = null,
private val expirationUnixTimeStamp: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : EditChatInviteLinkRequest, KnownChatInviteLinkRequest {
override val expireDate: DateTime?
get() = expirationUnixTimeStamp ?.seconds ?.let { DateTime(it.milliseconds) }
get() = expirationUnixTimeStamp ?.asDate
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
@ -26,10 +26,10 @@ data class EditChatInviteLink(
}
fun EditChatInviteLink(
chatId: ChatId,
chatId: ChatIdentifier,
inviteLink: String,
expireDate: DateTime,
membersLimit: MembersLimit? = null
): EditChatInviteLink = EditChatInviteLink(
chatId, inviteLink, expireDate.unixMillisDouble.milliseconds.seconds.toLong(), membersLimit
chatId, inviteLink, expireDate.toTelegramDate(), membersLimit
)

View File

@ -9,7 +9,7 @@ import kotlinx.serialization.*
@Serializable
data class RevokeChatInviteLink(
@SerialName(chatIdField)
override val chatId: ChatId,
override val chatId: ChatIdentifier,
@SerialName(inviteLinkField)
override val inviteLink: String
) : KnownChatInviteLinkRequest {

View File

@ -0,0 +1,31 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import com.soywiz.klock.DateTime
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.abstracts.PublicChat
suspend fun TelegramBot.createChatInviteLink(
chatId: ChatIdentifier,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = execute(CreateChatInviteLink(chatId, expiration, membersLimit))
suspend fun TelegramBot.createChatInviteLink(
chat: PublicChat,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = createChatInviteLink(chat.id, expiration, membersLimit)
suspend fun TelegramBot.createChatInviteLink(
chatId: ChatIdentifier,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = createChatInviteLink(chatId, expiration.toTelegramDate(), membersLimit)
suspend fun TelegramBot.createChatInviteLink(
chat: PublicChat,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = createChatInviteLink(chat.id, expiration.toTelegramDate(), membersLimit)

View File

@ -0,0 +1,64 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink
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(
chatId: ChatIdentifier,
previousLink: String,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = execute(EditChatInviteLink(chatId, previousLink, expiration, membersLimit))
suspend fun TelegramBot.editChatInviteLink(
chat: PublicChat,
previousLink: String,
expiration: TelegramDate? = null,
membersLimit: MembersLimit? = null
) = editChatInviteLink(chat.id, previousLink, expiration, membersLimit)
suspend fun TelegramBot.editChatInviteLink(
chatId: ChatIdentifier,
previousLink: String,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = editChatInviteLink(chatId, previousLink, expiration.toTelegramDate(), membersLimit)
suspend fun TelegramBot.editChatInviteLink(
chat: PublicChat,
previousLink: String,
expiration: DateTime,
membersLimit: MembersLimit? = null
) = editChatInviteLink(chat.id, previousLink, expiration.toTelegramDate(), membersLimit)
suspend fun TelegramBot.editChatInviteLink(
chat: ChatIdentifier,
previousLink: ChatInviteLink,
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
suspend fun TelegramBot.editChatInviteLink(
chat: ChatIdentifier,
previousLink: ChatInviteLink,
expiration: DateTime,
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
suspend fun TelegramBot.editChatInviteLink(
chat: PublicChat,
previousLink: ChatInviteLink,
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
suspend fun TelegramBot.editChatInviteLink(
chat: PublicChat,
previousLink: ChatInviteLink,
expiration: DateTime,
membersLimit: MembersLimit? = previousLink.membersLimit
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)

View File

@ -0,0 +1,27 @@
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.chat.invite_links.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
suspend fun TelegramBot.revokeChatInviteLink(
chatId: ChatIdentifier,
previousLink: String
) = execute(RevokeChatInviteLink(chatId, previousLink))
suspend fun TelegramBot.revokeChatInviteLink(
chat: PublicChat,
previousLink: String
) = revokeChatInviteLink(chat.id, previousLink)
suspend fun TelegramBot.revokeChatInviteLink(
chatId: ChatIdentifier,
previousLink: ChatInviteLink
) = revokeChatInviteLink(chatId, previousLink.inviteLink)
suspend fun TelegramBot.revokeChatInviteLink(
chat: PublicChat,
previousLink: ChatInviteLink
) = revokeChatInviteLink(chat, previousLink.inviteLink)