mirror of
https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin.git
synced 2024-11-25 11:38:55 +00:00
now on kicks will restrict users too
This commit is contained in:
parent
5e52e2c32e
commit
4a0e2cc843
@ -95,20 +95,22 @@ class CaptchaBotPlugin : Plugin {
|
|||||||
},
|
},
|
||||||
includeFilterByChatInBehaviourSubContext = false
|
includeFilterByChatInBehaviourSubContext = false
|
||||||
) {
|
) {
|
||||||
safelyWithoutExceptions { deleteMessage(it) }
|
launchSafelyWithoutExceptions {
|
||||||
val chat = it.chat.requireGroupChat()
|
safelyWithoutExceptions { deleteMessage(it) }
|
||||||
val newUsers = it.chatEvent.members
|
val chat = it.chat.requireGroupChat()
|
||||||
newUsers.forEach { user ->
|
val newUsers = it.chatEvent.members
|
||||||
restrictChatMember(
|
newUsers.forEach { user ->
|
||||||
chat,
|
restrictChatMember(
|
||||||
user,
|
chat,
|
||||||
permissions = ChatPermissions()
|
user,
|
||||||
)
|
permissions = ChatPermissions()
|
||||||
}
|
)
|
||||||
val settings = it.chat.settings()
|
}
|
||||||
doInSubContext(stopOnCompletion = false) {
|
val settings = it.chat.settings()
|
||||||
launch {
|
doInSubContext(stopOnCompletion = false) {
|
||||||
settings.captchaProvider.apply { doAction(it.date, chat, newUsers) }
|
launch {
|
||||||
|
settings.captchaProvider.apply { doAction(it.date, chat, newUsers) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user