mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
add support of join request approving/declining
This commit is contained in:
parent
c24d536d4c
commit
4715eb424f
@ -0,0 +1,39 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.chat.invite_links.ApproveChatJoinRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
|
||||
|
||||
suspend fun TelegramBot.approveChatJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId
|
||||
) = execute(ApproveChatJoinRequest(chatId, userId))
|
||||
|
||||
suspend fun TelegramBot.approveChatJoinRequest(
|
||||
chat: PublicChat,
|
||||
userId: UserId
|
||||
) = approveChatJoinRequest(chat.id, userId)
|
||||
|
||||
suspend fun TelegramBot.approveChatJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
user: User
|
||||
) = approveChatJoinRequest(chatId, user.id)
|
||||
|
||||
suspend fun TelegramBot.approveChatJoinRequest(
|
||||
chat: PublicChat,
|
||||
user: User
|
||||
) = approveChatJoinRequest(chat.id, user.id)
|
||||
|
||||
suspend fun TelegramBot.approveChatJoinRequest(
|
||||
chatJoinRequest: ChatJoinRequest
|
||||
) = approveChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user)
|
||||
|
||||
suspend fun TelegramBot.approve(
|
||||
chatJoinRequest: ChatJoinRequest
|
||||
) = approveChatJoinRequest(chatJoinRequest)
|
||||
|
||||
suspend fun TelegramBot.approveChatJoinRequest(
|
||||
chatJoinRequestUpdate: ChatJoinRequestUpdate
|
||||
) = approveChatJoinRequest(chatJoinRequestUpdate.data)
|
@ -0,0 +1,40 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.chat.invite_links.ApproveChatJoinRequest
|
||||
import dev.inmo.tgbotapi.requests.chat.invite_links.DeclineChatJoinRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||
import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
|
||||
|
||||
suspend fun TelegramBot.declineChatJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId
|
||||
) = execute(DeclineChatJoinRequest(chatId, userId))
|
||||
|
||||
suspend fun TelegramBot.declineChatJoinRequest(
|
||||
chat: PublicChat,
|
||||
userId: UserId
|
||||
) = declineChatJoinRequest(chat.id, userId)
|
||||
|
||||
suspend fun TelegramBot.declineChatJoinRequest(
|
||||
chatId: ChatIdentifier,
|
||||
user: User
|
||||
) = declineChatJoinRequest(chatId, user.id)
|
||||
|
||||
suspend fun TelegramBot.declineChatJoinRequest(
|
||||
chat: PublicChat,
|
||||
user: User
|
||||
) = declineChatJoinRequest(chat.id, user.id)
|
||||
|
||||
suspend fun TelegramBot.declineChatJoinRequest(
|
||||
chatJoinRequest: ChatJoinRequest
|
||||
) = declineChatJoinRequest(chatJoinRequest.chat, chatJoinRequest.user)
|
||||
|
||||
suspend fun TelegramBot.decline(
|
||||
chatJoinRequest: ChatJoinRequest
|
||||
) = declineChatJoinRequest(chatJoinRequest)
|
||||
|
||||
suspend fun TelegramBot.declineChatJoinRequest(
|
||||
chatJoinRequestUpdate: ChatJoinRequestUpdate
|
||||
) = declineChatJoinRequest(chatJoinRequestUpdate.data)
|
@ -0,0 +1,38 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.invite_links
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
sealed interface ChatJoinRequestAnswer : SimpleRequest<Boolean> {
|
||||
val chatId: ChatIdentifier
|
||||
val userId: UserId
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class ApproveChatJoinRequest(
|
||||
override val chatId: ChatIdentifier,
|
||||
override val userId: UserId
|
||||
) : ChatJoinRequestAnswer {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "approveChatJoinRequest"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class DeclineChatJoinRequest(
|
||||
override val chatId: ChatIdentifier,
|
||||
override val userId: UserId
|
||||
) : ChatJoinRequestAnswer {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "declineChatJoinRequest"
|
||||
}
|
@ -13,6 +13,7 @@ const val UPDATE_POLL = "poll"
|
||||
const val UPDATE_POLL_ANSWER = "poll_answer"
|
||||
const val MY_CHAT_MEMBER = "my_chat_member"
|
||||
const val CHAT_MEMBER = "chat_member"
|
||||
const val CHAT_JOIN_REQUEST = "chat_join_request"
|
||||
|
||||
val ALL_UPDATES_LIST = listOf(
|
||||
UPDATE_MESSAGE,
|
||||
@ -27,5 +28,6 @@ val ALL_UPDATES_LIST = listOf(
|
||||
UPDATE_POLL,
|
||||
UPDATE_POLL_ANSWER,
|
||||
MY_CHAT_MEMBER,
|
||||
CHAT_MEMBER
|
||||
CHAT_MEMBER,
|
||||
CHAT_JOIN_REQUEST
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user