Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed Apr 24, 2024
1 parent 4342541 commit c7ca98f
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 71 deletions.
1 change: 0 additions & 1 deletion common/src/jvmMain/kotlin/ChatsConfig.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.inmo.plagubot.suggestionsbot.common

import dev.inmo.micro_utils.language_codes.IetfLang
import dev.inmo.micro_utils.language_codes.IetfLanguageCode
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer
import dev.inmo.tgbotapi.types.IdChatIdentifier
Expand Down
3 changes: 2 additions & 1 deletion common/src/jvmMain/kotlin/MessageInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.inmo.plagubot.suggestionsbot.common

import dev.inmo.tgbotapi.extensions.utils.possiblyMediaGroupMessageOrNull
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MediaGroupId
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.message.abstracts.Message
import kotlinx.serialization.Serializable
Expand All @@ -10,7 +11,7 @@ import kotlinx.serialization.Serializable
data class MessageInfo(
val chatId: IdChatIdentifier,
val messageId: MessageId,
val group: String? = null
val group: MediaGroupId? = null
)

operator fun MessageInfo.Companion.invoke(
Expand Down
18 changes: 9 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[versions]

kotlin = "1.9.22"
kotlin-serialization = "1.6.2"
kotlin = "1.9.23"
kotlin-serialization = "1.6.3"

plagubot = "8.2.0"
plagubot-plugins = "0.18.2"
tgbotapi-libraries = "0.18.3"
plagubot = "8.3.0"
plagubot-plugins = "0.18.3"
tgbotapi-libraries = "0.19.0"

moko-resources = "0.23.0"

tgbotapi = "10.1.0"
tgbotapi = "12.0.1"

psql = "42.6.0"

microutils = "0.20.35"
microutils = "0.20.45"

ksp = "1.9.22-1.0.17"
ksp = "1.9.23-1.0.20"

dokka = "1.9.10"
dokka = "1.9.20"

[libraries]

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 19 additions & 16 deletions reviews/src/jvmMain/kotlin/repo/ExposedReviewMessagesInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import dev.inmo.micro_utils.repos.exposed.onetomany.AbstractExposedKeyValuesRepo
import dev.inmo.plagubot.suggestionsbot.reviews.models.ReviewContentInfo
import dev.inmo.plagubot.suggestionsbot.suggestions.models.SuggestionId
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.RawChatId
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.ISqlExpressionBuilder
Expand All @@ -31,35 +34,35 @@ class ExposedReviewMessagesInfo(

override val selectById: ISqlExpressionBuilder.(SuggestionId) -> Op<Boolean> = { keyColumn.eq(it.string) }
override val selectByValue: ISqlExpressionBuilder.(ReviewContentInfo) -> Op<Boolean> = {
chatIdColumn.eq(it.chatId.chatId).and(
threadIdColumn.eqOrIsNull(it.chatId.threadId)
chatIdColumn.eq(it.chatId.chatId.long).and(
threadIdColumn.eqOrIsNull(it.chatId.threadId ?.long)
).and(
messageIdColumn.eq(it.messageId)
messageIdColumn.eq(it.messageId.long)
).and(
suggestionChatIdColumn.eq(it.suggestionChatId.chatId)
suggestionChatIdColumn.eq(it.suggestionChatId.chatId.long)
).and(
suggestionThreadIdColumn.eqOrIsNull(it.suggestionChatId.threadId)
suggestionThreadIdColumn.eqOrIsNull(it.suggestionChatId.threadId ?.long)
).and(
suggestionMessageIdColumn.eq(it.suggestionMessageId)
suggestionMessageIdColumn.eq(it.suggestionMessageId.long)
)
}
override val ResultRow.asKey: SuggestionId
get() = SuggestionId(get(keyColumn))
override val ResultRow.asObject: ReviewContentInfo
get() = ReviewContentInfo(
IdChatIdentifier(get(chatIdColumn), get(threadIdColumn)),
get(messageIdColumn),
IdChatIdentifier(get(suggestionChatIdColumn), get(suggestionThreadIdColumn)),
get(suggestionMessageIdColumn)
IdChatIdentifier(RawChatId(get(chatIdColumn)), get(threadIdColumn) ?.let(::MessageThreadId)),
MessageId(get(messageIdColumn)),
IdChatIdentifier(RawChatId(get(suggestionChatIdColumn)), get(suggestionThreadIdColumn) ?.let(::MessageThreadId)),
MessageId(get(suggestionMessageIdColumn))
)

override fun insert(k: SuggestionId, v: ReviewContentInfo, it: InsertStatement<Number>) {
it[keyColumn] = k.string
it[chatIdColumn] = v.chatId.chatId
it[threadIdColumn] = v.chatId.threadId
it[messageIdColumn] = v.messageId
it[suggestionChatIdColumn] = v.suggestionChatId.chatId
it[suggestionThreadIdColumn] = v.suggestionChatId.threadId
it[suggestionMessageIdColumn] = v.suggestionMessageId
it[chatIdColumn] = v.chatId.chatId.long
it[threadIdColumn] = v.chatId.threadId ?.long
it[messageIdColumn] = v.messageId.long
it[suggestionChatIdColumn] = v.suggestionChatId.chatId.long
it[suggestionThreadIdColumn] = v.suggestionChatId.threadId ?.long
it[suggestionMessageIdColumn] = v.suggestionMessageId.long
}
}
2 changes: 0 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ includes.each { originalName ->
project.name = projectName
project.projectDir = new File(projectDirectory)
}

enableFeaturePreview("VERSION_CATALOGS")
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.libraries.resender.MessageMetaInfo
import dev.inmo.tgbotapi.libraries.resender.invoke
import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
import kotlinx.serialization.Serializable
Expand Down
4 changes: 2 additions & 2 deletions suggestions/src/commonMain/kotlin/repo/SuggestionsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import dev.inmo.micro_utils.repos.CRUDRepo
import dev.inmo.plagubot.suggestionsbot.suggestions.models.*
import korlibs.time.DateTime
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.UserId

import kotlinx.coroutines.flow.Flow


interface ReadSuggestionsRepo : ReadCRUDRepo<RegisteredSuggestion, SuggestionId> {
suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageIdentifier): SuggestionId?
suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageId): SuggestionId?

suspend fun getFirstMessageInfo(suggestionId: SuggestionId): SuggestionContentInfo?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.inmo.plagubot.suggestionsbot.suggestions.exposed
import dev.inmo.micro_utils.repos.exposed.*
import dev.inmo.plagubot.suggestionsbot.suggestions.models.*
import dev.inmo.tgbotapi.libraries.resender.MessageMetaInfo
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.*
import org.jetbrains.exposed.sql.*

internal class ExposedContentInfoRepo(
Expand All @@ -20,9 +20,9 @@ internal class ExposedContentInfoRepo(
val ResultRow.asObject
get() = SuggestionContentInfo(
MessageMetaInfo(
IdChatIdentifier(get(chatIdColumn), get(threadIdColumn)),
get(messageIdColumn),
get(groupColumn)
IdChatIdentifier(RawChatId(get(chatIdColumn)), get(threadIdColumn) ?.let(::MessageThreadId)),
MessageId(get(messageIdColumn)),
get(groupColumn) ?.let(::MediaGroupId)
),
get(orderColumn)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import korlibs.time.DateTime
import dev.inmo.micro_utils.repos.exposed.*
import dev.inmo.plagubot.suggestionsbot.suggestions.exposed.ExposedStatusesRepo.Companion.statusType
import dev.inmo.plagubot.suggestionsbot.suggestions.models.*
import dev.inmo.tgbotapi.types.RawChatId
import dev.inmo.tgbotapi.types.UserId
import org.jetbrains.exposed.sql.*
import kotlin.reflect.KClass
Expand All @@ -20,7 +21,7 @@ internal class ExposedStatusesRepo(
val ResultRow.asObject
get() = get(statusTypeColumn).status(
DateTime(get(dateTimeColumn)),
get(reviewerIdColumn) ?.let(::UserId)
get(reviewerIdColumn) ?.let(::RawChatId) ?.let(::UserId)
)

init {
Expand Down
31 changes: 14 additions & 17 deletions suggestions/src/jvmMain/kotlin/exposed/ExposedSuggestionsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import dev.inmo.micro_utils.repos.exposed.initTable
import dev.inmo.plagubot.suggestionsbot.suggestions.exposed.ExposedStatusesRepo.Companion.statusType
import dev.inmo.plagubot.suggestionsbot.suggestions.models.*
import dev.inmo.plagubot.suggestionsbot.suggestions.repo.SuggestionsRepo
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.messageThreadIdField
import dev.inmo.tgbotapi.types.*
import kotlinx.coroutines.flow.*
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
Expand Down Expand Up @@ -61,7 +58,7 @@ class ExposedSuggestionsRepo(
SortOrder.DESC
).limit(1).firstOrNull() ?.asObject
} ?: error("Unable to take any status for the suggestion $id"),
UserId(get(userIdColumn)),
UserId(RawChatId(get(userIdColumn))),
get(isAnonymousColumn),
with(contentRepo) {
selectAll().where { suggestionIdColumn.eq(id.string) }.map {
Expand Down Expand Up @@ -91,7 +88,7 @@ class ExposedSuggestionsRepo(
SortOrder.DESC
).limit(1).firstOrNull() ?.asObject
} ?: value.status,
UserId(get(userIdColumn)),
UserId(RawChatId(get(userIdColumn))),
get(isAnonymousColumn),
with(contentRepo) {
selectAll().where { suggestionIdColumn.eq(id.string) }.map {
Expand All @@ -108,7 +105,7 @@ class ExposedSuggestionsRepo(
}

override fun update(id: SuggestionId?, value: NewSuggestion, it: UpdateBuilder<Int>) {
it[userIdColumn] = value.user.chatId
it[userIdColumn] = value.user.chatId.long
it[isAnonymousColumn] = value.isAnonymous
}

Expand All @@ -121,7 +118,7 @@ class ExposedSuggestionsRepo(
insert {
it[suggestionIdColumn] = suggestionId.string
it[dateTimeColumn] = status.dateTime.unixMillis
it[reviewerIdColumn] = (status as? SuggestionStatus.Reviewed) ?.reviewerId ?.chatId
it[reviewerIdColumn] = (status as? SuggestionStatus.Reviewed) ?.reviewerId ?.chatId ?.long
it[statusTypeColumn] = status.statusType()
}
}
Expand All @@ -134,10 +131,10 @@ class ExposedSuggestionsRepo(
post.content.forEach { contentInfo ->
insert {
it[suggestionIdColumn] = post.id.string
it[chatIdColumn] = contentInfo.messageMetaInfo.chatId.chatId
it[threadIdColumn] = contentInfo.messageMetaInfo.chatId.threadId
it[messageIdColumn] = contentInfo.messageMetaInfo.messageId
it[groupColumn] = contentInfo.messageMetaInfo.group
it[chatIdColumn] = contentInfo.messageMetaInfo.chatId.chatId.long
it[threadIdColumn] = contentInfo.messageMetaInfo.chatId.threadId ?.long
it[messageIdColumn] = contentInfo.messageMetaInfo.messageId.long
it[groupColumn] = contentInfo.messageMetaInfo.group ?.string
it[orderColumn] = contentInfo.order
}
}
Expand Down Expand Up @@ -204,13 +201,13 @@ class ExposedSuggestionsRepo(
_updatedObjectsFlow.emit(it)
}

override suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageIdentifier): SuggestionId? {
override suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageId): SuggestionId? {
return transaction(database) {
with(contentRepo) {
selectAll().where {
chatIdColumn.eq(chatId.chatId)
.and(chatId.threadId ?.let { threadIdColumn.eq(it) } ?: threadIdColumn.isNull())
.and(messageIdColumn.eq(messageId))
chatIdColumn.eq(chatId.chatId.long)
.and(chatId.threadId ?.let { threadIdColumn.eq(it.long) } ?: threadIdColumn.isNull())
.and(messageIdColumn.eq(messageId.long))
}.limit(1).firstOrNull() ?.get(suggestionIdColumn)
} ?.let(::SuggestionId)
}
Expand All @@ -234,7 +231,7 @@ class ExposedSuggestionsRepo(

override suspend fun isUserHaveBannedSuggestions(userid: UserId): Boolean = transaction(database) {
selectAll().where {
userIdColumn.eq(userid.chatId).and(
userIdColumn.eq(userid.chatId.long).and(
idColumn.inSubQuery(
with(statusesRepo) {
select(suggestionIdColumn).where {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import dev.inmo.micro_utils.repos.exposed.initTable
import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo
import dev.inmo.plagubot.suggestionsbot.suggestions.models.SuggestionId
import dev.inmo.tgbotapi.libraries.resender.MessageMetaInfo
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.*
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.ISqlExpressionBuilder
Expand All @@ -29,32 +28,32 @@ class SuggestionsMessageMetaInfosExposedRepo(
private val groupColumn = text("group").nullable()
override val selectById: ISqlExpressionBuilder.(SuggestionId) -> Op<Boolean> = { keyColumn.eq(it.string) }
override val selectByValue: ISqlExpressionBuilder.(MessageMetaInfo) -> Op<Boolean> = {
chatIdColumn.eq(it.chatId.chatId).and(
threadIdColumn.eqOrIsNull(it.chatId.threadId)
chatIdColumn.eq(it.chatId.chatId.long).and(
threadIdColumn.eqOrIsNull(it.chatId.threadId ?.long)
).and(
messageIdColumn.eq(it.messageId)
messageIdColumn.eq(it.messageId.long)
).and(
groupColumn.eqOrIsNull(it.group)
groupColumn.eqOrIsNull(it.group ?.string)
)
}
override val ResultRow.asKey: SuggestionId
get() = SuggestionId(get(keyColumn))
override val ResultRow.asObject: MessageMetaInfo
get() = MessageMetaInfo(
IdChatIdentifier(get(chatIdColumn), get(threadIdColumn)),
get(messageIdColumn),
get(groupColumn)
IdChatIdentifier(RawChatId(get(chatIdColumn)), get(threadIdColumn) ?.let(::MessageThreadId)),
MessageId(get(messageIdColumn)),
get(groupColumn) ?.let(::MediaGroupId)
)

init {
initTable()
}

override fun update(k: SuggestionId, v: MessageMetaInfo, it: UpdateBuilder<Int>) {
it[chatIdColumn] = v.chatId.chatId
it[threadIdColumn] = v.chatId.threadId
it[messageIdColumn] = v.messageId
it[groupColumn] = v.group
it[chatIdColumn] = v.chatId.chatId.long
it[threadIdColumn] = v.chatId.threadId ?.long
it[messageIdColumn] = v.messageId.long
it[groupColumn] = v.group ?.string
}

override fun insertKey(k: SuggestionId, v: MessageMetaInfo, it: InsertStatement<Number>) {
Expand All @@ -66,10 +65,10 @@ class SuggestionsMessageMetaInfosExposedRepo(
messageId: MessageId
) = transaction(database) {
selectAll().where {
chatIdColumn.eq(chatId.chatId).and(
threadIdColumn.eqOrIsNull(chatId.threadId)
chatIdColumn.eq(chatId.chatId.long).and(
threadIdColumn.eqOrIsNull(chatId.threadId ?.long)
).and(
messageIdColumn.eq(messageId)
messageIdColumn.eq(messageId.long)
)
}.limit(1).firstOrNull() ?.get(keyColumn) ?.let(::SuggestionId)
}
Expand Down

0 comments on commit c7ca98f

Please sign in to comment.