2022-01-02 06:06:32 +00:00
|
|
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
2020-10-04 11:32:50 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
2022-05-10 18:23:14 +00:00
|
|
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
2022-03-24 10:52:13 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
2021-02-01 06:57:39 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.api.send.media.*
|
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
2022-03-21 05:25:59 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilterExcludeMediaGroups
|
2021-09-21 17:22:13 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
2021-02-01 06:57:39 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
2020-10-04 11:32:50 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
2024-01-08 09:46:23 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
|
|
|
import dev.inmo.tgbotapi.types.ReplyParameters
|
2024-04-18 14:06:59 +00:00
|
|
|
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
|
2024-01-08 09:46:23 +00:00
|
|
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
|
|
|
import dev.inmo.tgbotapi.types.quoteEntitiesField
|
2022-11-08 11:00:53 +00:00
|
|
|
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
2020-08-20 17:14:22 +00:00
|
|
|
import kotlinx.coroutines.*
|
|
|
|
|
|
|
|
suspend fun activateResenderBot(
|
|
|
|
token: String,
|
|
|
|
print: (Any) -> Unit
|
|
|
|
) {
|
2023-04-19 14:20:11 +00:00
|
|
|
telegramBotWithBehaviourAndLongPolling(token, scope = CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
2021-02-01 06:57:39 +00:00
|
|
|
onContentMessage(
|
2022-11-08 11:49:41 +00:00
|
|
|
subcontextUpdatesFilter = MessageFilterByChat,
|
2024-04-18 14:06:59 +00:00
|
|
|
initialFilter = { it !is BusinessContentMessage<*> || !it.sentByBusinessConnectionOwner }
|
2021-02-01 06:57:39 +00:00
|
|
|
) {
|
2022-03-24 10:52:13 +00:00
|
|
|
val chat = it.chat
|
2022-11-08 06:19:23 +00:00
|
|
|
|
|
|
|
val answer = withTypingAction(chat) {
|
2022-11-08 11:00:53 +00:00
|
|
|
executeUnsafe(
|
|
|
|
it.content.createResend(
|
|
|
|
chat.id,
|
|
|
|
messageThreadId = it.threadIdOrNull,
|
2024-01-08 09:46:23 +00:00
|
|
|
replyParameters = it.replyInfo ?.messageMeta ?.let { meta ->
|
|
|
|
val quote = it.withContentOrNull<TextContent>() ?.content ?.quote
|
|
|
|
ReplyParameters(
|
|
|
|
meta,
|
|
|
|
entities = quote ?.textSources ?: emptyList(),
|
|
|
|
quotePosition = quote ?.position
|
|
|
|
)
|
|
|
|
}
|
2022-11-08 11:00:53 +00:00
|
|
|
)
|
|
|
|
) {
|
2022-08-13 08:39:24 +00:00
|
|
|
it.forEach(print)
|
|
|
|
}
|
2022-03-24 10:52:13 +00:00
|
|
|
}
|
2022-11-08 06:19:23 +00:00
|
|
|
|
|
|
|
println("Answer info: $answer")
|
2021-02-01 06:57:39 +00:00
|
|
|
}
|
2022-01-02 06:06:32 +00:00
|
|
|
|
|
|
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
|
|
println(it)
|
|
|
|
}
|
2023-04-19 14:20:11 +00:00
|
|
|
print(bot.getMe())
|
|
|
|
}.second.join()
|
2020-08-20 17:14:22 +00:00
|
|
|
}
|