mirror of
https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin.git
synced 2024-11-25 11:38:55 +00:00
updates
This commit is contained in:
parent
338e97770d
commit
6fe5f96e4e
@ -31,6 +31,8 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
|
|||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.channels.toList
|
import kotlinx.coroutines.channels.toList
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
@ -256,7 +258,6 @@ data class ExpressionCaptchaProvider(
|
|||||||
) {
|
) {
|
||||||
val userBanDateTime = eventDateTime + checkTimeSpan
|
val userBanDateTime = eventDateTime + checkTimeSpan
|
||||||
newUsers.mapNotNull { user ->
|
newUsers.mapNotNull { user ->
|
||||||
safelyWithoutExceptions {
|
|
||||||
launch {
|
launch {
|
||||||
doInSubContext {
|
doInSubContext {
|
||||||
val callbackData = ExpressionBuilder.createExpression(
|
val callbackData = ExpressionBuilder.createExpression(
|
||||||
@ -290,8 +291,11 @@ data class ExpressionCaptchaProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var passed = true
|
var passed: Boolean? = null
|
||||||
|
val passedMutex = Mutex()
|
||||||
val callback: suspend (Boolean) -> Unit = {
|
val callback: suspend (Boolean) -> Unit = {
|
||||||
|
passedMutex.withLock {
|
||||||
|
if (passed == null) {
|
||||||
removeRedundantMessages()
|
removeRedundantMessages()
|
||||||
passed = it
|
passed = it
|
||||||
if (it) {
|
if (it) {
|
||||||
@ -302,8 +306,18 @@ data class ExpressionCaptchaProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val banJob = launch {
|
||||||
|
delay((userBanDateTime - eventDateTime).millisecondsLong)
|
||||||
|
|
||||||
|
if (passed == null) {
|
||||||
|
callback(false)
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val job = parallel {
|
|
||||||
var leftAttempts = attempts
|
var leftAttempts = attempts
|
||||||
waitDataCallbackQuery {
|
waitDataCallbackQuery {
|
||||||
when {
|
when {
|
||||||
@ -313,7 +327,7 @@ data class ExpressionCaptchaProvider(
|
|||||||
if (leftAttempts < 1) {
|
if (leftAttempts < 1) {
|
||||||
this
|
this
|
||||||
} else {
|
} else {
|
||||||
launch { answerCallbackQuery(this@waitDataCallbackQuery, leftRetriesText + leftAttempts) }
|
answerCallbackQuery(this@waitDataCallbackQuery, leftRetriesText + leftAttempts)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,15 +335,10 @@ data class ExpressionCaptchaProvider(
|
|||||||
}
|
}
|
||||||
}.first()
|
}.first()
|
||||||
|
|
||||||
|
banJob.cancel()
|
||||||
|
|
||||||
callback(leftAttempts > 0)
|
callback(leftAttempts > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
delay((userBanDateTime - eventDateTime).millisecondsLong)
|
|
||||||
|
|
||||||
if (job.isActive) job.cancel()
|
|
||||||
callback(passed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.joinAll()
|
}.joinAll()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user