first fully ready for trying system
This commit is contained in:
@@ -12,6 +12,7 @@ import dev.inmo.tgbotapi.requests.send.SendTextMessage
|
||||
import dev.inmo.tgbotapi.requests.send.media.*
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.utils.StorageFile
|
||||
import dev.inmo.tgbotapi.utils.StorageFileInfo
|
||||
import io.ktor.utils.io.ByteReadChannel
|
||||
import io.ktor.utils.io.core.readBytes
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -25,7 +26,9 @@ class PublicationTargetTelegram(
|
||||
when (val content = it.content) {
|
||||
is BinaryContent -> {
|
||||
val storageFile by lazy {
|
||||
StorageFile(content.filename.name, content.inputProvider().readBytes()).asMultipartFile()
|
||||
StorageFile(StorageFileInfo(content.filename.name)) {
|
||||
content.inputProvider()
|
||||
}.asMultipartFile()
|
||||
}
|
||||
when (content.mimeType) {
|
||||
is KnownMimeTypes.Image.Jpeg,
|
||||
@@ -38,7 +41,10 @@ class PublicationTargetTelegram(
|
||||
is KnownMimeTypes.Audio.Mpeg -> {
|
||||
SendAudio(targetChatId, storageFile)
|
||||
}
|
||||
else -> null
|
||||
else -> SendDocument(
|
||||
targetChatId,
|
||||
storageFile
|
||||
)
|
||||
}
|
||||
}
|
||||
is TextContent -> {
|
||||
@@ -47,7 +53,16 @@ class PublicationTargetTelegram(
|
||||
else -> null
|
||||
}
|
||||
}.forEach { request ->
|
||||
bot.executeUnsafe(request, 3, 1000L)
|
||||
repeat(3) {
|
||||
runCatching {
|
||||
bot.execute(request)
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
}.onSuccess {
|
||||
return@forEach
|
||||
}
|
||||
delay(1000L)
|
||||
}
|
||||
delay(100L)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user