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.channels.Channel
|
||||
import kotlinx.coroutines.channels.toList
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import kotlin.random.Random
|
||||
@ -256,7 +258,6 @@ data class ExpressionCaptchaProvider(
|
||||
) {
|
||||
val userBanDateTime = eventDateTime + checkTimeSpan
|
||||
newUsers.mapNotNull { user ->
|
||||
safelyWithoutExceptions {
|
||||
launch {
|
||||
doInSubContext {
|
||||
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 = {
|
||||
passedMutex.withLock {
|
||||
if (passed == null) {
|
||||
removeRedundantMessages()
|
||||
passed = 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
|
||||
waitDataCallbackQuery {
|
||||
when {
|
||||
@ -313,7 +327,7 @@ data class ExpressionCaptchaProvider(
|
||||
if (leftAttempts < 1) {
|
||||
this
|
||||
} else {
|
||||
launch { answerCallbackQuery(this@waitDataCallbackQuery, leftRetriesText + leftAttempts) }
|
||||
answerCallbackQuery(this@waitDataCallbackQuery, leftRetriesText + leftAttempts)
|
||||
null
|
||||
}
|
||||
}
|
||||
@ -321,15 +335,10 @@ data class ExpressionCaptchaProvider(
|
||||
}
|
||||
}.first()
|
||||
|
||||
banJob.cancel()
|
||||
|
||||
callback(leftAttempts > 0)
|
||||
}
|
||||
|
||||
delay((userBanDateTime - eventDateTime).millisecondsLong)
|
||||
|
||||
if (job.isActive) job.cancel()
|
||||
callback(passed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.joinAll()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user