mirror of
https://github.com/InsanusMokrassar/CaptchaPlaguBotPlugin.git
synced 2024-11-24 19:18:51 +00:00
actualize
This commit is contained in:
parent
23af90137e
commit
19afa7c5aa
@ -23,8 +23,7 @@ import dev.inmo.tgbotapi.extensions.utils.*
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities
|
import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.regular
|
import dev.inmo.tgbotapi.extensions.utils.formatting.regular
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe
|
||||||
import dev.inmo.tgbotapi.libraries.cache.admins.AdminsCacheAPI
|
import dev.inmo.tgbotapi.libraries.cache.admins.*
|
||||||
import dev.inmo.tgbotapi.libraries.cache.admins.adminsPlugin
|
|
||||||
import dev.inmo.tgbotapi.requests.DeleteMessage
|
import dev.inmo.tgbotapi.requests.DeleteMessage
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.mention
|
import dev.inmo.tgbotapi.types.MessageEntity.textsources.mention
|
||||||
@ -45,12 +44,6 @@ import org.jetbrains.exposed.sql.Database
|
|||||||
private const val enableAutoDeleteCommands = "captcha_auto_delete_commands_on"
|
private const val enableAutoDeleteCommands = "captcha_auto_delete_commands_on"
|
||||||
private const val disableAutoDeleteCommands = "captcha_auto_delete_commands_off"
|
private const val disableAutoDeleteCommands = "captcha_auto_delete_commands_off"
|
||||||
|
|
||||||
private suspend fun AdminsCacheAPI.verifyMessageFromAdmin(message: CommonMessage<*>) = when (message) {
|
|
||||||
is CommonGroupContentMessage<*> -> getChatAdmins(message.chat.id) ?.any { it.user.id == message.user.id } == true
|
|
||||||
is AnonymousGroupContentMessage<*> -> true
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class CaptchaBotPlugin : Plugin {
|
class CaptchaBotPlugin : Plugin {
|
||||||
override suspend fun getCommands(): List<BotCommand> = listOf(
|
override suspend fun getCommands(): List<BotCommand> = listOf(
|
||||||
@ -160,21 +153,11 @@ class CaptchaBotPlugin : Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (adminsAPI != null) {
|
if (adminsAPI != null) {
|
||||||
suspend fun <T : MessageContent> CommonMessage<T>.doAfterVerification(block: suspend () -> Unit) {
|
|
||||||
val chat = chat
|
|
||||||
|
|
||||||
if (chat is PublicChat) {
|
|
||||||
val verified = adminsAPI.verifyMessageFromAdmin(this)
|
|
||||||
if (verified) {
|
|
||||||
block()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onCommand(
|
onCommand(
|
||||||
enableAutoDeleteCommands,
|
enableAutoDeleteCommands,
|
||||||
requireOnlyCommandInMessage = false
|
requireOnlyCommandInMessage = false
|
||||||
) { message ->
|
) { message ->
|
||||||
message.doAfterVerification {
|
message.doAfterVerification(adminsAPI) {
|
||||||
val settings = message.chat.settings()
|
val settings = message.chat.settings()
|
||||||
|
|
||||||
repo.update(
|
repo.update(
|
||||||
@ -189,7 +172,7 @@ class CaptchaBotPlugin : Plugin {
|
|||||||
disableAutoDeleteCommands,
|
disableAutoDeleteCommands,
|
||||||
requireOnlyCommandInMessage = false
|
requireOnlyCommandInMessage = false
|
||||||
) { message ->
|
) { message ->
|
||||||
message.doAfterVerification {
|
message.doAfterVerification(adminsAPI) {
|
||||||
val settings = message.chat.settings()
|
val settings = message.chat.settings()
|
||||||
|
|
||||||
repo.update(
|
repo.update(
|
||||||
|
Loading…
Reference in New Issue
Block a user