Compare commits
3 Commits
43cdef96d0
...
e375170567
Author | SHA1 | Date |
---|---|---|
InsanusMokrassar | e375170567 | |
InsanusMokrassar | 8017678da8 | |
InsanusMokrassar | 317db251b9 |
|
@ -10,7 +10,7 @@ kotlin_serialisation_runtime_version=1.3.3
|
|||
plagubot_version=1.0.0
|
||||
|
||||
micro_utils_version=0.10.4
|
||||
tgbotapi_libraries_version=0.0.18
|
||||
tgbotapi_libraries_version=0.1.0
|
||||
|
||||
project_group=dev.inmo
|
||||
project_version=0.1.6
|
||||
|
|
|
@ -18,12 +18,13 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
|||
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
|
||||
import dev.inmo.tgbotapi.libraries.cache.admins.*
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.chat.RestrictionsChatPermissions
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedGroupChat
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
private const val enableAutoDeleteCommands = "captcha_auto_delete_commands_on"
|
||||
private const val disableAutoDeleteCommands = "captcha_auto_delete_commands_off"
|
||||
|
@ -46,59 +47,61 @@ private val changeCaptchaMethodCommandRegex = Regex(
|
|||
|
||||
@Serializable
|
||||
class CaptchaBotPlugin : Plugin {
|
||||
override suspend fun getCommands(): List<BotCommand> = listOf(
|
||||
BotCommand(
|
||||
enableAutoDeleteCommands,
|
||||
"Enable auto removing of commands addressed to captcha plugin"
|
||||
),
|
||||
BotCommand(
|
||||
disableAutoDeleteCommands,
|
||||
"Disable auto removing of commands addressed to captcha plugin"
|
||||
),
|
||||
BotCommand(
|
||||
enableAutoDeleteServiceMessages,
|
||||
"Enable auto removing of users joined messages"
|
||||
),
|
||||
BotCommand(
|
||||
disableAutoDeleteServiceMessages,
|
||||
"Disable auto removing of users joined messages"
|
||||
),
|
||||
BotCommand(
|
||||
enableSlotMachineCaptcha,
|
||||
"Change captcha method to slot machine"
|
||||
),
|
||||
BotCommand(
|
||||
enableSimpleCaptcha,
|
||||
"Change captcha method to simple button"
|
||||
),
|
||||
BotCommand(
|
||||
disableCaptcha,
|
||||
"Disable captcha for chat"
|
||||
),
|
||||
BotCommand(
|
||||
enableCaptcha,
|
||||
"Enable captcha for chat"
|
||||
),
|
||||
BotCommand(
|
||||
enableExpressionCaptcha,
|
||||
"Change captcha method to expressions"
|
||||
),
|
||||
BotCommand(
|
||||
enableKickOnUnsuccess,
|
||||
"Not solved captcha users will be kicked from the chat"
|
||||
),
|
||||
BotCommand(
|
||||
disableKickOnUnsuccess,
|
||||
"Not solved captcha users will NOT be kicked from the chat"
|
||||
)
|
||||
)
|
||||
// override suspend fun getCommands(): List<BotCommand> = listOf(
|
||||
// BotCommand(
|
||||
// enableAutoDeleteCommands,
|
||||
// "Enable auto removing of commands addressed to captcha plugin"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// disableAutoDeleteCommands,
|
||||
// "Disable auto removing of commands addressed to captcha plugin"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// enableAutoDeleteServiceMessages,
|
||||
// "Enable auto removing of users joined messages"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// disableAutoDeleteServiceMessages,
|
||||
// "Disable auto removing of users joined messages"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// enableSlotMachineCaptcha,
|
||||
// "Change captcha method to slot machine"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// enableSimpleCaptcha,
|
||||
// "Change captcha method to simple button"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// disableCaptcha,
|
||||
// "Disable captcha for chat"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// enableCaptcha,
|
||||
// "Enable captcha for chat"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// enableExpressionCaptcha,
|
||||
// "Change captcha method to expressions"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// enableKickOnUnsuccess,
|
||||
// "Not solved captcha users will be kicked from the chat"
|
||||
// ),
|
||||
// BotCommand(
|
||||
// disableKickOnUnsuccess,
|
||||
// "Not solved captcha users will NOT be kicked from the chat"
|
||||
// )
|
||||
// )
|
||||
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single { CaptchaChatsSettingsRepo(database) }
|
||||
}
|
||||
|
||||
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||
val repo: CaptchaChatsSettingsRepo by koin.inject()
|
||||
val adminsAPI = koin.adminsPlugin ?.adminsAPI(koin.get())
|
||||
|
||||
override suspend fun BehaviourContext.invoke(
|
||||
database: Database,
|
||||
params: Map<String, Any>
|
||||
) {
|
||||
val repo = CaptchaChatsSettingsRepo(database)
|
||||
val adminsAPI = params.adminsPlugin ?.adminsAPI(database)
|
||||
suspend fun Chat.settings() = repo.getById(id) ?: repo.create(ChatSettings(id)).first()
|
||||
|
||||
onNewChatMembers(
|
||||
|
@ -127,7 +130,7 @@ class CaptchaBotPlugin : Plugin {
|
|||
}
|
||||
val defaultChatPermissions = (getChat(it.chat) as ExtendedGroupChat).permissions
|
||||
|
||||
doInSubContext(stopOnCompletion = false) {
|
||||
createSubContextAndDoWithUpdatesFilter(stopOnCompletion = false) {
|
||||
launch {
|
||||
settings.captchaProvider.apply { doAction(it.date, chat, newUsers, defaultChatPermissions) }
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ import dev.inmo.tgbotapi.extensions.utils.shortcuts.executeUnsafe
|
|||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.requests.DeleteMessage
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.mention
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
||||
import dev.inmo.tgbotapi.types.chat.LeftRestrictionsChatPermissions
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.textsources.mention
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.toList
|
||||
|
@ -94,12 +94,12 @@ data class SlotMachineCaptchaProvider(
|
|||
val authorized = Channel<User>(newUsers.size)
|
||||
val messagesToDelete = Channel<Message>(Channel.UNLIMITED)
|
||||
val subContexts = newUsers.map {
|
||||
doInSubContext(stopOnCompletion = false) {
|
||||
createSubContextAndDoWithUpdatesFilter (stopOnCompletion = false) {
|
||||
val sentMessage = sendTextMessage(
|
||||
chat,
|
||||
buildEntities {
|
||||
+it.mention(it.firstName)
|
||||
regular(", ${captchaText}")
|
||||
regular(", $captchaText")
|
||||
}
|
||||
).also { messagesToDelete.send(it) }
|
||||
val sentDice = sendDice(
|
||||
|
@ -182,7 +182,7 @@ data class SimpleCaptchaProvider(
|
|||
newUsers.mapNotNull {
|
||||
safelyWithoutExceptions {
|
||||
launch {
|
||||
doInSubContext(stopOnCompletion = false) {
|
||||
createSubContextAndDoWithUpdatesFilter(stopOnCompletion = false) {
|
||||
val callbackData = uuid4().toString()
|
||||
val sentMessage = sendTextMessage(
|
||||
chat,
|
||||
|
@ -294,7 +294,7 @@ data class ExpressionCaptchaProvider(
|
|||
val userBanDateTime = eventDateTime + checkTimeSpan
|
||||
newUsers.map { user ->
|
||||
launch {
|
||||
doInSubContext {
|
||||
createSubContextAndDoWithUpdatesFilter {
|
||||
val callbackData = ExpressionBuilder.createExpression(
|
||||
maxPerNumber,
|
||||
operations
|
||||
|
|
Loading…
Reference in New Issue