mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-24 02:58:49 +00:00
update up to 0.36.0
This commit is contained in:
parent
be2de6e372
commit
d89202aebb
@ -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"
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user