diff --git a/FSMBot/src/main/kotlin/SimpleFSMBot.kt b/FSMBot/src/main/kotlin/SimpleFSMBot.kt index c5b6c21..030299a 100644 --- a/FSMBot/src/main/kotlin/SimpleFSMBot.kt +++ b/FSMBot/src/main/kotlin/SimpleFSMBot.kt @@ -1,4 +1,5 @@ import dev.inmo.micro_utils.coroutines.AccumulatorFlow +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.fsm.common.State import dev.inmo.tgbotapi.extensions.api.send.send import dev.inmo.tgbotapi.extensions.api.send.sendMessage @@ -8,6 +9,8 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread import dev.inmo.tgbotapi.extensions.utils.formatting.* +import dev.inmo.tgbotapi.extensions.utils.textContentOrNull +import dev.inmo.tgbotapi.extensions.utils.withContentOrNull import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage @@ -54,7 +57,8 @@ suspend fun main(args: Array) { val content = contentMessage.content when { - content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context) + content is TextContent && content.text == "/stop" + || content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context) else -> { execute(content.createResend(it.context)) it @@ -72,5 +76,17 @@ suspend fun main(args: Array) { ) { startChain(ExpectContentOrStopState(it.chat.id, it)) } + + onContentMessage( + { + it.content.textContentOrNull() ?.text == "/start" + } + ) { + startChain(ExpectContentOrStopState(it.chat.id, it.withContentOrNull() ?: return@onContentMessage)) + } + + allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { + println(it) + } }.second.join() } diff --git a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt index 52e566c..4bbf65b 100644 --- a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt +++ b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt @@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.utils.shortcuts.* import dev.inmo.tgbotapi.extensions.utils.withContentOrNull import dev.inmo.tgbotapi.types.ReplyParameters +import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.quoteEntitiesField import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull @@ -22,6 +23,7 @@ suspend fun activateResenderBot( telegramBotWithBehaviourAndLongPolling(token, scope = CoroutineScope(currentCoroutineContext() + SupervisorJob())) { onContentMessage( subcontextUpdatesFilter = MessageFilterByChat, + initialFilter = { it !is BusinessContentMessage<*> || !it.sentByBusinessConnectionOwner } ) { val chat = it.chat diff --git a/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt b/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt index 9cefc7a..db0c802 100644 --- a/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt +++ b/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt @@ -83,7 +83,7 @@ suspend fun main(args: Array) { getStickerSet(stickerSetName).stickers.last() ) } - }.onFailure { _ -> + }.onFailure { exception -> createNewStickerSet( it.chat.id.toChatId(), stickerSetName.string,