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 {
|
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"
|
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user