From d375875067cd68514a1d1da7f932bd92ba07a029 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 5 Jan 2022 01:15:32 +0600 Subject: [PATCH] chats settings update --- .../captcha/db/CaptchaChatsSettingsRepo.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/db/CaptchaChatsSettingsRepo.kt b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/db/CaptchaChatsSettingsRepo.kt index 821a5d0..af36785 100644 --- a/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/db/CaptchaChatsSettingsRepo.kt +++ b/src/main/kotlin/dev/inmo/plagubot/plugins/captcha/db/CaptchaChatsSettingsRepo.kt @@ -31,6 +31,8 @@ class CaptchaChatsSettingsRepo( default(defaultCaptchaProviderValue) } private val autoRemoveCommandsColumn = bool("autoRemoveCommands") + private val autoRemoveEventsColumn = bool("autoRemoveEvents") + private val enabledColumn = bool("enabled") override val primaryKey = PrimaryKey(chatIdColumn) @@ -42,27 +44,35 @@ class CaptchaChatsSettingsRepo( it[chatIdColumn] = value.chatId.chatId it[captchaProviderColumn] = captchaProviderSerialFormat.encodeToString(CaptchaProvider.serializer(), value.captchaProvider) it[autoRemoveCommandsColumn] = value.autoRemoveCommands + it[autoRemoveEventsColumn] = value.autoRemoveEvents + it[enabledColumn] = value.enabled } override fun update(id: ChatId, value: ChatSettings, it: UpdateStatement) { if (id.chatId == value.chatId.chatId) { it[captchaProviderColumn] = captchaProviderSerialFormat.encodeToString(CaptchaProvider.serializer(), value.captchaProvider) it[autoRemoveCommandsColumn] = value.autoRemoveCommands + it[autoRemoveEventsColumn] = value.autoRemoveEvents + it[enabledColumn] = value.enabled } } override fun InsertStatement.asObject(value: ChatSettings): ChatSettings = ChatSettings( - get(chatIdColumn).toChatId(), - captchaProviderSerialFormat.decodeFromString(CaptchaProvider.serializer(), get(captchaProviderColumn)), - get(autoRemoveCommandsColumn) + chatId = get(chatIdColumn).toChatId(), + captchaProvider = captchaProviderSerialFormat.decodeFromString(CaptchaProvider.serializer(), get(captchaProviderColumn)), + autoRemoveCommands = get(autoRemoveCommandsColumn), + autoRemoveEvents = get(autoRemoveEventsColumn), + enabled = get(enabledColumn) ) override val selectById: SqlExpressionBuilder.(ChatId) -> Op = { chatIdColumn.eq(it.chatId) } override val ResultRow.asObject: ChatSettings get() = ChatSettings( - get(chatIdColumn).toChatId(), - captchaProviderSerialFormat.decodeFromString(CaptchaProvider.serializer(), get(captchaProviderColumn)), - get(autoRemoveCommandsColumn) + chatId = get(chatIdColumn).toChatId(), + captchaProvider = captchaProviderSerialFormat.decodeFromString(CaptchaProvider.serializer(), get(captchaProviderColumn)), + autoRemoveCommands = get(autoRemoveCommandsColumn), + autoRemoveEvents = get(autoRemoveEventsColumn), + enabled = get(enabledColumn) ) init {