mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-12-22 14:07:14 +00:00
fixes
This commit is contained in:
parent
1f6dd7aad1
commit
4423eba1d9
@ -28,6 +28,7 @@ tgbotapi = { module = "dev.inmo:tgbotapi", version.ref = "tgbotapi" }
|
|||||||
plagubot-plugin = { module = "dev.inmo:plagubot.plugin", version.ref = "plagubot" }
|
plagubot-plugin = { module = "dev.inmo:plagubot.plugin", version.ref = "plagubot" }
|
||||||
plagubot-bot = { module = "dev.inmo:plagubot.bot", version.ref = "plagubot" }
|
plagubot-bot = { module = "dev.inmo:plagubot.bot", version.ref = "plagubot" }
|
||||||
plagubot-plugins-inline-queries = { module = "dev.inmo:plagubot.plugins.inline.queries", version.ref = "plagubot-plugins" }
|
plagubot-plugins-inline-queries = { module = "dev.inmo:plagubot.plugins.inline.queries", version.ref = "plagubot-plugins" }
|
||||||
|
plagubot-plugins-inline-buttons = { module = "dev.inmo:plagubot.plugins.inline.buttons", version.ref = "plagubot-plugins" }
|
||||||
microutils-repos-common = { module = "dev.inmo:micro_utils.repos.common", version.ref = "microutils" }
|
microutils-repos-common = { module = "dev.inmo:micro_utils.repos.common", version.ref = "microutils" }
|
||||||
microutils-repos-exposed = { module = "dev.inmo:micro_utils.repos.exposed", version.ref = "microutils" }
|
microutils-repos-exposed = { module = "dev.inmo:micro_utils.repos.exposed", version.ref = "microutils" }
|
||||||
microutils-repos-cache = { module = "dev.inmo:micro_utils.repos.cache", version.ref = "microutils" }
|
microutils-repos-cache = { module = "dev.inmo:micro_utils.repos.cache", version.ref = "microutils" }
|
||||||
|
@ -4,12 +4,20 @@ import dev.inmo.kslog.common.TagLogger
|
|||||||
import dev.inmo.kslog.common.w
|
import dev.inmo.kslog.common.w
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
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.Koin
|
||||||
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
private val actualPlugin = dev.inmo.plagubot.plugins.inline.queries.Plugin
|
private val actualPlugin = dev.inmo.plagubot.plugins.inline.queries.Plugin
|
||||||
|
|
||||||
object Plugin : Plugin by actualPlugin {
|
object Plugin : Plugin by actualPlugin {
|
||||||
private val log = TagLogger("InlinePlugin")
|
private val log = TagLogger("InlinePlugin")
|
||||||
|
|
||||||
|
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||||
|
single { actualPlugin }
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||||
log.w {
|
log.w {
|
||||||
"Built-in inline plugin has been deprecated. Use \"${actualPlugin::class.qualifiedName}\" instead"
|
"Built-in inline plugin has been deprecated. Use \"${actualPlugin::class.qualifiedName}\" instead"
|
||||||
|
@ -14,5 +14,10 @@ kotlin {
|
|||||||
api libs.microutils.koin
|
api libs.microutils.koin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jvmMain {
|
||||||
|
dependencies {
|
||||||
|
api libs.plagubot.plugins.inline.queries
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,21 @@ package dev.inmo.plaguposter.posts.panel
|
|||||||
import dev.inmo.plaguposter.posts.models.RegisteredPost
|
import dev.inmo.plaguposter.posts.models.RegisteredPost
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.InlineKeyboardButton
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.InlineKeyboardButton
|
||||||
|
|
||||||
fun interface PanelButtonBuilder {
|
interface PanelButtonBuilder {
|
||||||
|
val weight: Int
|
||||||
suspend fun buildButton(post: RegisteredPost): InlineKeyboardButton?
|
suspend fun buildButton(post: RegisteredPost): InlineKeyboardButton?
|
||||||
|
|
||||||
|
class Default(override val weight: Int = 0, private val block: suspend (RegisteredPost) -> InlineKeyboardButton?) : PanelButtonBuilder {
|
||||||
|
override suspend fun buildButton(post: RegisteredPost): InlineKeyboardButton? = block(post)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
operator fun invoke(block: suspend (RegisteredPost) -> InlineKeyboardButton?) = Default(
|
||||||
|
block = block
|
||||||
|
)
|
||||||
|
operator fun invoke(weight: Int, block: suspend (RegisteredPost) -> InlineKeyboardButton?) = Default(
|
||||||
|
weight,
|
||||||
|
block
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,14 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineK
|
|||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
|
||||||
class PanelButtonsAPI(
|
class PanelButtonsAPI(
|
||||||
private val preset: List<PanelButtonBuilder>,
|
private val preset: Map<Int, List<PanelButtonBuilder>>,
|
||||||
private val rootPanelButtonText: String
|
private val rootPanelButtonText: String
|
||||||
) {
|
) {
|
||||||
private val _buttons = mutableSetOf<PanelButtonBuilder>().also {
|
private val _buttonsMap = mutableMapOf<Int, MutableList<PanelButtonBuilder>>().also {
|
||||||
it.addAll(preset)
|
it.putAll(preset.map { it.key to it.value.toMutableList() })
|
||||||
}
|
}
|
||||||
internal val buttonsBuilders: List<PanelButtonBuilder>
|
internal val buttonsBuilders: List<PanelButtonBuilder>
|
||||||
get() = _buttons.toList()
|
get() = _buttonsMap.toList().sortedBy { it.first }.flatMap { it.second }
|
||||||
internal val forceRefreshFlow = MutableSharedFlow<PostId>()
|
internal val forceRefreshFlow = MutableSharedFlow<PostId>()
|
||||||
|
|
||||||
val RootPanelButtonBuilder = PanelButtonBuilder {
|
val RootPanelButtonBuilder = PanelButtonBuilder {
|
||||||
@ -22,8 +22,13 @@ class PanelButtonsAPI(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(button: PanelButtonBuilder) = _buttons.add(button)
|
fun add(button: PanelButtonBuilder, weight: Int = button.weight) = _buttonsMap.getOrPut(weight) { mutableListOf() }.add(button)
|
||||||
fun remove(button: PanelButtonBuilder) = _buttons.remove(button)
|
fun remove(button: PanelButtonBuilder) = _buttonsMap.mapNotNull { (k, v) ->
|
||||||
|
v.remove(button)
|
||||||
|
k.takeIf { v.isEmpty() }
|
||||||
|
}.forEach {
|
||||||
|
_buttonsMap.remove(it)
|
||||||
|
}
|
||||||
suspend fun forceRefresh(postId: PostId) {
|
suspend fun forceRefresh(postId: PostId) {
|
||||||
forceRefreshFlow.emit(postId)
|
forceRefreshFlow.emit(postId)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.benasher44.uuid.uuid4
|
|||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.koin.getAllDistinct
|
import dev.inmo.micro_utils.koin.getAllDistinct
|
||||||
|
import dev.inmo.micro_utils.koin.singleWithRandomQualifierAndBinds
|
||||||
import dev.inmo.micro_utils.repos.deleteById
|
import dev.inmo.micro_utils.repos.deleteById
|
||||||
import dev.inmo.micro_utils.repos.set
|
import dev.inmo.micro_utils.repos.set
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
@ -22,10 +23,10 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessag
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage
|
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.ChatId
|
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||||
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.SwitchInlineQueryCurrentChatInlineKeyboardButton
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.message.ParseMode
|
import dev.inmo.tgbotapi.types.message.ParseMode
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@ -70,9 +71,13 @@ object Plugin : Plugin {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
PanelButtonsAPI(
|
PanelButtonsAPI(
|
||||||
getAllDistinct<PanelButtonBuilder>() + builtInButtons,
|
emptyMap(),
|
||||||
config.rootButtonText
|
config.rootButtonText
|
||||||
)
|
).apply {
|
||||||
|
(getAllDistinct<PanelButtonBuilder>() + builtInButtons).forEach {
|
||||||
|
add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
id "org.jetbrains.kotlin.plugin.serialization"
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$mppProjectWithSerializationPresetPath"
|
apply from: "$mppProjectWithSerializationPresetPath"
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package dev.inmo.plaguposter.triggers.command
|
package dev.inmo.plaguposter.triggers.command
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
import com.benasher44.uuid.uuid4
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.micro_utils.fsm.common.State
|
import dev.inmo.micro_utils.fsm.common.State
|
||||||
import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination
|
|
||||||
import dev.inmo.plagubot.Plugin
|
import dev.inmo.plagubot.Plugin
|
||||||
import dev.inmo.plaguposter.common.SuccessfulSymbol
|
import dev.inmo.plaguposter.common.SuccessfulSymbol
|
||||||
import dev.inmo.plaguposter.common.UnsuccessfulSymbol
|
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
import dev.inmo.plagubot.plugins.inline.queries.models.Format
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
import dev.inmo.plagubot.plugins.inline.queries.models.OfferTemplate
|
||||||
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
import dev.inmo.plagubot.plugins.inline.queries.repos.InlineTemplatesRepo
|
||||||
@ -16,14 +13,10 @@ import dev.inmo.plaguposter.posts.panel.PanelButtonsAPI
|
|||||||
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
import dev.inmo.plaguposter.posts.repo.PostsRepo
|
||||||
import dev.inmo.plaguposter.posts.sending.PostPublisher
|
import dev.inmo.plaguposter.posts.sending.PostPublisher
|
||||||
import dev.inmo.plaguposter.ratings.selector.Selector
|
import dev.inmo.plaguposter.ratings.selector.Selector
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitTextMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.strictlyOn
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
@ -33,9 +26,7 @@ import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
|||||||
import dev.inmo.tgbotapi.types.ChatId
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.regular
|
import dev.inmo.tgbotapi.types.message.textsources.regular
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
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.*
|
||||||
|
Loading…
Reference in New Issue
Block a user