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.send.media.sendMediaGroup
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.updates.retrieving.startGettingFlowsUpdatesByLongPolling
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlin.coroutines.coroutineContext
suspend fun activateResenderBot(
token: String,
@ -18,26 +16,24 @@ suspend fun activateResenderBot(
print(bot.getMe())
supervisorScope {
val scope = this
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
filterContentMessages<MessageContent>(scope).onEach {
it.content.createResends(it.chat.id, replyToMessageId = it.messageId).forEach {
bot.executeUnsafe(it) {
it.forEach(print)
} ?.also {
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)
bot.buildBehaviour(CoroutineScope(coroutineContext + SupervisorJob())) {
onContentMessage(
additionalFilter = { it !is MediaGroupMessage<*> }
) {
it.content.createResends(it.chat.id, replyToMessageId = it.messageId).forEach {
executeUnsafe(it) {
it.forEach(print)
} ?.also(print)
}
}
}
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
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
zipStoreBase=GRADLE_USER_HOME
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