1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-05 00:10:07 +00:00

Compare commits

..

6 Commits

Author SHA1 Message Date
e74f339ae2
Merge pull request #609 from InsanusMokrassar/2.0.3
2.0.3
2022-06-17 14:34:23 +06:00
ff7702486f downloadFileToTemp 2022-06-17 13:49:44 +06:00
c7818fe4df
Update gradle.properties 2022-06-17 11:04:31 +06:00
8243acd69e regularln 2022-06-17 02:51:22 +06:00
8081602a39 update microutils 2022-06-17 00:20:30 +06:00
6fd85dbc56 start 2.0.3 2022-06-17 00:16:23 +06:00
4 changed files with 72 additions and 3 deletions

View File

@ -1,5 +1,14 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 2.0.3
* `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`
## 2.0.2 ## 2.0.2
* `Versions`: * `Versions`:

View File

@ -12,7 +12,7 @@ korlibs_version=2.7.0
uuid_version=0.4.1 uuid_version=0.4.1
ktor_version=2.0.2 ktor_version=2.0.2
micro_utils_version=0.11.0 micro_utils_version=0.11.3
javax_activation_version=1.1.1 javax_activation_version=1.1.1
@ -20,6 +20,6 @@ javax_activation_version=1.1.1
dokka_version=1.6.21 dokka_version=1.6.21
library_group=dev.inmo library_group=dev.inmo
library_version=2.0.2 library_version=2.0.3
github_release_plugin_version=2.3.7 github_release_plugin_version=2.4.1

View File

@ -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)
)

View File

@ -18,3 +18,6 @@ data class RegularTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun regular(text: String) = RegularTextSource(text) inline fun regular(text: String) = RegularTextSource(text)
@Suppress("NOTHING_TO_INLINE")
inline fun regularln(text: String) = regular("$text\n")