diff --git a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/Plugin.kt b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/Plugin.kt index 055fad3..2b9ad84 100644 --- a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/Plugin.kt +++ b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/Plugin.kt @@ -95,20 +95,22 @@ class CaptchaBotPlugin : Plugin { }, includeFilterByChatInBehaviourSubContext = false ) { - safelyWithoutExceptions { deleteMessage(it) } - val chat = it.chat.requireGroupChat() - val newUsers = it.chatEvent.members - newUsers.forEach { user -> - restrictChatMember( - chat, - user, - permissions = ChatPermissions() - ) - } - val settings = it.chat.settings() - doInSubContext(stopOnCompletion = false) { - launch { - settings.captchaProvider.apply { doAction(it.date, chat, newUsers) } + launchSafelyWithoutExceptions { + safelyWithoutExceptions { deleteMessage(it) } + val chat = it.chat.requireGroupChat() + val newUsers = it.chatEvent.members + newUsers.forEach { user -> + restrictChatMember( + chat, + user, + permissions = ChatPermissions() + ) + } + val settings = it.chat.settings() + doInSubContext(stopOnCompletion = false) { + launch { + settings.captchaProvider.apply { doAction(it.date, chat, newUsers) } + } } } } 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 2b1533a..b508bfa 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 @@ -49,7 +49,8 @@ sealed class CaptchaProvider { @Serializable data class SlotMachineCaptchaProvider( val checkTimeSeconds: Seconds = 300, - val captchaText: String = "solve this captcha: " + val captchaText: String = "solve this captcha: ", + val kick: Boolean = true ) : CaptchaProvider() { @Transient private val checkTimeSpan = checkTimeSeconds.seconds @@ -119,7 +120,12 @@ data class SlotMachineCaptchaProvider( subContexts.forEach { (context, user) -> if (user !in authorizedUsers) { context.stop() - safelyWithoutExceptions { kickChatMember(chat, user) } + if (kick) { + safelyWithoutExceptions { + restrictChatMember(chat, user, permissions = LeftRestrictionsChatPermissions) + kickChatMember(chat, user) + } + } } } messagesToDelete.close() @@ -186,7 +192,10 @@ data class SimpleCaptchaProvider( if (job.isActive) { job.cancel() if (kick) { - safelyWithoutExceptions { kickChatMember(chat, it) } + safelyWithoutExceptions { + restrictChatMember(chat, it, permissions = LeftRestrictionsChatPermissions) + kickChatMember(chat, it) + } } } stop() @@ -257,7 +266,7 @@ data class ExpressionCaptchaProvider( newUsers: List ) { val userBanDateTime = eventDateTime + checkTimeSpan - newUsers.mapNotNull { user -> + newUsers.map { user -> launch { doInSubContext { val callbackData = ExpressionBuilder.createExpression( @@ -302,7 +311,10 @@ data class ExpressionCaptchaProvider( safelyWithoutExceptions { restrictChatMember(chat, user, permissions = LeftRestrictionsChatPermissions) } } else { if (kick) { - safelyWithoutExceptions { kickChatMember(chat, user) } + safelyWithoutExceptions { + restrictChatMember(chat, user, permissions = LeftRestrictionsChatPermissions) + kickChatMember(chat, user) + } } } }