rework of multipart files with fixes in new sticker sets

This commit is contained in:
InsanusMokrassar committed 2023-03-11 21:17:59 +06:00
1 parent 6722ab5f50
commit e5a48e9684
18 files changed
+295 -139

No files matched your search

@@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.types.files.TelegramMediaFile
import dev.inmo.tgbotapi.types.message.content.MediaContent
import io.ktor.util.cio.use
import io.ktor.util.cio.writeChannel
import io.ktor.utils.io.copyAndClose
import io.ktor.utils.io.copyTo
import kotlinx.coroutines.job
import java.io.File
@@ -25,7 +26,7 @@ suspend fun TelegramBot.downloadFile(
doOutsideOfCoroutine { destFile.createNewFile() }
destFile.writeChannel(coroutineContext.job).use {
readChannel.copyTo(this)
readChannel.copyAndClose(this)
}
return destFile
@@ -30,11 +30,17 @@ suspend fun TelegramBot.downloadFileToTemp(
suspend fun TelegramBot.downloadFileToTemp(
pathedFile: PathedFile
) = downloadFileToTemp(
): File = downloadFileToTemp(
pathedFile.filePath
).apply {
runCatching {
renameTo(File(parentFile, "$nameWithoutExtension.${pathedFile.fileName.fileExtension}"))
).run {
val newFile = File(parentFile, "$nameWithoutExtension.${pathedFile.fileName.fileExtension}")
val success = runCatching {
renameTo(newFile)
}.getOrElse { false }
if (success) {
newFile
} else {
this@run
}
}