2021-06-27 19:14:16 +00:00
|
|
|
import dev.inmo.micro_utils.coroutines.defaultSafelyExceptionHandler
|
2021-01-18 17:32:47 +00:00
|
|
|
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
2021-06-27 19:14:16 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviour
|
|
|
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
|
|
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
2021-08-08 14:32:26 +00:00
|
|
|
import dev.inmo.tgbotapi.types.*
|
2020-10-04 11:32:50 +00:00
|
|
|
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
|
|
|
|
import dev.inmo.tgbotapi.types.message.*
|
2020-06-02 14:24:41 +00:00
|
|
|
import kotlinx.coroutines.*
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This bot will always return message about forwarder. In cases when sent message was not a forward message it will
|
|
|
|
* send suitable message
|
|
|
|
*/
|
|
|
|
suspend fun main(vararg args: String) {
|
|
|
|
val botToken = args.first()
|
|
|
|
|
2021-06-27 19:14:16 +00:00
|
|
|
telegramBotWithBehaviour(botToken, CoroutineScope(Dispatchers.IO)) {
|
|
|
|
onContentMessage(includeMediaGroups = true) {
|
|
|
|
val toAnswer = buildEntities {
|
|
|
|
when (val forwardInfo = it.forwardInfo) {
|
|
|
|
null -> +"There is no forward info"
|
|
|
|
is AnonymousForwardInfo -> {
|
|
|
|
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
|
2020-06-02 14:24:41 +00:00
|
|
|
}
|
2021-06-27 19:14:16 +00:00
|
|
|
is UserForwardInfo -> {
|
|
|
|
val user = forwardInfo.from
|
2021-08-08 14:32:26 +00:00
|
|
|
when (user) {
|
|
|
|
is CommonUser -> regular("User ")
|
|
|
|
is CommonBot,
|
|
|
|
is ExtendedBot -> regular("Bot ")
|
|
|
|
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
2021-06-27 19:14:16 +00:00
|
|
|
}
|
|
|
|
is ForwardFromChannelInfo -> regular("Channel (") + code((forwardInfo.channelChat).title) + ")"
|
|
|
|
is ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).title) + ")"
|
2020-06-02 14:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-27 19:14:16 +00:00
|
|
|
reply(it, toAnswer)
|
|
|
|
coroutineContext.job.invokeOnCompletion { println("completance of onContentMessage") }
|
|
|
|
}
|
|
|
|
coroutineContext.job.invokeOnCompletion { println("Completed :)") }
|
|
|
|
}.second.join()
|
2020-06-02 14:24:41 +00:00
|
|
|
}
|