update up to 0.36.0

This commit is contained in:
InsanusMokrassar 2021-10-18 17:14:40 +06:00
parent be2de6e372
commit d89202aebb
3 changed files with 28 additions and 40 deletions

View File

@ -1,6 +1,7 @@
buildscript { buildscript {
repositories { repositories {
jcenter() mavenLocal()
mavenCentral()
} }
dependencies { dependencies {
@ -13,10 +14,13 @@ apply plugin: 'application'
mainClassName="SimpleFSMBotKt" mainClassName="SimpleFSMBotKt"
repositories {
mavenLocal()
mavenCentral()
}
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version" implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
implementation "dev.inmo:micro_utils.fsm.common:$micro_utils_version"
} }

View File

@ -1,20 +1,13 @@
import dev.inmo.micro_utils.fsm.common.State import dev.inmo.micro_utils.fsm.common.State
import dev.inmo.micro_utils.fsm.common.dsl.buildFSM
import dev.inmo.micro_utils.fsm.common.dsl.strictlyOn
import dev.inmo.tgbotapi.extensions.api.send.media.sendMediaGroup
import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.api.send.sendMessage import dev.inmo.tgbotapi.extensions.api.send.sendMessage
import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
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.parseCommandsWithParams import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.extensions.utils.formatting.*
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import kotlinx.coroutines.* import kotlinx.coroutines.*
sealed interface BotState : State sealed interface BotState : State
@ -24,8 +17,7 @@ data class StopState(override val context: ChatId) : BotState
suspend fun main(args: Array<String>) { suspend fun main(args: Array<String>) {
val botToken = args.first() val botToken = args.first()
telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) { telegramBotWithBehaviourAndFSMAndStartLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
val fsm = buildFSM {
strictlyOn<ExpectContentOrStopState> { strictlyOn<ExpectContentOrStopState> {
sendMessage( sendMessage(
it.context, it.context,
@ -34,31 +26,23 @@ suspend fun main(args: Array<String>) {
} }
) )
doInSubContext(stopOnCompletion = false) { val content = waitContentMessage().first()
val behaviourSubcontext = this when {
onContentMessage( content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
initialFilter = { message -> message.chat.id == it.context } else -> {
) { message -> execute(content.createResend(it.context))
execute(message.content.createResend(it.context)) it
} }
onCommand("stop") {
behaviourSubcontext.cancel()
} }
}.join()
StopState(it.context)
} }
strictlyOn<StopState> { strictlyOn<StopState> {
sendMessage(it.context, "You have stopped sending of content") sendMessage(it.context, "You have stopped sending of content")
null null
} }
}
command("start") { command("start") {
fsm.startChain(ExpectContentOrStopState(it.chat.id, it)) startChain(ExpectContentOrStopState(it.chat.id, it))
} }
fsm.start(this)
}.second.join() }.second.join()
} }

View File

@ -3,5 +3,5 @@ org.gradle.parallel=true
kotlin_version=1.5.31 kotlin_version=1.5.31
telegram_bot_api_version=0.35.9 telegram_bot_api_version=0.36.0
micro_utils_version=0.5.31 micro_utils_version=0.7.2