Merge pull request #5 from InsanusMokrassar/0.0.4

0.0.4
This commit is contained in:
InsanusMokrassar 2022-10-03 00:57:58 +06:00 committed by GitHub
commit af1bddcc85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 11 deletions

View File

@ -10,5 +10,5 @@ android.enableJetifier=true
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.0.3 version=0.0.4
android_code_version=3 android_code_version=4

View File

@ -3,12 +3,12 @@
kotlin = "1.7.10" kotlin = "1.7.10"
kotlin-serialization = "1.4.0" kotlin-serialization = "1.4.0"
plagubot = "2.3.2" plagubot = "2.3.4"
tgbotapi = "3.2.3" tgbotapi = "3.2.7"
microutils = "0.12.13" microutils = "0.12.16"
kslog = "0.5.2" kslog = "0.5.2"
krontab = "0.8.1" krontab = "0.8.1"
tgbotapi-libraries = "0.5.3" tgbotapi-libraries = "0.5.5"
psql = "42.5.0" psql = "42.5.0"
@ -19,8 +19,8 @@ espresso_core = "3.4.0"
android-gradle-plugin = "7.2.2" android-gradle-plugin = "7.2.2"
android-minSdk = "21" android-minSdk = "21"
android-compileSdk = "32" android-compileSdk = "33"
android-buildTools = "32.0.0" android-buildTools = "33.0.0"
[libraries] [libraries]

View File

@ -18,6 +18,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.strictlyOn import dev.inmo.tgbotapi.extensions.behaviour_builder.strictlyOn
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
import dev.inmo.tgbotapi.extensions.utils.extensions.sameChat
import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage
import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities
import dev.inmo.tgbotapi.extensions.utils.formatting.regular import dev.inmo.tgbotapi.extensions.utils.formatting.regular
@ -80,6 +81,12 @@ object Plugin : Plugin {
}.first() }.first()
emptyList<ContentMessage<MessageContent>>() emptyList<ContentMessage<MessageContent>>()
} }
add {
val finishPressed = waitCommandMessage("finish_post").filter {
it.sameChat(messageToDelete)
}.first()
emptyList<ContentMessage<MessageContent>>()
}
}.ifEmpty { }.ifEmpty {
edit(messageToDelete, "Ok, finishing your request") edit(messageToDelete, "Ok, finishing your request")
return@strictlyOn RegistrationState.Finish( return@strictlyOn RegistrationState.Finish(
@ -135,8 +142,16 @@ object Plugin : Plugin {
koin.getOrNull<InlineTemplatesRepo>() ?.apply { koin.getOrNull<InlineTemplatesRepo>() ?.apply {
addTemplate( addTemplate(
OfferTemplate( OfferTemplate(
"Start post", "Start post creating",
listOf(Format("/start_post")) listOf(Format("/start_post")),
"Use this command to start creating of complex post with several messages"
)
)
addTemplate(
OfferTemplate(
"Finish post creating",
listOf(Format("/finish_post")),
"Finish creating of complex post"
) )
) )
} }

View File

@ -22,6 +22,7 @@ import dev.inmo.plaguposter.ratings.models.Rating
import dev.inmo.plaguposter.ratings.repo.RatingsRepo import dev.inmo.plaguposter.ratings.repo.RatingsRepo
import dev.inmo.plaguposter.ratings.source.models.* import dev.inmo.plaguposter.ratings.source.models.*
import dev.inmo.plaguposter.ratings.source.repos.* import dev.inmo.plaguposter.ratings.source.repos.*
import dev.inmo.plaguposter.ratings.utils.postsByRatings
import dev.inmo.tgbotapi.extensions.api.answers.answer import dev.inmo.tgbotapi.extensions.api.answers.answer
import dev.inmo.tgbotapi.extensions.api.delete import dev.inmo.tgbotapi.extensions.api.delete
import dev.inmo.tgbotapi.extensions.api.edit.edit import dev.inmo.tgbotapi.extensions.api.edit.edit
@ -34,8 +35,9 @@ 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.dataButton
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
import dev.inmo.tgbotapi.types.message.textsources.bold
import dev.inmo.tgbotapi.types.message.textsources.regular import dev.inmo.tgbotapi.types.message.textsources.regular
import kotlinx.coroutines.flow.filter import dev.inmo.tgbotapi.utils.buildEntities
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.json.* import kotlinx.serialization.json.*
@ -79,6 +81,7 @@ object Plugin : Plugin {
val postsRepo = koin.get<PostsRepo>() val postsRepo = koin.get<PostsRepo>()
val config = koin.get<Config>() val config = koin.get<Config>()
val panelApi = koin.getOrNull<PanelButtonsAPI>() val panelApi = koin.getOrNull<PanelButtonsAPI>()
val chatConfig = koin.get<ChatConfig>()
onPollUpdates (markerFactory = { it.id }) { poll -> onPollUpdates (markerFactory = { it.id }) { poll ->
val postId = pollsToPostsIdsRepo.get(poll.id) ?: return@onPollUpdates val postId = pollsToPostsIdsRepo.get(poll.id) ?: return@onPollUpdates
@ -208,6 +211,22 @@ object Plugin : Plugin {
} }
} }
} }
onCommand("ratings", requireOnlyCommandInMessage = true) {
if (it.chat.id == chatConfig.sourceChatId) {
val ratings = ratingsRepo.postsByRatings().toList().sortedByDescending { it.first }
val textSources = buildEntities {
+ "Ratings amount: " + bold("${ratings.sumOf { it.second.size }}") + "\n\n"
ratings.forEach {
+ "" + bold("% 3.1f".format(it.first.double)) + ": " + bold(it.second.size.toString()) + "\n"
}
}
runCatchingSafely {
edit(it, textSources)
}.onFailure { _ ->
reply(it, textSources)
}
}
}
koin.getOrNull<InlineTemplatesRepo>() ?.apply { koin.getOrNull<InlineTemplatesRepo>() ?.apply {
addTemplate( addTemplate(

View File

@ -0,0 +1,15 @@
package dev.inmo.plaguposter.ratings.utils
import dev.inmo.micro_utils.pagination.utils.getAll
import dev.inmo.micro_utils.repos.pagination.getAll
import dev.inmo.plaguposter.posts.models.PostId
import dev.inmo.plaguposter.ratings.models.Rating
import dev.inmo.plaguposter.ratings.repo.RatingsRepo
suspend fun RatingsRepo.postsByRatings(): Map<Rating, List<PostId>> {
return getAll { keys(it) }.groupBy {
it.second
}.map {
it.key to it.value.map { it.first }
}.toMap()
}