now on kicks will restrict users too

This commit is contained in:
InsanusMokrassar 2021-06-13 02:00:03 +06:00
parent 5e52e2c32e
commit 4a0e2cc843
2 changed files with 33 additions and 19 deletions

View File

@ -95,6 +95,7 @@ class CaptchaBotPlugin : Plugin {
}, },
includeFilterByChatInBehaviourSubContext = false includeFilterByChatInBehaviourSubContext = false
) { ) {
launchSafelyWithoutExceptions {
safelyWithoutExceptions { deleteMessage(it) } safelyWithoutExceptions { deleteMessage(it) }
val chat = it.chat.requireGroupChat() val chat = it.chat.requireGroupChat()
val newUsers = it.chatEvent.members val newUsers = it.chatEvent.members
@ -112,6 +113,7 @@ class CaptchaBotPlugin : Plugin {
} }
} }
} }
}
if (adminsAPI != null) { if (adminsAPI != null) {
onCommand(changeCaptchaMethodCommandRegex) { onCommand(changeCaptchaMethodCommandRegex) {

View File

@ -49,7 +49,8 @@ sealed class CaptchaProvider {
@Serializable @Serializable
data class SlotMachineCaptchaProvider( data class SlotMachineCaptchaProvider(
val checkTimeSeconds: Seconds = 300, val checkTimeSeconds: Seconds = 300,
val captchaText: String = "solve this captcha: " val captchaText: String = "solve this captcha: ",
val kick: Boolean = true
) : CaptchaProvider() { ) : CaptchaProvider() {
@Transient @Transient
private val checkTimeSpan = checkTimeSeconds.seconds private val checkTimeSpan = checkTimeSeconds.seconds
@ -119,7 +120,12 @@ data class SlotMachineCaptchaProvider(
subContexts.forEach { (context, user) -> subContexts.forEach { (context, user) ->
if (user !in authorizedUsers) { if (user !in authorizedUsers) {
context.stop() context.stop()
safelyWithoutExceptions { kickChatMember(chat, user) } if (kick) {
safelyWithoutExceptions {
restrictChatMember(chat, user, permissions = LeftRestrictionsChatPermissions)
kickChatMember(chat, user)
}
}
} }
} }
messagesToDelete.close() messagesToDelete.close()
@ -186,7 +192,10 @@ data class SimpleCaptchaProvider(
if (job.isActive) { if (job.isActive) {
job.cancel() job.cancel()
if (kick) { if (kick) {
safelyWithoutExceptions { kickChatMember(chat, it) } safelyWithoutExceptions {
restrictChatMember(chat, it, permissions = LeftRestrictionsChatPermissions)
kickChatMember(chat, it)
}
} }
} }
stop() stop()
@ -257,7 +266,7 @@ data class ExpressionCaptchaProvider(
newUsers: List<User> newUsers: List<User>
) { ) {
val userBanDateTime = eventDateTime + checkTimeSpan val userBanDateTime = eventDateTime + checkTimeSpan
newUsers.mapNotNull { user -> newUsers.map { user ->
launch { launch {
doInSubContext { doInSubContext {
val callbackData = ExpressionBuilder.createExpression( val callbackData = ExpressionBuilder.createExpression(
@ -302,7 +311,10 @@ data class ExpressionCaptchaProvider(
safelyWithoutExceptions { restrictChatMember(chat, user, permissions = LeftRestrictionsChatPermissions) } safelyWithoutExceptions { restrictChatMember(chat, user, permissions = LeftRestrictionsChatPermissions) }
} else { } else {
if (kick) { if (kick) {
safelyWithoutExceptions { kickChatMember(chat, user) } safelyWithoutExceptions {
restrictChatMember(chat, user, permissions = LeftRestrictionsChatPermissions)
kickChatMember(chat, user)
}
} }
} }
} }