This commit is contained in:
InsanusMokrassar 2021-03-12 15:48:31 +06:00
parent aa89a289ce
commit 9e0f43dcc0
7 changed files with 19 additions and 15 deletions

View File

@ -4,7 +4,7 @@ import dev.inmo.tgbotapi.extensions.api.downloadFile
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
import dev.inmo.tgbotapi.extensions.utils.flatMap
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
import dev.inmo.tgbotapi.utils.filenameFromUrl
import kotlinx.coroutines.*
@ -22,7 +22,7 @@ suspend fun main(args: Array<String>) {
val bot = telegramBot(botToken)
val scope = CoroutineScope(Dispatchers.Default)
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
bot.longPolling(scope = scope) {
val flow = merge (
filterContentMessages<MediaContent>(),
mediaGroupMessages().flatMap()

View File

@ -7,10 +7,9 @@ import dev.inmo.tgbotapi.extensions.utils.formatting.codeMarkdownV2
import dev.inmo.tgbotapi.extensions.utils.formatting.regularMarkdownV2
import dev.inmo.tgbotapi.extensions.utils.shortcuts.mediaGroupMessages
import dev.inmo.tgbotapi.extensions.utils.updates.asContentMessagesFlow
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
import dev.inmo.tgbotapi.types.message.*
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
@ -25,7 +24,7 @@ suspend fun main(vararg args: String) {
val scope = CoroutineScope(Dispatchers.Default)
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
bot.longPolling(scope = scope) {
(merge(messageFlow.asContentMessagesFlow(), mediaGroupMessages(scope).flatMap())).mapNotNull { it.asPossiblyForwardedMessage() }.onEach { message ->
safely({ it.printStackTrace() }) {
val toAnswer = when (val forwardInfo = message.forwardInfo) {

View File

@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.extensions.utils.asChannelChat
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.abstracts.*
@ -25,7 +25,7 @@ suspend fun main(vararg args: String) {
val scope = CoroutineScope(Dispatchers.Default)
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
bot.longPolling(scope = scope) {
messageFlow.onEach {
safely {
val message = it.data

View File

@ -20,11 +20,7 @@ suspend fun activateResenderBot(
onContentMessage(
additionalFilter = { it !is MediaGroupMessage<*> }
) {
it.content.createResends(it.chat.id, replyToMessageId = it.messageId).forEach {
executeUnsafe(it) {
it.forEach(print)
} ?.also(print)
}
executeUnsafe(it.content.createResend(it.chat.id, replyToMessageId = it.messageId))
}
onVisualGallery {
sendVisualMediaGroup(it.chat!!, it.map { it.content.toMediaGroupMemberInputMedia() })

View File

@ -3,7 +3,7 @@ import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.extensions.utils.shortcuts.filterContentMessages
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
import dev.inmo.tgbotapi.types.message.content.DiceContent
import kotlinx.coroutines.*
@ -14,7 +14,7 @@ suspend fun main(args: Array<String>) {
val bot = telegramBot(args.first())
val scope = CoroutineScope(Dispatchers.Default)
bot.startGettingFlowsUpdatesByLongPolling(scope = scope) {
bot.longPolling(scope = scope) {
filterContentMessages<DiceContent>(scope).onEach {
val content = it.content
val dice = content.dice

View File

@ -2,5 +2,14 @@ allprojects {
repositories {
mavenLocal()
jcenter()
if (project.hasProperty("GITHUB_USER") && project.hasProperty("GITHUB_TOKEN")) {
maven {
url "https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"
credentials {
username = project.getProperty("GITHUB_USER")
password = project.getProperty("GITHUB_TOKEN")
}
}
}
}
}

View File

@ -2,4 +2,4 @@ kotlin.code.style=official
org.gradle.parallel=true
kotlin_version=1.4.31
telegram_bot_api_version=0.32.8
telegram_bot_api_version=0.33.0