improvements in users requests

This commit is contained in:
InsanusMokrassar 2024-01-10 23:10:28 +06:00
parent 984ffb8bae
commit 6a04b3980c

View File

@ -7,14 +7,11 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPoll
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared
import dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUsersShared
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestBotButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestChatButton
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestGroupButton
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestUserButton
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestUserOrBotButton
import dev.inmo.tgbotapi.types.BotCommand import dev.inmo.tgbotapi.types.BotCommand
import dev.inmo.tgbotapi.types.chat.PrivateChat import dev.inmo.tgbotapi.types.chat.PrivateChat
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
import dev.inmo.tgbotapi.types.message.textsources.mention import dev.inmo.tgbotapi.types.message.textsources.mention
import dev.inmo.tgbotapi.types.request.RequestId import dev.inmo.tgbotapi.types.request.RequestId
import dev.inmo.tgbotapi.utils.row import dev.inmo.tgbotapi.utils.row
@ -50,30 +47,35 @@ suspend fun main(args: Array<String>) {
resizeKeyboard = true, resizeKeyboard = true,
) { ) {
row { row {
requestUserOrBotButton( requestUsersOrBotsButton(
"\uD83D\uDC64/\uD83E\uDD16", "\uD83D\uDC64/\uD83E\uDD16",
requestIdUserOrBot requestIdUserOrBot,
maxCount = keyboardButtonRequestUserLimit.last
) )
} }
row { row {
requestUserButton( requestUsersButton(
"\uD83D\uDC64", "\uD83D\uDC64",
requestIdUserNonPremium, requestIdUserNonPremium,
premiumUser = false premiumUser = false,
maxCount = keyboardButtonRequestUserLimit.last
) )
requestUserButton( requestUsersButton(
"\uD83D\uDC64", "\uD83D\uDC64",
requestIdUserAny, requestIdUserAny,
premiumUser = null premiumUser = null,
maxCount = keyboardButtonRequestUserLimit.last
) )
requestUserButton( requestUsersButton(
"\uD83D\uDC64", "\uD83D\uDC64",
requestIdUserPremium, requestIdUserPremium,
premiumUser = true premiumUser = true,
maxCount = keyboardButtonRequestUserLimit.last
) )
requestBotButton( requestBotsButton(
"\uD83E\uDD16", "\uD83E\uDD16",
requestIdBot requestIdBot,
maxCount = keyboardButtonRequestUserLimit.last
) )
} }
row { row {
@ -164,25 +166,26 @@ suspend fun main(args: Array<String>) {
) )
} }
onUserShared { onUsersShared {
val userId = it.chatEvent.userId it.chatEvent.userIds.forEach { userId ->
val userInfo = runCatchingSafely { getChat(userId) }.getOrNull() val userInfo = runCatchingSafely { getChat(userId) }.getOrNull()
reply( reply(
it, it,
) { ) {
+"You have shared " +"You have shared "
+mention( +mention(
when (it.chatEvent.requestId) { when (it.chatEvent.requestId) {
requestIdUserOrBot -> "user or bot" requestIdUserOrBot -> "user or bot"
requestIdUserNonPremium -> "non premium user" requestIdUserNonPremium -> "non premium user"
requestIdUserAny -> "any user" requestIdUserAny -> "any user"
requestIdUserPremium -> "premium user" requestIdUserPremium -> "premium user"
requestIdBot -> "bot" requestIdBot -> "bot"
else -> "somebody O.o" else -> "somebody O.o"
}, },
userId userId
) )
+" (user info: $userInfo; user id: $userId)" +" (user info: $userInfo; user id: $userId)"
}
} }
} }