From 6fd85dbc5654c4ead818080f63638013b235a032 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Jun 2022 00:16:23 +0600 Subject: [PATCH 1/5] start 2.0.3 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e98bbfd484..11fa4d21af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 2.0.3 + ## 2.0.2 * `Versions`: diff --git a/gradle.properties b/gradle.properties index dedcd0547a..380afb49f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,6 @@ javax_activation_version=1.1.1 dokka_version=1.6.21 library_group=dev.inmo -library_version=2.0.2 +library_version=2.0.3 github_release_plugin_version=2.3.7 From 8081602a392db424f457ef1b65db008db6d3bb2f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Jun 2022 00:20:30 +0600 Subject: [PATCH 2/5] update microutils --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11fa4d21af..2267be580d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 2.0.3 +* `Versions`: + * `MicroUtils`: `0.11.0` -> `0.11.3` + ## 2.0.2 * `Versions`: diff --git a/gradle.properties b/gradle.properties index 380afb49f2..f4c04cfdb8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ korlibs_version=2.7.0 uuid_version=0.4.1 ktor_version=2.0.2 -micro_utils_version=0.11.0 +micro_utils_version=0.11.3 javax_activation_version=1.1.1 From 8243acd69e6aa88be986269b520461697c54df8f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Jun 2022 02:51:22 +0600 Subject: [PATCH 3/5] regularln --- CHANGELOG.md | 2 ++ .../tgbotapi/types/message/textsources/RegularTextSource.kt | 3 +++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2267be580d..c1693d3fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 2.0.3 +* `Core`: + * New function `regularln` for simple creating of `RegularTextSource` with new line in the end * `Versions`: * `MicroUtils`: `0.11.0` -> `0.11.3` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/RegularTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/RegularTextSource.kt index ce6f65b086..4593f54121 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/RegularTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/RegularTextSource.kt @@ -18,3 +18,6 @@ data class RegularTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo @Suppress("NOTHING_TO_INLINE") inline fun regular(text: String) = RegularTextSource(text) + +@Suppress("NOTHING_TO_INLINE") +inline fun regularln(text: String) = regular("$text\n") From c7818fe4dfe2dd4bd83be7137d2b27afa9ece1d8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Jun 2022 11:04:31 +0600 Subject: [PATCH 4/5] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f4c04cfdb8..7f7862a783 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,4 +22,4 @@ dokka_version=1.6.21 library_group=dev.inmo library_version=2.0.3 -github_release_plugin_version=2.3.7 +github_release_plugin_version=2.4.1 From ff7702486f6f2cab9f1f6a4961f1fce23f8d28b0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 17 Jun 2022 13:49:33 +0600 Subject: [PATCH 5/5] downloadFileToTemp --- CHANGELOG.md | 2 + .../api/files/DownloadFileToTempFile.kt | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tgbotapi.api/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileToTempFile.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c1693d3fcd..de906bdf97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * `Core`: * New function `regularln` for simple creating of `RegularTextSource` with new line in the end +* `API`: + * New function `downloadFileToTemp` for simple downloading of file in filesystem and manipulation with avoiding of direct using input streams and other low-level things * `Versions`: * `MicroUtils`: `0.11.0` -> `0.11.3` diff --git a/tgbotapi.api/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileToTempFile.kt b/tgbotapi.api/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileToTempFile.kt new file mode 100644 index 0000000000..299e9d1ddd --- /dev/null +++ b/tgbotapi.api/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/api/files/DownloadFileToTempFile.kt @@ -0,0 +1,57 @@ +package dev.inmo.tgbotapi.extensions.api.files + +import com.benasher44.uuid.uuid4 +import dev.inmo.micro_utils.common.filename +import dev.inmo.micro_utils.coroutines.doOutsideOfCoroutine +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo +import dev.inmo.tgbotapi.requests.abstracts.FileId +import dev.inmo.tgbotapi.types.files.PathedFile +import dev.inmo.tgbotapi.types.files.TelegramMediaFile +import dev.inmo.tgbotapi.types.message.content.MediaContent +import dev.inmo.tgbotapi.utils.fileExtension +import io.ktor.util.cio.use +import io.ktor.util.cio.writeChannel +import io.ktor.utils.io.copyTo +import kotlinx.coroutines.job +import java.io.File +import kotlin.coroutines.coroutineContext + +suspend fun TelegramBot.downloadFileToTemp( + filePath: String +): File { + return downloadFile( + filePath, + File.createTempFile(uuid4().toString(), "_temp").apply { + deleteOnExit() + } + ) +} + +suspend fun TelegramBot.downloadFileToTemp( + pathedFile: PathedFile +) = downloadFileToTemp( + pathedFile.filePath +).apply { + runCatching { + renameTo(File(parentFile, "$nameWithoutExtension.${pathedFile.fileName.fileExtension}")) + } +} + +suspend fun TelegramBot.downloadFileToTemp( + fileId: FileId +) = downloadFileToTemp( + getFileAdditionalInfo(fileId) +) + +suspend fun TelegramBot.downloadFileToTemp( + file: TelegramMediaFile +): File = downloadFileToTemp( + getFileAdditionalInfo(file) +) + +suspend fun TelegramBot.downloadFileToTemp( + file: MediaContent +) = downloadFileToTemp( + getFileAdditionalInfo(file.media) +)