2020-10-04 11:32:50 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
|
|
import dev.inmo.tgbotapi.extensions.api.send.media.sendMediaGroup
|
2020-11-18 06:35:45 +00:00
|
|
|
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
|
|
|
import dev.inmo.micro_utils.coroutines.safely
|
2020-10-04 11:32:50 +00:00
|
|
|
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
|
2020-08-20 17:14:22 +00:00
|
|
|
import kotlinx.coroutines.*
|
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
|
|
|
|
|
suspend fun activateResenderBot(
|
|
|
|
token: String,
|
|
|
|
print: (Any) -> Unit
|
|
|
|
) {
|
|
|
|
val bot = telegramBot(token)
|
|
|
|
|
|
|
|
print(bot.getMe())
|
|
|
|
|
|
|
|
supervisorScope {
|
|
|
|
val scope = this
|
2020-10-27 10:23:27 +00:00
|
|
|
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
|
2020-08-20 17:14:22 +00:00
|
|
|
filterContentMessages<MessageContent>(scope).onEach {
|
|
|
|
it.content.createResends(it.chat.id, replyToMessageId = it.messageId).forEach {
|
2020-08-23 18:41:24 +00:00
|
|
|
bot.executeUnsafe(it) {
|
|
|
|
it.forEach(print)
|
|
|
|
} ?.also {
|
2020-08-20 17:14:22 +00:00
|
|
|
print(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.launchIn(scope)
|
2020-08-23 18:41:24 +00:00
|
|
|
mediaGroupMessages(scope).onEach {
|
|
|
|
safely({ print(it.stackTraceToString()) }) {
|
|
|
|
println(it.chat)
|
|
|
|
bot.execute(it.createResend(it.chat ?: return@safely, replyTo = it.first().messageId)).also {
|
2020-08-20 17:14:22 +00:00
|
|
|
print(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.launchIn(scope)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|