TelegramBotAPI-examples/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt

40 lines
1.4 KiB
Kotlin
Raw Normal View History

2020-10-04 11:32:50 +00:00
import dev.inmo.tgbotapi.extensions.api.bot.getMe
2020-11-18 06:35:45 +00:00
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.extensions.api.send.media.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
2020-10-04 11:32:50 +00:00
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import kotlinx.coroutines.*
import kotlin.coroutines.coroutineContext
suspend fun activateResenderBot(
token: String,
print: (Any) -> Unit
) {
val bot = telegramBot(token)
print(bot.getMe())
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()
}