mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
improve users shared DSLs
This commit is contained in:
parent
86c86dfb8a
commit
89524290c5
@ -17,12 +17,15 @@ import kotlinx.serialization.encoding.Encoder
|
|||||||
sealed interface KeyboardButtonRequestUsers {
|
sealed interface KeyboardButtonRequestUsers {
|
||||||
val requestId: RequestId
|
val requestId: RequestId
|
||||||
val isBot: Boolean?
|
val isBot: Boolean?
|
||||||
|
val isPremium: Boolean?
|
||||||
val maxCount: Int
|
val maxCount: Int
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Any(
|
data class Any(
|
||||||
@SerialName(requestIdField)
|
@SerialName(requestIdField)
|
||||||
override val requestId: RequestId,
|
override val requestId: RequestId,
|
||||||
|
@SerialName(userIsPremiumField)
|
||||||
|
override val isPremium: Boolean? = null,
|
||||||
@SerialName(maxQuantityField)
|
@SerialName(maxQuantityField)
|
||||||
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
) : KeyboardButtonRequestUsers {
|
) : KeyboardButtonRequestUsers {
|
||||||
@ -36,7 +39,7 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
@SerialName(requestIdField)
|
@SerialName(requestIdField)
|
||||||
override val requestId: RequestId,
|
override val requestId: RequestId,
|
||||||
@SerialName(userIsPremiumField)
|
@SerialName(userIsPremiumField)
|
||||||
val isPremium: Boolean? = null,
|
override val isPremium: Boolean? = null,
|
||||||
@SerialName(maxQuantityField)
|
@SerialName(maxQuantityField)
|
||||||
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
override val maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
) : KeyboardButtonRequestUsers {
|
) : KeyboardButtonRequestUsers {
|
||||||
@ -55,6 +58,8 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
@SerialName(userIsBotField)
|
@SerialName(userIsBotField)
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
override val isBot: Boolean = true
|
override val isBot: Boolean = true
|
||||||
|
override val isPremium: Boolean?
|
||||||
|
get() = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializer(KeyboardButtonRequestUsers::class)
|
@Serializer(KeyboardButtonRequestUsers::class)
|
||||||
@ -80,7 +85,7 @@ sealed interface KeyboardButtonRequestUsers {
|
|||||||
return when (surrogate.userIsBot) {
|
return when (surrogate.userIsBot) {
|
||||||
true -> Bot(surrogate.requestId, surrogate.maxCount)
|
true -> Bot(surrogate.requestId, surrogate.maxCount)
|
||||||
false -> Common(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
|
false -> Common(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
|
||||||
null -> Any(surrogate.requestId, surrogate.maxCount)
|
null -> Any(surrogate.requestId, surrogate.userIsPremium, surrogate.maxCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,10 @@ package dev.inmo.tgbotapi.types.buttons.reply
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.*
|
import dev.inmo.tgbotapi.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
|
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +57,7 @@ inline fun webAppReplyButton(
|
|||||||
/**
|
/**
|
||||||
* Creates [RequestUserKeyboardButton]
|
* Creates [RequestUserKeyboardButton]
|
||||||
*/
|
*/
|
||||||
inline fun requestUserReplyButton(
|
inline fun requestUsersReplyButton(
|
||||||
text: String,
|
text: String,
|
||||||
requestUser: KeyboardButtonRequestUsers
|
requestUser: KeyboardButtonRequestUsers
|
||||||
) = RequestUserKeyboardButton(
|
) = RequestUserKeyboardButton(
|
||||||
@ -63,15 +65,51 @@ inline fun requestUserReplyButton(
|
|||||||
requestUser
|
requestUser
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates [RequestUserKeyboardButton]
|
||||||
|
*/
|
||||||
|
@Deprecated("Renamed", ReplaceWith("requestUsersReplyButton(text, requestUser)", "dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton"))
|
||||||
|
inline fun requestUserReplyButton(
|
||||||
|
text: String,
|
||||||
|
requestUser: KeyboardButtonRequestUsers
|
||||||
|
) = requestUsersReplyButton(text, requestUser)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
||||||
*/
|
*/
|
||||||
|
inline fun requestBotsReplyButton(
|
||||||
|
text: String,
|
||||||
|
requestId: RequestId,
|
||||||
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
|
) = requestUsersReplyButton(
|
||||||
|
text,
|
||||||
|
KeyboardButtonRequestUsers.Bot(requestId, maxCount)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Bot]
|
||||||
|
*/
|
||||||
|
@Deprecated("Renamed", ReplaceWith("requestBotsReplyButton(text, requestId)", "dev.inmo.tgbotapi.types.buttons.reply.requestBotsReplyButton"))
|
||||||
inline fun requestBotReplyButton(
|
inline fun requestBotReplyButton(
|
||||||
text: String,
|
text: String,
|
||||||
requestId: RequestId
|
requestId: RequestId,
|
||||||
) = requestUserReplyButton(
|
) = requestBotsReplyButton(
|
||||||
text,
|
text,
|
||||||
KeyboardButtonRequestUsers.Bot(requestId)
|
requestId,
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Common]
|
||||||
|
*/
|
||||||
|
inline fun requestUsersReplyButton(
|
||||||
|
text: String,
|
||||||
|
requestId: RequestId,
|
||||||
|
premiumUser: Boolean? = null,
|
||||||
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
|
) = requestUsersReplyButton(
|
||||||
|
text,
|
||||||
|
KeyboardButtonRequestUsers.Common(requestId, premiumUser, maxCount)
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,10 +118,26 @@ inline fun requestBotReplyButton(
|
|||||||
inline fun requestUserReplyButton(
|
inline fun requestUserReplyButton(
|
||||||
text: String,
|
text: String,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
premiumUser: Boolean? = null
|
premiumUser: Boolean? = null,
|
||||||
) = requestUserReplyButton(
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
|
) = requestUsersReplyButton(
|
||||||
text,
|
text,
|
||||||
KeyboardButtonRequestUsers.Common(requestId, premiumUser)
|
requestId,
|
||||||
|
premiumUser,
|
||||||
|
maxCount
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates [RequestUserKeyboardButton] with [KeyboardButtonRequestUsers.Any]
|
||||||
|
*/
|
||||||
|
inline fun requestUsersOrBotsReplyButton(
|
||||||
|
text: String,
|
||||||
|
requestId: RequestId,
|
||||||
|
premiumUser: Boolean? = null,
|
||||||
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
|
) = requestUsersReplyButton(
|
||||||
|
text,
|
||||||
|
KeyboardButtonRequestUsers.Any(requestId, premiumUser, maxCount)
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons
|
|||||||
import dev.inmo.tgbotapi.types.buttons.*
|
import dev.inmo.tgbotapi.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
||||||
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
|
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
|
||||||
|
import dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
@ -142,7 +143,7 @@ inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
|||||||
text: String,
|
text: String,
|
||||||
requestUser: KeyboardButtonRequestUsers
|
requestUser: KeyboardButtonRequestUsers
|
||||||
) = add(
|
) = add(
|
||||||
requestUserReplyButton(
|
requestUsersReplyButton(
|
||||||
text,
|
text,
|
||||||
requestUser
|
requestUser
|
||||||
)
|
)
|
||||||
@ -169,7 +170,7 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
|||||||
inline fun ReplyKeyboardRowBuilder.requestBotsButton(
|
inline fun ReplyKeyboardRowBuilder.requestBotsButton(
|
||||||
text: String,
|
text: String,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
maxCount: Int
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
) = requestUsersButton(
|
) = requestUsersButton(
|
||||||
text,
|
text,
|
||||||
KeyboardButtonRequestUsers.Bot(requestId, maxCount)
|
KeyboardButtonRequestUsers.Bot(requestId, maxCount)
|
||||||
@ -200,7 +201,7 @@ inline fun ReplyKeyboardRowBuilder.requestUsersButton(
|
|||||||
text: String,
|
text: String,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
premiumUser: Boolean? = null,
|
premiumUser: Boolean? = null,
|
||||||
maxCount: Int
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
) = requestUsersButton(
|
) = requestUsersButton(
|
||||||
text,
|
text,
|
||||||
KeyboardButtonRequestUsers.Common(requestId, premiumUser, maxCount)
|
KeyboardButtonRequestUsers.Common(requestId, premiumUser, maxCount)
|
||||||
@ -227,10 +228,11 @@ inline fun ReplyKeyboardRowBuilder.requestUserButton(
|
|||||||
inline fun ReplyKeyboardRowBuilder.requestUsersOrBotsButton(
|
inline fun ReplyKeyboardRowBuilder.requestUsersOrBotsButton(
|
||||||
text: String,
|
text: String,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
maxCount: Int
|
premiumUser: Boolean? = null,
|
||||||
|
maxCount: Int = keyboardButtonRequestUserLimit.first
|
||||||
) = requestUsersButton(
|
) = requestUsersButton(
|
||||||
text,
|
text,
|
||||||
KeyboardButtonRequestUsers.Any(requestId, maxCount)
|
KeyboardButtonRequestUsers.Any(requestId, premiumUser, maxCount)
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user