fixes in captcha related to expression

This commit is contained in:
InsanusMokrassar 2022-09-21 15:14:20 +06:00
parent c84cff9ddc
commit 7dead36cd9

View File

@ -8,6 +8,7 @@ import dev.inmo.plagubot.plugins.captcha.slotMachineReplyMarkup
import dev.inmo.tgbotapi.extensions.api.answers.answerCallbackQuery
import dev.inmo.tgbotapi.extensions.api.chat.members.*
import dev.inmo.tgbotapi.extensions.api.deleteMessage
import dev.inmo.tgbotapi.extensions.api.edit.edit
import dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup
import dev.inmo.tgbotapi.extensions.api.send.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
@ -397,29 +398,42 @@ data class ExpressionCaptchaProvider(
bold(callbackData.second)
}
suspend fun removeRedundantMessages() {
suspend fun removeRedundantMessages(removeSentMessage: Boolean = true) {
safelyWithoutExceptions {
if (removeSentMessage) {
deleteMessage(sentMessage)
}
}
}
var passed: Boolean? = null
val passedMutex = Mutex()
val callback: suspend (Boolean) -> Unit = {
passedMutex.withLock {
if (passed == null) {
removeRedundantMessages()
passed = it
runCatchingSafely<Unit> {
when {
it -> safelyWithoutExceptions {
it -> {
removeRedundantMessages()
safelyWithoutExceptions {
restrictChatMember(
chat,
user,
permissions = leftRestrictionsPermissions
)
}
kickOnUnsuccess -> banUser(chat, user, leftRestrictionsPermissions)
}
else -> {
removeRedundantMessages(removeSentMessage = false)
edit(sentMessage) {
+"User " + mention(user) + underline("didn't passed") + "captcha"
}
if (kickOnUnsuccess) {
banUser(chat, user, leftRestrictionsPermissions)
}
}
}
}
}
}