mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2026-03-13 12:32:33 +00:00
@@ -1,5 +1,7 @@
|
||||
# PlaguPoster
|
||||
|
||||
## 0.11.0
|
||||
|
||||
## 0.10.1
|
||||
|
||||
* Dependencies update
|
||||
|
||||
@@ -10,6 +10,7 @@ buildscript {
|
||||
classpath libs.kotlin.gradle.plugin
|
||||
classpath libs.kotlin.serialization.plugin
|
||||
classpath libs.kotlin.dokka.plugin
|
||||
classpath libs.github.release
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
0
changelog_parser.sh
Normal file → Executable file
0
changelog_parser.sh
Normal file → Executable file
@@ -25,14 +25,14 @@ if (secretFile.exists() || project.hasProperty(githubTokenVariableName) || (gith
|
||||
githubRelease {
|
||||
token githubReleaseToken
|
||||
|
||||
owner "InsanusMokrassar"
|
||||
repo "PlaguPoster"
|
||||
owner = "InsanusMokrassar"
|
||||
repo = "PlaguPoster"
|
||||
|
||||
tagName "v${project.version}"
|
||||
releaseName "${project.version}"
|
||||
targetCommitish "${project.version}"
|
||||
tagName = "v${project.version}"
|
||||
releaseName = "${project.version}"
|
||||
targetCommitish = "${project.version}"
|
||||
|
||||
body getCurrentVersionChangelog()
|
||||
body = getCurrentVersionChangelog()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,4 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.10.1
|
||||
version=0.11.0
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
[versions]
|
||||
|
||||
kotlin = "2.2.0"
|
||||
kotlin-serialization = "1.9.0"
|
||||
kotlin = "2.3.10"
|
||||
kotlin-serialization = "1.10.0"
|
||||
|
||||
plagubot = "10.7.0"
|
||||
tgbotapi = "27.1.2"
|
||||
microutils = "0.26.2"
|
||||
kslog = "1.5.0"
|
||||
krontab = "2.7.2"
|
||||
plagubot-plugins = "0.24.5"
|
||||
plagubot = "11.0.0"
|
||||
tgbotapi = "32.0.0"
|
||||
microutils = "0.29.1"
|
||||
kslog = "1.6.0"
|
||||
krontab = "2.8.0"
|
||||
plagubot-plugins = "0.25.0"
|
||||
|
||||
nmcp="1.0.2"
|
||||
nmcp = "1.4.4"
|
||||
|
||||
dokka = "2.0.0"
|
||||
|
||||
psql = "42.6.0"
|
||||
|
||||
github-release = "2.5.2"
|
||||
|
||||
[libraries]
|
||||
|
||||
kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
|
||||
@@ -44,6 +46,7 @@ psql = { module = "org.postgresql:postgresql", version.ref = "psql" }
|
||||
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||
kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
|
||||
kotlin-dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
|
||||
github-release = { module = "com.github.breadmoirai:github-release", version.ref = "github-release" }
|
||||
|
||||
[plugins]
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import dev.inmo.kslog.common.w
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton
|
||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
||||
import dev.inmo.tgbotapi.types.MilliSeconds
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardButtonStyle
|
||||
import dev.inmo.tgbotapi.utils.bold
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.filter
|
||||
@@ -148,7 +149,7 @@ object Plugin : Plugin {
|
||||
message,
|
||||
text = "Are you sure want to trigger posts garbage collecting?",
|
||||
replyMarkup = flatInlineKeyboard {
|
||||
dataButton("Sure", yesData)
|
||||
dataButton("Sure", yesData, style = KeyboardButtonStyle.Primary)
|
||||
dataButton("No", noData)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package dev.inmo.plaguposter.posts.panel
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.koin.getAllDistinct
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import dev.inmo.micro_utils.repos.cache.cache.FullKVCache
|
||||
import dev.inmo.micro_utils.repos.cache.cached
|
||||
import dev.inmo.micro_utils.repos.cache.full.cached
|
||||
import dev.inmo.micro_utils.repos.cache.full.fullyCached
|
||||
import dev.inmo.plagubot.Plugin
|
||||
import dev.inmo.plagubot.registerConfig
|
||||
@@ -35,6 +34,7 @@ import dev.inmo.tgbotapi.types.MessageId
|
||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardButtonStyle
|
||||
import dev.inmo.tgbotapi.types.message.ParseMode
|
||||
import dev.inmo.tgbotapi.utils.bold
|
||||
import dev.inmo.tgbotapi.utils.buildEntities
|
||||
@@ -42,7 +42,6 @@ import dev.inmo.tgbotapi.utils.italic
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
@@ -73,7 +72,8 @@ object Plugin : Plugin {
|
||||
PanelButtonBuilder {
|
||||
CallbackDataInlineKeyboardButton(
|
||||
text,
|
||||
"refresh ${it.id.string}"
|
||||
"refresh ${it.id.string}",
|
||||
style = KeyboardButtonStyle.Primary
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ object Plugin : Plugin {
|
||||
basePostsMessages
|
||||
}
|
||||
|
||||
postsRepo.newObjectsFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
postsRepo.newObjectsFlow.subscribeLoggingDropExceptions(this) {
|
||||
val firstContent = it.content.first()
|
||||
val buttons = api.buttonsBuilders.chunked(config.buttonsPerRow).mapNotNull { row ->
|
||||
row.mapNotNull { builder ->
|
||||
@@ -166,7 +166,7 @@ object Plugin : Plugin {
|
||||
edit(
|
||||
query.message,
|
||||
replyMarkup = flatInlineKeyboard {
|
||||
dataButton("\uD83D\uDDD1", approveData)
|
||||
dataButton("\uD83D\uDDD1", approveData, style = KeyboardButtonStyle.Danger)
|
||||
api.RootPanelButtonBuilder.buildButton(post) ?.let(::add)
|
||||
}
|
||||
)
|
||||
@@ -188,7 +188,7 @@ object Plugin : Plugin {
|
||||
val postId = query.data.removePrefix("refresh ").let(::PostId)
|
||||
val (chatId, messageId) = postsMessages.get(postId) ?: return@onMessageDataCallbackQuery
|
||||
|
||||
runCatchingSafely {
|
||||
runCatching {
|
||||
refreshPostMessage(
|
||||
postId,
|
||||
chatId,
|
||||
|
||||
@@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.builtins.PairSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.jetbrains.exposed.v1.jdbc.Database
|
||||
|
||||
private val ChatIdToMessageSerializer = PairSerializer(FullChatIdentifierSerializer, MessageId.serializer())
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@ import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.*
|
||||
import dev.inmo.plaguposter.posts.models.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.v1.core.Column
|
||||
import org.jetbrains.exposed.v1.core.ReferenceOption
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.Table
|
||||
import org.jetbrains.exposed.v1.jdbc.Database
|
||||
|
||||
internal class ExposedContentInfoRepo(
|
||||
override val database: Database,
|
||||
|
||||
@@ -13,11 +13,19 @@ import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.MessageId
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
|
||||
import org.jetbrains.exposed.sql.statements.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
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.inList
|
||||
import org.jetbrains.exposed.v1.core.isNull
|
||||
import org.jetbrains.exposed.v1.core.statements.InsertStatement
|
||||
import org.jetbrains.exposed.v1.core.statements.UpdateBuilder
|
||||
import org.jetbrains.exposed.v1.jdbc.Database
|
||||
import org.jetbrains.exposed.v1.jdbc.deleteWhere
|
||||
import org.jetbrains.exposed.v1.jdbc.insert
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
|
||||
class ExposedPostsRepo(
|
||||
override val database: Database
|
||||
@@ -37,8 +45,8 @@ class ExposedPostsRepo(
|
||||
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(idColumn)
|
||||
|
||||
override val selectById: ISqlExpressionBuilder.(PostId) -> Op<Boolean> = { idColumn.eq(it.string) }
|
||||
override val selectByIds: ISqlExpressionBuilder.(List<PostId>) -> Op<Boolean> = { idColumn.inList(it.map { it.string }) }
|
||||
override val selectById: (PostId) -> Op<Boolean> = { idColumn.eq(it.string) }
|
||||
override val selectByIds: (List<PostId>) -> Op<Boolean> = { idColumn.inList(it.map { it.string }) }
|
||||
override val ResultRow.asId: PostId
|
||||
get() = PostId(get(idColumn))
|
||||
override val ResultRow.asObject: RegisteredPost
|
||||
@@ -133,7 +141,7 @@ class ExposedPostsRepo(
|
||||
val existsIds = posts.keys.toList()
|
||||
transaction(db = database) {
|
||||
val deleted = deleteWhere {
|
||||
selectByIds(it, existsIds)
|
||||
selectByIds(existsIds)
|
||||
}
|
||||
with(contentRepo) {
|
||||
deleteWhere {
|
||||
|
||||
@@ -22,6 +22,7 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sameChat
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.textContentOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardButtonStyle
|
||||
import dev.inmo.tgbotapi.utils.regular
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.*
|
||||
@@ -56,7 +57,8 @@ object Plugin : Plugin {
|
||||
flatInlineKeyboard {
|
||||
dataButton(
|
||||
"Finish",
|
||||
buttonUuid
|
||||
buttonUuid,
|
||||
style = KeyboardButtonStyle.Primary,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -25,7 +25,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onComman
|
||||
import dev.inmo.tgbotapi.types.Seconds
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.plaguposter.ratings.source
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.kslog.common.e
|
||||
import dev.inmo.kslog.common.logger
|
||||
import dev.inmo.micro_utils.common.fixed
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
@@ -43,6 +44,8 @@ import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard
|
||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardButtonStyle
|
||||
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
||||
import dev.inmo.tgbotapi.types.message.textsources.boldTextSource
|
||||
import dev.inmo.tgbotapi.types.message.textsources.regularTextSource
|
||||
import dev.inmo.tgbotapi.types.polls.InputPollOption
|
||||
@@ -54,13 +57,15 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.qualifier.named
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object Plugin : Plugin {
|
||||
private val ratingVariantsQualifier = named("ratingsVariants")
|
||||
private const val attachedSymbolControlSymbol = "\${attached_symbol}"
|
||||
private const val currentRatingControlSymbol = "\${rating}"
|
||||
|
||||
@Serializable
|
||||
internal data class Config(
|
||||
@@ -68,7 +73,9 @@ object Plugin : Plugin {
|
||||
val variants: RatingsVariants,
|
||||
val autoAttach: Boolean,
|
||||
val ratingOfferText: String,
|
||||
val panelButtonText: String = "Ratings"
|
||||
val panelButtonText: String = "Ratings $attachedSymbolControlSymbol",
|
||||
val ratingEnabledStyle: KeyboardButtonStyle? = null,
|
||||
val ratingDisabledStyle: KeyboardButtonStyle? = null,
|
||||
)
|
||||
|
||||
override fun Module.setupDI(params: JsonObject) {
|
||||
@@ -115,12 +122,22 @@ object Plugin : Plugin {
|
||||
val panelApi = koin.getOrNull<PanelButtonsAPI>()
|
||||
val chatConfig = koin.get<ChatConfig>()
|
||||
|
||||
val panelApiOnPollUpdatesUpdateTrigger: suspend (PostId) -> Unit = if (config.panelButtonText.contains(currentRatingControlSymbol)) {
|
||||
{
|
||||
panelApi ?.forceRefresh(it)
|
||||
}
|
||||
} else {
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
onPollUpdates (markerFactory = { it.id }) { poll ->
|
||||
val postId = pollsToPostsIdsRepo.get(poll.id) ?: return@onPollUpdates
|
||||
val newRating = poll.options.sumOf {
|
||||
(variantsTransformer(it.textSources.makeSourceString()) ?.double ?.times(it.votes)) ?: 0.0
|
||||
}
|
||||
ratingsRepo.set(postId, Rating(newRating))
|
||||
panelApiOnPollUpdatesUpdateTrigger(postId)
|
||||
}
|
||||
|
||||
suspend fun attachPoll(postId: PostId): Boolean {
|
||||
@@ -297,13 +314,69 @@ object Plugin : Plugin {
|
||||
panelApi ?.apply {
|
||||
add(
|
||||
PanelButtonBuilder {
|
||||
suspend fun isEnabled() = pollsToPostsIdsRepo.keys(it.id, firstPageWithOneElementPagination).results.any()
|
||||
val enabled = let { _ ->
|
||||
var enabled: Boolean? = null
|
||||
suspend {
|
||||
enabled ?: (isEnabled().also { enabled = it })
|
||||
}
|
||||
}
|
||||
val rating = let { _ ->
|
||||
var rating: Rating? = null
|
||||
suspend {
|
||||
if (isEnabled()) {
|
||||
rating ?: ratingsRepo.get(it.id) ?.also { rating = it }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
val resultText = config.panelButtonText
|
||||
.let {
|
||||
if (it.contains(attachedSymbolControlSymbol)) {
|
||||
it.replace(
|
||||
attachedSymbolControlSymbol,
|
||||
if (enabled()) {
|
||||
SuccessfulSymbol
|
||||
} else {
|
||||
UnsuccessfulSymbol
|
||||
}
|
||||
)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
.let {
|
||||
if (it.contains(currentRatingControlSymbol)) {
|
||||
val rating = rating()
|
||||
if (rating != null) {
|
||||
it.replace(
|
||||
currentRatingControlSymbol,
|
||||
rating.double.roundToInt().toString()
|
||||
)
|
||||
} else {
|
||||
it.replace(
|
||||
currentRatingControlSymbol,
|
||||
UnsuccessfulSymbol
|
||||
)
|
||||
}
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
.take(12) // maximal text appropriate for this button
|
||||
CallbackDataInlineKeyboardButton(
|
||||
config.panelButtonText + if (pollsToPostsIdsRepo.keys(it.id, firstPageWithOneElementPagination).results.any()) {
|
||||
SuccessfulSymbol
|
||||
resultText,
|
||||
"toggle_ratings ${it.id.string}",
|
||||
style = if (config.ratingEnabledStyle != null || config.ratingDisabledStyle != null) {
|
||||
if (enabled()) {
|
||||
config.ratingEnabledStyle
|
||||
} else {
|
||||
config.ratingDisabledStyle
|
||||
}
|
||||
} else {
|
||||
UnsuccessfulSymbol
|
||||
},
|
||||
"toggle_ratings ${it.id.string}"
|
||||
null
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -4,10 +4,13 @@ import dev.inmo.micro_utils.repos.exposed.initTable
|
||||
import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo
|
||||
import dev.inmo.plaguposter.common.ShortMessageInfo
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull
|
||||
import org.jetbrains.exposed.sql.statements.*
|
||||
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
|
||||
|
||||
class ExposedPollsToMessagesInfoRepo(
|
||||
database: Database
|
||||
@@ -19,8 +22,8 @@ class ExposedPollsToMessagesInfoRepo(
|
||||
private val chatIdColumn = long("chat_id")
|
||||
private val threadIdColumn = long("thread_id").nullable().default(null)
|
||||
private val messageIdColumn = long("message_id")
|
||||
override val selectById: ISqlExpressionBuilder.(PollId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: ISqlExpressionBuilder.(ShortMessageInfo) -> Op<Boolean> = {
|
||||
override val selectById: (PollId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: (ShortMessageInfo) -> Op<Boolean> = {
|
||||
chatIdColumn.eq(it.chatId.chatId.long)
|
||||
.and(it.chatId.threadId?.let { threadIdColumn.eq(it.long) } ?: threadIdColumn.isNull()).and(
|
||||
messageIdColumn.eq(it.messageId.long)
|
||||
|
||||
@@ -4,16 +4,19 @@ import dev.inmo.micro_utils.repos.exposed.initTable
|
||||
import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.tgbotapi.types.PollId
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.statements.*
|
||||
import org.jetbrains.exposed.v1.core.Op
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.statements.UpdateBuilder
|
||||
import org.jetbrains.exposed.v1.jdbc.Database
|
||||
|
||||
class ExposedPollsToPostsIdsRepo(
|
||||
database: Database
|
||||
) : PollsToPostsIdsRepo, AbstractExposedKeyValueRepo<PollId, PostId>(database, "polls_to_posts") {
|
||||
override val keyColumn = text("poll_id")
|
||||
val postIdColumn = text("postId")
|
||||
override val selectById: ISqlExpressionBuilder.(PollId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: ISqlExpressionBuilder.(PostId) -> Op<Boolean> = { postIdColumn.eq(it.string) }
|
||||
override val selectById: (PollId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: (PostId) -> Op<Boolean> = { postIdColumn.eq(it.string) }
|
||||
override val ResultRow.asKey: PollId
|
||||
get() = PollId(get(keyColumn))
|
||||
override val ResultRow.asObject: PostId
|
||||
|
||||
@@ -6,9 +6,17 @@ import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.ratings.models.Rating
|
||||
import dev.inmo.plaguposter.ratings.repo.RatingsRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.statements.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
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.lessEq
|
||||
import org.jetbrains.exposed.v1.core.notInList
|
||||
import org.jetbrains.exposed.v1.core.statements.UpdateBuilder
|
||||
import org.jetbrains.exposed.v1.jdbc.Database
|
||||
import org.jetbrains.exposed.v1.jdbc.Query
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
|
||||
class ExposedRatingsRepo (
|
||||
database: Database
|
||||
@@ -18,8 +26,8 @@ class ExposedRatingsRepo (
|
||||
) {
|
||||
override val keyColumn = text("post_id")
|
||||
val ratingsColumn = double("rating")
|
||||
override val selectById: ISqlExpressionBuilder.(PostId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: ISqlExpressionBuilder.(Rating) -> Op<Boolean> = { ratingsColumn.eq(it.double) }
|
||||
override val selectById: (PostId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: (Rating) -> Op<Boolean> = { ratingsColumn.eq(it.double) }
|
||||
override val ResultRow.asKey: PostId
|
||||
get() = get(keyColumn).let(::PostId)
|
||||
override val ResultRow.asObject: Rating
|
||||
|
||||
@@ -41,7 +41,11 @@
|
||||
"Results": 0
|
||||
},
|
||||
"autoAttach": true,
|
||||
"ratingOfferText": "What do you think about it?"
|
||||
"ratingOfferText": "What do you think about it?",
|
||||
"panelButtonText": "Ratings ${attached_symbol}",
|
||||
"ratingEnabledStyle": "success",
|
||||
"ratingDisabledStyle": "danger",
|
||||
"_note": "For panelButtonText you may use two control symbols: ${attached_symbol} to attach icon about enabled state and ${rating} to enable rating showing in button"
|
||||
},
|
||||
"selector": {
|
||||
"items": [
|
||||
|
||||
@@ -31,7 +31,6 @@ import dev.inmo.tgbotapi.types.message.textsources.regularTextSource
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
@@ -114,7 +113,7 @@ object Plugin : Plugin {
|
||||
PanelButtonBuilder {
|
||||
CallbackDataInlineKeyboardButton(
|
||||
text,
|
||||
"publish ${it.id.string}"
|
||||
"publish ${it.id.string}",
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -41,7 +41,6 @@ import kotlinx.coroutines.flow.collectIndexed
|
||||
import kotlinx.coroutines.flow.take
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.*
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.inmo.plaguposter.posts.models.RegisteredPost
|
||||
import dev.inmo.plaguposter.posts.panel.PanelButtonBuilder
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.InlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardButtonStyle
|
||||
|
||||
class TimerPanelButton(
|
||||
private val timersRepo: TimersRepo
|
||||
@@ -18,7 +19,12 @@ class TimerPanelButton(
|
||||
|
||||
return CallbackDataInlineKeyboardButton(
|
||||
"⏰ ${ if (publishingTime == null) UnsuccessfulSymbol else SuccessfulSymbol }",
|
||||
"$timerSetPrefix ${post.id}"
|
||||
"$timerSetPrefix ${post.id}",
|
||||
style = if (publishingTime == null) {
|
||||
null
|
||||
} else {
|
||||
KeyboardButtonStyle.Success
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,15 +11,12 @@ import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
||||
import dev.inmo.plaguposter.triggers.timer.TimersRepo
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
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.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.Op
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.statements.UpdateBuilder
|
||||
import org.jetbrains.exposed.v1.jdbc.Database
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
|
||||
class ExposedTimersRepo(
|
||||
database: Database,
|
||||
@@ -31,8 +28,8 @@ class ExposedTimersRepo(
|
||||
) {
|
||||
override val keyColumn = text("post_id")
|
||||
private val dateTimeColumn = long("date_time")
|
||||
override val selectById: ISqlExpressionBuilder.(PostId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: ISqlExpressionBuilder.(DateTime) -> Op<Boolean> = { dateTimeColumn.eq(it.unixMillisLong) }
|
||||
override val selectById: (PostId) -> Op<Boolean> = { keyColumn.eq(it.string) }
|
||||
override val selectByValue: (DateTime) -> Op<Boolean> = { dateTimeColumn.eq(it.unixMillisLong) }
|
||||
override val ResultRow.asKey: PostId
|
||||
get() = PostId(get(keyColumn))
|
||||
override val ResultRow.asObject: DateTime
|
||||
|
||||
Reference in New Issue
Block a user