mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2025-12-05 20:45:40 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47f9e09bd2 | |||
| 1d88423b03 | |||
| 3634b9a2a2 | |||
| 4b7c2451cd | |||
| 1cd7c07d29 | |||
| 9c4b49df22 | |||
| 963d33a452 | |||
| 7a05b56af2 | |||
| 39d49f5d58 | |||
| b9700a8fd9 | |||
| 79c195f534 | |||
| 91221d865c | |||
| 5808f45677 | |||
| 29d6d11d87 | |||
| 609c6b97fc |
@@ -10,5 +10,5 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.0.2
|
||||
android_code_version=2
|
||||
version=0.0.4
|
||||
android_code_version=4
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
kotlin = "1.7.10"
|
||||
kotlin-serialization = "1.4.0"
|
||||
|
||||
plagubot = "2.3.1"
|
||||
tgbotapi = "3.2.1"
|
||||
microutils = "0.12.13"
|
||||
plagubot = "2.3.4"
|
||||
tgbotapi = "3.2.7"
|
||||
microutils = "0.12.16"
|
||||
kslog = "0.5.2"
|
||||
krontab = "0.8.1"
|
||||
tgbotapi-libraries = "0.5.3"
|
||||
tgbotapi-libraries = "0.5.5"
|
||||
|
||||
psql = "42.3.6"
|
||||
psql = "42.5.0"
|
||||
|
||||
dexcount = "3.1.0"
|
||||
junit_version = "4.12"
|
||||
@@ -19,8 +19,8 @@ espresso_core = "3.4.0"
|
||||
|
||||
android-gradle-plugin = "7.2.2"
|
||||
android-minSdk = "21"
|
||||
android-compileSdk = "32"
|
||||
android-buildTools = "32.0.0"
|
||||
android-compileSdk = "33"
|
||||
android-buildTools = "33.0.0"
|
||||
|
||||
[libraries]
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.plaguposter.posts.panel
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.koin.getAllDistinct
|
||||
import dev.inmo.micro_utils.repos.deleteById
|
||||
@@ -10,8 +11,10 @@ import dev.inmo.plaguposter.common.ChatConfig
|
||||
import dev.inmo.plaguposter.posts.models.PostId
|
||||
import dev.inmo.plaguposter.posts.panel.repos.PostsMessages
|
||||
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||
import dev.inmo.tgbotapi.extensions.api.delete
|
||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
||||
@@ -19,14 +22,11 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessag
|
||||
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.extensions.utils.withContentOrNull
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.ParseMode
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.*
|
||||
@@ -41,7 +41,8 @@ object Plugin : Plugin {
|
||||
val parseMode: ParseMode? = null,
|
||||
val buttonsPerRow: Int = 4,
|
||||
val deleteButtonText: String? = null,
|
||||
val rootButtonText: String = "Return to panel"
|
||||
val rootButtonText: String = "◀️",
|
||||
val refreshButtonText: String? = "\uD83D\uDD04"
|
||||
)
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
params["panel"] ?.let { element ->
|
||||
@@ -57,6 +58,14 @@ object Plugin : Plugin {
|
||||
"delete ${it.id.string}"
|
||||
)
|
||||
}
|
||||
},
|
||||
config.refreshButtonText ?.let { text ->
|
||||
PanelButtonBuilder {
|
||||
CallbackDataInlineKeyboardButton(
|
||||
text,
|
||||
"refresh ${it.id.string}"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
PanelButtonsAPI(
|
||||
@@ -97,7 +106,7 @@ object Plugin : Plugin {
|
||||
delete(chatId, messageId)
|
||||
}
|
||||
|
||||
suspend fun updatePost(
|
||||
suspend fun refreshPostMessage(
|
||||
postId: PostId,
|
||||
chatId: ChatId,
|
||||
messageId: MessageIdentifier
|
||||
@@ -108,9 +117,10 @@ object Plugin : Plugin {
|
||||
builder.buildButton(post)
|
||||
}.takeIf { it.isNotEmpty() }
|
||||
}
|
||||
edit(
|
||||
editMessageText(
|
||||
chatId,
|
||||
messageId,
|
||||
text = config.text,
|
||||
replyMarkup = InlineKeyboardMarkup(buttons)
|
||||
)
|
||||
}
|
||||
@@ -121,7 +131,8 @@ object Plugin : Plugin {
|
||||
}
|
||||
) {
|
||||
val postId = it.data.removePrefix(PanelButtonsAPI.openGlobalMenuDataPrefix).let(::PostId)
|
||||
updatePost(postId, it.message.chat.id, it.message.messageId)
|
||||
refreshPostMessage(postId, it.message.chat.id, it.message.messageId)
|
||||
answer(it)
|
||||
}
|
||||
onMessageDataCallbackQuery(
|
||||
initialFilter = {
|
||||
@@ -140,6 +151,7 @@ object Plugin : Plugin {
|
||||
api.RootPanelButtonBuilder.buildButton(post) ?.let(::add)
|
||||
}
|
||||
)
|
||||
answer(query)
|
||||
|
||||
val pushedButton = waitMessageDataCallbackQuery().first {
|
||||
it.message.sameMessage(query.message)
|
||||
@@ -149,10 +161,27 @@ object Plugin : Plugin {
|
||||
postsRepo.deleteById(postId)
|
||||
}
|
||||
}
|
||||
onMessageDataCallbackQuery(
|
||||
initialFilter = {
|
||||
it.data.startsWith("refresh ") && it.message.chat.id == chatsConfig.sourceChatId
|
||||
}
|
||||
) { query ->
|
||||
val postId = query.data.removePrefix("refresh ").let(::PostId)
|
||||
val (chatId, messageId) = postsMessages.get(postId) ?: return@onMessageDataCallbackQuery
|
||||
|
||||
runCatchingSafely {
|
||||
refreshPostMessage(
|
||||
postId,
|
||||
chatId,
|
||||
messageId
|
||||
)
|
||||
}
|
||||
answer(query)
|
||||
}
|
||||
|
||||
api.forceRefreshFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
val (chatId, messageId) = postsMessages.get(it) ?: return@subscribeSafelyWithoutExceptions
|
||||
updatePost(it, chatId, messageId)
|
||||
refreshPostMessage(it, chatId, messageId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.strictlyOn
|
||||
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.formatting.buildEntities
|
||||
import dev.inmo.tgbotapi.extensions.utils.formatting.regular
|
||||
@@ -80,6 +81,12 @@ object Plugin : Plugin {
|
||||
}.first()
|
||||
emptyList<ContentMessage<MessageContent>>()
|
||||
}
|
||||
add {
|
||||
val finishPressed = waitCommandMessage("finish_post").filter {
|
||||
it.sameChat(messageToDelete)
|
||||
}.first()
|
||||
emptyList<ContentMessage<MessageContent>>()
|
||||
}
|
||||
}.ifEmpty {
|
||||
edit(messageToDelete, "Ok, finishing your request")
|
||||
return@strictlyOn RegistrationState.Finish(
|
||||
@@ -135,8 +142,16 @@ object Plugin : Plugin {
|
||||
koin.getOrNull<InlineTemplatesRepo>() ?.apply {
|
||||
addTemplate(
|
||||
OfferTemplate(
|
||||
"Start post",
|
||||
listOf(Format("/start_post"))
|
||||
"Start post creating",
|
||||
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"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
@@ -273,6 +292,7 @@ object Plugin : Plugin {
|
||||
attachPoll(postId)
|
||||
}
|
||||
}
|
||||
answer(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
ratings/src/commonMain/kotlin/utils/PostsByRatings.kt
Normal file
15
ratings/src/commonMain/kotlin/utils/PostsByRatings.kt
Normal 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()
|
||||
}
|
||||
@@ -13,19 +13,24 @@
|
||||
"dev.inmo.plaguposter.ratings.source.Plugin",
|
||||
"dev.inmo.plaguposter.ratings.selector.Plugin",
|
||||
"dev.inmo.plaguposter.triggers.selector_with_timer.Plugin",
|
||||
"dev.inmo.plaguposter.ratings.gc.Plugin",
|
||||
"dev.inmo.plaguposter.inlines.Plugin",
|
||||
"dev.inmo.plaguposter.triggers.command.Plugin"
|
||||
"dev.inmo.plaguposter.triggers.command.Plugin",
|
||||
"dev.inmo.plaguposter.posts.panel.Plugin"
|
||||
],
|
||||
"posts": {
|
||||
"targetChat": 12345678,
|
||||
"cacheChat": 12345678,
|
||||
"sourceChat": 12345678
|
||||
"chats": {
|
||||
"targetChat": 12345678,
|
||||
"cacheChat": 12345678,
|
||||
"sourceChat": 12345678
|
||||
}
|
||||
},
|
||||
"ratingsPolls": {
|
||||
"variants": {
|
||||
"Ok": 1,
|
||||
"Not ok": -1
|
||||
"Круть": 2,
|
||||
"Ок": 1,
|
||||
"Не ок": -1,
|
||||
"Совсем не ок": -2,
|
||||
"Посмотреть результаты": 0
|
||||
},
|
||||
"autoAttach": true,
|
||||
"ratingOfferText": "What do you think about it?"
|
||||
@@ -35,33 +40,18 @@
|
||||
{
|
||||
"time": {
|
||||
"from": "00:00",
|
||||
"to": "00:00"
|
||||
"to": "23:59"
|
||||
},
|
||||
"rating": {
|
||||
"min": 0.0,
|
||||
"max": 1.0,
|
||||
"prefer": "random"
|
||||
"prefer": "max"
|
||||
}
|
||||
},
|
||||
{
|
||||
"time": {
|
||||
"from": "00:00",
|
||||
"from": "23:59",
|
||||
"to": "00:00"
|
||||
},
|
||||
"rating": {
|
||||
"min": 0.0,
|
||||
"max": 1.0,
|
||||
"prefer": "min"
|
||||
}
|
||||
},
|
||||
{
|
||||
"time": {
|
||||
"from": "00:00",
|
||||
"to": "00:00"
|
||||
},
|
||||
"rating": {
|
||||
"min": 0.0,
|
||||
"max": 1.0,
|
||||
"prefer": "max"
|
||||
}
|
||||
}
|
||||
@@ -70,11 +60,13 @@
|
||||
"timer_trigger": {
|
||||
"krontab": "0 30 2/4 * *"
|
||||
},
|
||||
"gc": {
|
||||
"autoclear": {
|
||||
"rating": -2,
|
||||
"autoClearKrontab": "0 0 0 * *",
|
||||
"skipPostAge": 86400
|
||||
}
|
||||
"panel": {
|
||||
"textPrefix": "Post management:",
|
||||
"buttonsPerRow": 2,
|
||||
"parseMode": "MarkdownV2",
|
||||
"deleteButtonText": "Delete"
|
||||
},
|
||||
"publish_command": {
|
||||
"panelButtonText": "Publish"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user