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 {
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
@ -13,10 +14,13 @@ apply plugin: 'application'
mainClassName="SimpleFSMBotKt"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_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.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.behaviour_builder.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
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.message.abstracts.CommonMessage
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.*
sealed interface BotState : State
@ -24,8 +17,7 @@ data class StopState(override val context: ChatId) : BotState
suspend fun main(args: Array<String>) {
val botToken = args.first()
telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) {
val fsm = buildFSM {
telegramBotWithBehaviourAndFSMAndStartLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
strictlyOn<ExpectContentOrStopState> {
sendMessage(
it.context,
@ -34,31 +26,23 @@ suspend fun main(args: Array<String>) {
}
)
doInSubContext(stopOnCompletion = false) {
val behaviourSubcontext = this
onContentMessage(
initialFilter = { message -> message.chat.id == it.context }
) { message ->
execute(message.content.createResend(it.context))
val content = waitContentMessage().first()
when {
content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
else -> {
execute(content.createResend(it.context))
it
}
onCommand("stop") {
behaviourSubcontext.cancel()
}
}.join()
StopState(it.context)
}
strictlyOn<StopState> {
sendMessage(it.context, "You have stopped sending of content")
null
}
}
command("start") {
fsm.startChain(ExpectContentOrStopState(it.chat.id, it))
startChain(ExpectContentOrStopState(it.chat.id, it))
}
fsm.start(this)
}.second.join()
}

View File

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