From d8dbb2512fd0421c5dfb299ebe80ca0268f6b2d2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 31 Jul 2022 00:35:05 +0600 Subject: [PATCH] fixes --- .../captcha/SlotMachineAnswersMarkup.kt | 10 ++++-- .../captcha/provider/CaptchaProvider.kt | 33 +++++++++---------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/SlotMachineAnswersMarkup.kt b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/SlotMachineAnswersMarkup.kt index a0e9e6b..cea7c2a 100644 --- a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/SlotMachineAnswersMarkup.kt +++ b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/SlotMachineAnswersMarkup.kt @@ -1,6 +1,7 @@ package dev.inmo.plagubot.plugins.captcha import dev.inmo.tgbotapi.extensions.utils.SlotMachineReelImage +import dev.inmo.tgbotapi.extensions.utils.types.buttons.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -23,7 +24,10 @@ fun slotMachineReplyMarkup( } else -> listOf(CallbackDataInlineKeyboardButton("$first$second$third", "$first$second$third")) } - return InlineKeyboardMarkup( - texts.chunked(2) - ) + return inlineKeyboard { + texts.chunked(2).forEach { add(it) } +// row { +// dataButton("Cancel (Admins only)", "cancel") +// } + } } diff --git a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/provider/CaptchaProvider.kt b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/provider/CaptchaProvider.kt index 4b549d6..8e04391 100644 --- a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/provider/CaptchaProvider.kt +++ b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/provider/CaptchaProvider.kt @@ -146,18 +146,20 @@ data class SlotMachineCaptchaProvider( val clicked = arrayOf(null, null, null) while (leftToClick.isNotEmpty()) { val userClicked = waitMessageDataCallbackQuery().filter { it.user.id == user.id && it.message.messageId == sentDice.messageId }.first() - if (userClicked.data == leftToClick.first()) { - clicked[3 - leftToClick.size] = leftToClick.removeAt(0) - if (clicked.contains(null)) { - safelyWithoutExceptions { answerCallbackQuery(userClicked, "Ok, next one") } - editMessageReplyMarkup(sentDice, slotMachineReplyMarkup(clicked[0], clicked[1], clicked[2])) - } else { - safelyWithoutExceptions { answerCallbackQuery(userClicked, "Thank you and welcome", showAlert = true) } - safelyWithoutExceptions { deleteMessage(sentMessage) } - safelyWithoutExceptions { deleteMessage(sentDice) } + + when { + userClicked.data == leftToClick.first() -> { + clicked[3 - leftToClick.size] = leftToClick.removeAt(0) + if (clicked.contains(null)) { + safelyWithoutExceptions { answerCallbackQuery(userClicked, "Ok, next one") } + editMessageReplyMarkup(sentDice, slotMachineReplyMarkup(clicked[0], clicked[1], clicked[2])) + } else { + safelyWithoutExceptions { answerCallbackQuery(userClicked, "Thank you and welcome", showAlert = true) } + safelyWithoutExceptions { deleteMessage(sentMessage) } + safelyWithoutExceptions { deleteMessage(sentDice) } + } } - } else { - safelyWithoutExceptions { answerCallbackQuery(userClicked, "Nope") } + else -> safelyWithoutExceptions { answerCallbackQuery(userClicked, "Nope") } } } authorized.send(user) @@ -378,12 +380,9 @@ data class ExpressionCaptchaProvider( if (passed == null) { removeRedundantMessages() passed = it - if (it) { - safelyWithoutExceptions { restrictChatMember(chat, user, permissions = leftRestrictionsPermissions) } - } else { - if (kickOnUnsuccess) { - banUser(chat, user, leftRestrictionsPermissions) - } + when { + it -> safelyWithoutExceptions { restrictChatMember(chat, user, permissions = leftRestrictionsPermissions) } + kickOnUnsuccess -> banUser(chat, user, leftRestrictionsPermissions) } } }