update tgbotapi version up to 0.32.1, gradle wrapper and resender bot logic according to update of tgbotapi

This commit is contained in:
InsanusMokrassar 2021-02-01 12:57:39 +06:00
parent f5b526e0c5
commit ccb29d6977
3 changed files with 26 additions and 30 deletions

View File

@ -1,14 +1,12 @@
import dev.inmo.tgbotapi.extensions.api.bot.getMe import dev.inmo.tgbotapi.extensions.api.bot.getMe
import dev.inmo.tgbotapi.extensions.api.send.media.sendMediaGroup
import dev.inmo.tgbotapi.bot.Ktor.telegramBot import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.extensions.api.send.media.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
import dev.inmo.tgbotapi.extensions.utils.shortcuts.* import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.flow.launchIn import kotlin.coroutines.coroutineContext
import kotlinx.coroutines.flow.onEach
suspend fun activateResenderBot( suspend fun activateResenderBot(
token: String, token: String,
@ -18,26 +16,24 @@ suspend fun activateResenderBot(
print(bot.getMe()) print(bot.getMe())
supervisorScope { bot.buildBehaviour(CoroutineScope(coroutineContext + SupervisorJob())) {
val scope = this onContentMessage(
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) { additionalFilter = { it !is MediaGroupMessage<*> }
filterContentMessages<MessageContent>(scope).onEach { ) {
it.content.createResends(it.chat.id, replyToMessageId = it.messageId).forEach { it.content.createResends(it.chat.id, replyToMessageId = it.messageId).forEach {
bot.executeUnsafe(it) { executeUnsafe(it) {
it.forEach(print) it.forEach(print)
} ?.also { } ?.also(print)
print(it) }
}
}
}.launchIn(scope)
mediaGroupMessages(scope).onEach {
safely({ print(it.stackTraceToString()) }) {
println(it.chat)
bot.execute(it.createResend(it.chat ?: return@safely, replyTo = it.first().messageId)).also {
print(it)
}
}
}.launchIn(scope)
} }
} onVisualGallery {
sendVisualMediaGroup(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() })
}
onPlaylist {
sendPlaylist(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() })
}
onDocumentsGroup {
sendDocumentsGroup(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() })
}
}.join()
} }

View File

@ -2,4 +2,4 @@ kotlin.code.style=official
org.gradle.parallel=true org.gradle.parallel=true
kotlin_version=1.4.21 kotlin_version=1.4.21
telegram_bot_api_version=0.31.0 telegram_bot_api_version=0.32.1

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip