Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 0.25.0

* `Versions`:
* `Kotlin`: `2.3.10`
* `Serialization`: `1.10.0`
* `PlaguBot`: `11.0.0`
* `KSLog`: `1.6.0`
* `MicroUtils`: `0.29.1`
* `TelegramBotAPILibraries`: `0.29.0`

## 0.24.7

* `Versions`:
Expand Down
8 changes: 4 additions & 4 deletions bans/src/main/kotlin/BanPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dev.inmo.micro_utils.common.mapOnFirst
import dev.inmo.micro_utils.common.mapOnSecond
import dev.inmo.micro_utils.common.onFirst
import dev.inmo.micro_utils.common.onSecond
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.micro_utils.coroutines.runCatchingLogging
import dev.inmo.micro_utils.koin.singleWithBinds
import dev.inmo.micro_utils.repos.add
import dev.inmo.micro_utils.repos.set
Expand Down Expand Up @@ -202,7 +202,7 @@ class BanPlugin : Plugin {
if (warnings >= chatSettings.warningsUntilBan) {
when {
userInReply != null -> {
val banned = runCatchingSafely {
val banned = runCatchingLogging {
banChatMember(commandMessage.chat, userInReply)
}.isSuccess
reply(
Expand All @@ -215,7 +215,7 @@ class BanPlugin : Plugin {
}
}
channelInReply != null -> {
val banned = runCatchingSafely {
val banned = runCatchingLogging {
banChatSenderChat(commandMessage.chat, channelInReply.id)
}.isSuccess
reply(
Expand Down Expand Up @@ -378,7 +378,7 @@ class BanPlugin : Plugin {
}.either()


val banned = runCatchingSafely {
val banned = runCatchingLogging {
userInReply.onFirst {
banChatMember(commandMessage.chat, it.id)
}.onSecond {
Expand Down
6 changes: 3 additions & 3 deletions bans/src/main/kotlin/InlineButtonsDrawer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.inmo.plagubot.plugins.bans

import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.micro_utils.coroutines.runCatchingLogging
import dev.inmo.micro_utils.repos.set
import dev.inmo.plagubot.plugins.bans.db.ChatsSettingsTable
import dev.inmo.plagubot.plugins.bans.models.ChatSettings
Expand Down Expand Up @@ -145,7 +145,7 @@ internal class BansInlineButtonsDrawer(
reply(query.message, "Updated")
}

runCatchingSafely { drawInlineButtons(chatId, query.user.id, query.message.messageId, InlineButtonsKeys.Settings) }
runCatchingLogging { drawInlineButtons(chatId, query.user.id, query.message.messageId, InlineButtonsKeys.Settings) }

answer(query)

Expand All @@ -165,7 +165,7 @@ internal class BansInlineButtonsDrawer(
return
}

runCatchingSafely {
runCatchingLogging {
editMessageReplyMarkup(
userId,
messageId,
Expand Down
18 changes: 9 additions & 9 deletions bans/src/main/kotlin/db/ChatsSettingsTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import dev.inmo.plagubot.plugins.bans.utils.banPluginSerialFormat
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.RawChatId
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.ISqlExpressionBuilder
import org.jetbrains.exposed.sql.Op
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.statements.InsertStatement
import org.jetbrains.exposed.sql.statements.UpdateBuilder
import org.jetbrains.exposed.v1.core.Op
import org.jetbrains.exposed.v1.core.ResultRow
import org.jetbrains.exposed.v1.core.and
import org.jetbrains.exposed.v1.core.eq
import org.jetbrains.exposed.v1.core.isNull
import org.jetbrains.exposed.v1.core.statements.UpdateBuilder
import org.jetbrains.exposed.v1.jdbc.Database

internal typealias ChatsSettingsTable = KeyValueRepo<IdChatIdentifier, ChatSettings>

Expand All @@ -27,10 +27,10 @@ private class ExposedChatsSettingsTable(
override val keyColumn = long("chatId")
private val threadIdColumn = long("threadId").nullable().default(null)
private val chatSettingsColumn = text("userId")
override val selectById: ISqlExpressionBuilder.(IdChatIdentifier) -> Op<Boolean> = {
override val selectById: (IdChatIdentifier) -> Op<Boolean> = {
keyColumn.eq(it.chatId.long).and(it.threadId ?.long ?.let { threadIdColumn.eq(it) } ?: threadIdColumn.isNull())
}
override val selectByValue: ISqlExpressionBuilder.(ChatSettings) -> Op<Boolean> = {
override val selectByValue: (ChatSettings) -> Op<Boolean> = {
chatSettingsColumn.eq(banPluginSerialFormat.encodeToString(ChatSettings.serializer(), it))
}
override val ResultRow.asKey: IdChatIdentifier
Expand Down
4 changes: 1 addition & 3 deletions bans/src/main/kotlin/db/WarningsTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import dev.inmo.micro_utils.repos.mappers.withMapper
import dev.inmo.plagubot.plugins.bans.utils.banPluginSerialFormat
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.v1.jdbc.Database

internal val Database.warningsTable: WarningsTable
get() = ExposedKeyValuesRepo(
Expand Down
2 changes: 0 additions & 2 deletions bans/src/main/kotlin/models/WorkMode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import kotlinx.serialization.modules.polymorphic

@Serializable
sealed interface WorkMode {
@Serializable
sealed interface EnabledForAdmins : WorkMode {
@Serializable
companion object Default : EnabledForAdmins
}
@Serializable
sealed interface EnabledForUsers : WorkMode {
@Serializable
companion object Default : EnabledForUsers
Expand Down
25 changes: 12 additions & 13 deletions captcha/src/main/kotlin/Plugin.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.inmo.plagubot.plugins.captcha

import com.benasher44.uuid.uuid4
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
import dev.inmo.micro_utils.coroutines.runCatchingLogging
import dev.inmo.micro_utils.koin.singleWithRandomQualifier
import dev.inmo.micro_utils.repos.create
import dev.inmo.plagubot.Plugin
Expand Down Expand Up @@ -198,7 +197,7 @@ class CaptchaBotPlugin : Plugin {
val settings = chat.settings()
if (!settings.enabled) return

safelyWithoutExceptions {
runCatching {
if (settings.autoRemoveEvents && msg != null) {
deleteMessage(msg)
}
Expand All @@ -218,7 +217,7 @@ class CaptchaBotPlugin : Plugin {
newUsers = if (settings.casEnabled) {
newUsers.filterNot { user ->
casChecker.isBanned(user.id).also { isBanned ->
runCatchingSafely {
runCatchingLogging {
if (isBanned) {
val entities = buildEntities {
+"User " + mention(user) + " is banned in " + link("CAS System", "https://cas.chat/query?u=${user.id.chatId}")
Expand All @@ -229,7 +228,7 @@ class CaptchaBotPlugin : Plugin {
} ?: send(chat, entities)

when {
joinRequest -> runCatchingSafely { declineChatJoinRequest(chat.id, user.id) }
joinRequest -> runCatchingLogging { declineChatJoinRequest(chat.id, user.id) }
settings.kickOnUnsuccess -> banChatMember(chat.id, user)
}
}
Expand All @@ -244,7 +243,7 @@ class CaptchaBotPlugin : Plugin {
newUsers.filterNot { user ->
usersPassInfoRepo.havePassedChats(user.id, settings.captchaProvider.complexity).also {
if (it) {
runCatchingSafely {
runCatchingLogging {
val entities = buildEntities {
+"User " + mention(user) + " has passed captcha earlier. Captcha has been cancelled"
}
Expand All @@ -254,7 +253,7 @@ class CaptchaBotPlugin : Plugin {
} ?: send(chat, entities)

when {
joinRequest -> runCatchingSafely { approveChatJoinRequest(chat.id, user.id) }
joinRequest -> runCatchingLogging { approveChatJoinRequest(chat.id, user.id) }
else -> restrictChatMember(chat.id, user, permissions = defaultChatPermissions)
}
}
Expand Down Expand Up @@ -315,7 +314,7 @@ class CaptchaBotPlugin : Plugin {
it.doAfterVerification(adminsAPI) {
val settings = it.chat.settings()
if (settings.autoRemoveCommands) {
safelyWithoutExceptions { deleteMessage(it) }
runCatching { deleteMessage(it) }
}
val commands = it.parseCommandsWithArgs()
val changeCommand = commands.keys.first {
Expand Down Expand Up @@ -452,7 +451,7 @@ class CaptchaBotPlugin : Plugin {
)

reply(message, "Ok, new users didn't pass captcha will be kicked").apply {
launchSafelyWithoutExceptions {
launchLoggingDropExceptions {
delay(5000L)
delete(this@apply)
}
Expand All @@ -474,7 +473,7 @@ class CaptchaBotPlugin : Plugin {
)

reply(message, "Ok, new users didn't passed captcha will NOT be kicked").apply {
launchSafelyWithoutExceptions {
launchLoggingDropExceptions {
delay(5000L)
delete(this@apply)
}
Expand All @@ -496,7 +495,7 @@ class CaptchaBotPlugin : Plugin {
)

reply(message, "Ok, CAS banned user will automatically fail captcha").apply {
launchSafelyWithoutExceptions {
launchLoggingDropExceptions {
delay(5000L)
delete(this@apply)
}
Expand All @@ -518,7 +517,7 @@ class CaptchaBotPlugin : Plugin {
)

reply(message, "Ok, CAS banned user will NOT automatically fail captcha").apply {
launchSafelyWithoutExceptions {
launchLoggingDropExceptions {
delay(5000L)
delete(this@apply)
}
Expand Down
21 changes: 11 additions & 10 deletions captcha/src/main/kotlin/db/CaptchaChatsSettingsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.RawChatId
import dev.inmo.tgbotapi.types.toChatId
import kotlinx.serialization.json.Json
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.ISqlExpressionBuilder
import org.jetbrains.exposed.sql.Op
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.statements.InsertStatement
import org.jetbrains.exposed.sql.statements.UpdateBuilder
import org.jetbrains.exposed.v1.core.Op
import org.jetbrains.exposed.v1.core.ResultRow
import org.jetbrains.exposed.v1.core.and
import org.jetbrains.exposed.v1.core.eq
import org.jetbrains.exposed.v1.core.isNull
import org.jetbrains.exposed.v1.core.or
import org.jetbrains.exposed.v1.core.statements.InsertStatement
import org.jetbrains.exposed.v1.core.statements.UpdateBuilder
import org.jetbrains.exposed.v1.jdbc.Database

private val captchaProviderSerialFormat = Json {
ignoreUnknownKeys = true
Expand Down Expand Up @@ -45,7 +46,7 @@ class CaptchaChatsSettingsRepo(

override val primaryKey = PrimaryKey(chatIdColumn)

override val selectByIds: ISqlExpressionBuilder.(List<IdChatIdentifier>) -> Op<Boolean> = {
override val selectByIds: (List<IdChatIdentifier>) -> Op<Boolean> = {
fun IdChatIdentifier.createEq() = chatIdColumn.eq(chatId.long).and(
threadId ?.let { threadIdColumn.eq(it.long) } ?: threadIdColumn.isNull()
)
Expand Down Expand Up @@ -85,7 +86,7 @@ class CaptchaChatsSettingsRepo(
autoPassKnown = get(autoPassKnownColumn),
)

override val selectById: ISqlExpressionBuilder.(IdChatIdentifier) -> Op<Boolean> = { chatIdColumn.eq(it.chatId.long) }
override val selectById: (IdChatIdentifier) -> Op<Boolean> = { chatIdColumn.eq(it.chatId.long) }
override val ResultRow.asObject: ChatSettings
get() = ChatSettings(
chatId = asId,
Expand Down
23 changes: 11 additions & 12 deletions captcha/src/main/kotlin/db/UsersPassInfoRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import dev.inmo.tgbotapi.types.RawChatId
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.toChatId
import kotlinx.serialization.Serializable
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.ISqlExpressionBuilder
import org.jetbrains.exposed.sql.Op
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.statements.InsertStatement
import org.jetbrains.exposed.sql.statements.UpdateBuilder
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.v1.core.Column
import org.jetbrains.exposed.v1.core.Op
import org.jetbrains.exposed.v1.core.ResultRow
import org.jetbrains.exposed.v1.core.and
import org.jetbrains.exposed.v1.core.eq
import org.jetbrains.exposed.v1.core.greaterEq
import org.jetbrains.exposed.v1.core.statements.UpdateBuilder
import org.jetbrains.exposed.v1.jdbc.Database
import org.jetbrains.exposed.v1.jdbc.transactions.transaction

class UsersPassInfoRepo(database: Database) : AbstractExposedKeyValuesRepo<UserId, UsersPassInfoRepo.PassInfo>(
database,
Expand All @@ -37,10 +36,10 @@ class UsersPassInfoRepo(database: Database) : AbstractExposedKeyValuesRepo<UserI

override val keyColumn: Column<Long>
get() = userIdColumn
override val selectById: ISqlExpressionBuilder.(UserId) -> Op<Boolean> = {
override val selectById: (UserId) -> Op<Boolean> = {
userIdColumn.eq(it.chatId.long)
}
override val selectByValue: ISqlExpressionBuilder.(PassInfo) -> Op<Boolean> = {
override val selectByValue: (PassInfo) -> Op<Boolean> = {
chatIdColumn.eq(it.chatId.chatId.long).and(passedColumn.eq(it.passed))
}
override val ResultRow.asKey: UserId
Expand Down
Loading
Loading