mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-12-17 03:35:45 +00:00
Compare commits
20 Commits
2.0.0
...
ff7702486f
| Author | SHA1 | Date | |
|---|---|---|---|
| ff7702486f | |||
| c7818fe4df | |||
| 8243acd69e | |||
| 8081602a39 | |||
| 6fd85dbc56 | |||
| 8d6f4ba136 | |||
| b95b339ad1 | |||
| 637979100b | |||
| 4067439a13 | |||
| 03583ff6c1 | |||
| c1330f8e32 | |||
| db36c6aacb | |||
| 757e317e70 | |||
| cb708a1ba4 | |||
| 551276f78e | |||
| 88339a4977 | |||
| a13371e14c | |||
| ad7fdc6211 | |||
| c870a48a22 | |||
| 3149fd0231 |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,5 +1,28 @@
|
||||
# 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
|
||||
|
||||
* `Versions`:
|
||||
* `MicroUtils`: `0.10.8` -> `0.11.0`
|
||||
* `UUID`: `0.4.0` -> `0.4.1`
|
||||
|
||||
## 2.0.1
|
||||
|
||||
* `Versions`:
|
||||
* `Ktor`: `2.0.1` -> `2.0.2`
|
||||
* `MicroUtils`: `0.10.5` -> `0.10.8`
|
||||
* `Utils`:
|
||||
* `TelegramBot#longPolling` now accepts `UpdatesFilter` instead of `FlowsUpdatesFilter`
|
||||
|
||||
## 2.0.0
|
||||
|
||||
___ALL PREVIOUS DEPRECATIONS HAVE BEEN REMOVED___
|
||||
|
||||
@@ -9,10 +9,10 @@ kotlin_version=1.6.21
|
||||
kotlin_coroutines_version=1.6.1
|
||||
kotlin_serialisation_runtime_version=1.3.3
|
||||
korlibs_version=2.7.0
|
||||
uuid_version=0.4.0
|
||||
ktor_version=2.0.1
|
||||
uuid_version=0.4.1
|
||||
ktor_version=2.0.2
|
||||
|
||||
micro_utils_version=0.10.5
|
||||
micro_utils_version=0.11.3
|
||||
|
||||
javax_activation_version=1.1.1
|
||||
|
||||
@@ -20,6 +20,6 @@ javax_activation_version=1.1.1
|
||||
dokka_version=1.6.21
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=2.0.0
|
||||
library_version=2.0.3
|
||||
|
||||
github_release_plugin_version=2.3.7
|
||||
github_release_plugin_version=2.4.1
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
@@ -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")
|
||||
|
||||
@@ -166,11 +166,11 @@ suspend fun TelegramBot.flushAccumulatedUpdates(
|
||||
* all updates receivers, because this method will trigger getting of updates and.
|
||||
*/
|
||||
fun TelegramBot.longPolling(
|
||||
flowsUpdatesFilter: FlowsUpdatesFilter,
|
||||
updatesFilter: UpdatesFilter,
|
||||
timeoutSeconds: Seconds = 30,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
exceptionsHandler: ExceptionHandler<Unit>? = null
|
||||
): Job = flowsUpdatesFilter.run {
|
||||
): Job = updatesFilter.run {
|
||||
startGettingOfUpdatesByLongPolling(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user