diff --git a/FSMBot/src/main/kotlin/SimpleFSMBot.kt b/FSMBot/src/main/kotlin/SimpleFSMBot.kt index 9b37e22..707cf17 100644 --- a/FSMBot/src/main/kotlin/SimpleFSMBot.kt +++ b/FSMBot/src/main/kotlin/SimpleFSMBot.kt @@ -6,17 +6,21 @@ 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.extensions.sameThread import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.utils.botCommand +import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import kotlinx.coroutines.* +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.first sealed interface BotState : State -data class ExpectContentOrStopState(override val context: ChatId, val sourceMessage: CommonMessage) : BotState -data class StopState(override val context: ChatId) : BotState +data class ExpectContentOrStopState(override val context: Pair, val sourceMessage: CommonMessage) : BotState +data class StopState(override val context: Pair) : BotState suspend fun main(args: Array) { val botToken = args.first() @@ -39,30 +43,35 @@ suspend fun main(args: Array) { ) { strictlyOn { send( - it.context + it.context.first, + threadId = it.context.second ) { +"Send me some content or " + botCommand("stop") + " if you want to stop sending" } - val contentMessage = waitContentMessage().first() + val contentMessage = waitContentMessage().filter { message -> + message.sameThread(it.sourceMessage) + }.first() val content = contentMessage.content when { content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context) else -> { - execute(content.createResend(it.context)) + execute(content.createResend(it.context.first, messageThreadId = it.context.second)) it } } } strictlyOn { - send(it.context) { +"You have stopped sending of content" } + send(it.context.first, threadId = it.context.second) { +"You have stopped sending of content" } null } - command("start") { - startChain(ExpectContentOrStopState(it.chat.id, it)) + command( + "start" + ) { + startChain(ExpectContentOrStopState(it.chat.id to it.threadIdOrNull, it)) } }.second.join() } diff --git a/GetMeBot/src/main/kotlin/GetMeBot.kt b/GetMeBot/src/main/kotlin/GetMeBot.kt index aa883dd..78c18f5 100644 --- a/GetMeBot/src/main/kotlin/GetMeBot.kt +++ b/GetMeBot/src/main/kotlin/GetMeBot.kt @@ -1,5 +1,16 @@ import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.bot.getMe +import dev.inmo.tgbotapi.extensions.api.chat.forum.closeForumTopic +import dev.inmo.tgbotapi.extensions.api.chat.forum.createForumTopic +import dev.inmo.tgbotapi.extensions.api.chat.forum.deleteForumTopic +import dev.inmo.tgbotapi.extensions.api.chat.forum.reopenForumTopic +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onForumTopicClosed +import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.CustomEmojiId +import dev.inmo.tgbotapi.types.ForumTopic +import kotlinx.coroutines.delay /** * This is one of the most easiest bot - it will just print information about itself diff --git a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt index 1eb6d17..cec4079 100644 --- a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt +++ b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt @@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilte import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.utils.shortcuts.* +import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import kotlinx.coroutines.* suspend fun activateResenderBot( @@ -20,33 +21,23 @@ suspend fun activateResenderBot( bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) { onContentMessage( - initialFilter = CommonMessageFilterExcludeMediaGroups, - subcontextUpdatesFilter = MessageFilterByChat + subcontextUpdatesFilter = MessageFilterByChat, ) { val chat = it.chat - withTypingAction(chat) { - executeUnsafe(it.content.createResend(chat.id, replyToMessageId = it.messageId)) { + + val answer = withTypingAction(chat) { + executeUnsafe( + it.content.createResend( + chat.id, + messageThreadId = it.threadIdOrNull, + replyToMessageId = it.messageId + ) + ) { it.forEach(print) } } - } - onVisualGallery { - val chat = it.chat ?: return@onVisualGallery - withUploadPhotoAction(chat) { - send(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() }) - } - } - onPlaylist { - val chat = it.chat ?: return@onPlaylist - withUploadDocumentAction(chat) { - send(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() }) - } - } - onDocumentsGroup { - val chat = it.chat ?: return@onDocumentsGroup - withUploadDocumentAction(chat) { - send(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() }) - } + + println("Answer info: $answer") } allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { diff --git a/gradle.properties b/gradle.properties index a5ec16a..7b0a235 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx768m kotlin_version=1.7.20 -telegram_bot_api_version=3.3.1 +telegram_bot_api_version=4.0.0 micro_utils_version=0.13.2 serialization_version=1.4.1 ktor_version=2.1.3