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

36 lines
1.3 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<*> }
) {
2021-03-12 09:48:31 +00:00
executeUnsafe(it.content.createResend(it.chat.id, replyToMessageId = it.messageId))
}
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()
}