mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-11-25 08:58:45 +00:00
updates
This commit is contained in:
parent
1d88423b03
commit
47f9e09bd2
@ -22,6 +22,7 @@ import dev.inmo.plaguposter.ratings.models.Rating
|
||||
import dev.inmo.plaguposter.ratings.repo.RatingsRepo
|
||||
import dev.inmo.plaguposter.ratings.source.models.*
|
||||
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.delete
|
||||
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.flatInlineKeyboard
|
||||
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 kotlinx.coroutines.flow.filter
|
||||
import dev.inmo.tgbotapi.utils.buildEntities
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
@ -79,6 +81,7 @@ object Plugin : Plugin {
|
||||
val postsRepo = koin.get<PostsRepo>()
|
||||
val config = koin.get<Config>()
|
||||
val panelApi = koin.getOrNull<PanelButtonsAPI>()
|
||||
val chatConfig = koin.get<ChatConfig>()
|
||||
|
||||
onPollUpdates (markerFactory = { it.id }) { poll ->
|
||||
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 {
|
||||
addTemplate(
|
||||
|
@ -1,8 +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() {
|
||||
getAll()
|
||||
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user