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
) {
launchSafelyWithoutExceptions {
safelyWithoutExceptions { deleteMessage(it) }
val chat = it.chat.requireGroupChat()
val newUsers = it.chatEvent.members
@ -112,6 +113,7 @@ class CaptchaBotPlugin : Plugin {
}
}
}
}
if (adminsAPI != null) {
onCommand(changeCaptchaMethodCommandRegex) {

View File

@ -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<User>
) {
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)
}
}
}
}