1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

Merge pull request #75 from InsanusMokrassar/0.26.1

0.26.1
This commit is contained in:
InsanusMokrassar 2020-04-06 12:15:27 +06:00 committed by GitHub
commit db9c460e66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 64 additions and 45 deletions

View File

@ -38,6 +38,19 @@
and size of retrieved updates is equal to 100 (max count of retrieved updates)
* Extensions `getUpdates` now will receive only not nullable `limit` parameter
### 0.26.1
* `TelegramBotAPI`:
* `BotCommand` now will check and throw error in case when command or description lengths is/are incorrect
* `StorageFile` now is common for all platforms
* JavaScript realization was removed due to its redundancy
* JVM realization was replaced with `fun` factory
* `StorageFile` now able to accept any factory of `Input`
* `StorageFileInfo` was added to avoid strange collisions with throws in `StorageFile`
* Fixes issue with `hashTag` for markdown
* `InvalidPhotoDimensionsException` was added for cases when `PHOTO_INVALID_DIMENSION` answer received
* Other fixes
## 0.25.0
* Common:

View File

@ -14,6 +14,7 @@ fun newRequestException(
description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause)
description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
description.contains("PHOTO_INVALID_DIMENSIONS") -> InvalidPhotoDimensionsException(response, plainAnswer, message, cause)
else -> null
}
} ?: CommonRequestException(response, plainAnswer, message, cause)
@ -41,3 +42,6 @@ class MessageIsNotModifiedException(response: Response, plainAnswer: String, mes
class MessageToEditNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
RequestException(response, plainAnswer, message, cause)
class InvalidPhotoDimensionsException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
RequestException(response, plainAnswer, message, cause)

View File

@ -33,8 +33,8 @@ internal object InputFileSerializer : KSerializer<InputFile> {
@Serializable(InputFileSerializer::class)
data class MultipartFile (
val file: StorageFile,
val mimeType: String = file.contentType,
val filename: String = file.fileName
val mimeType: String = file.storageFileInfo.contentType,
val filename: String = file.storageFileInfo.fileName
) : InputFile() {
override val fileId: String = file.generateCustomName()
override val fileId: String = file.storageFileInfo.generateCustomName()
}

View File

@ -9,4 +9,13 @@ data class BotCommand(
val command: String,
@SerialName(descriptionField)
val description: String
)
) {
init {
if (command.length !in botCommandLengthLimit) {
error("Command size must be in range $botCommandLengthLimit, but actually have length ${command.length}")
}
if (description.length !in botCommandDescriptionLimit) {
error("Command description size must be in range $botCommandDescriptionLimit, but actually have length ${description.length}")
}
}
}

View File

@ -49,7 +49,8 @@ val customTitleLength = 0 .. 16
val diceResultLimit = 1 .. 6
val botCommandLimit = 1 .. 32
val botCommandLengthLimit = 1 .. 32
val botCommandLimit = botCommandLengthLimit
val botCommandDescriptionLimit = 3 .. 256
val botCommandsLimit = 0 .. 100

View File

@ -1,12 +1,21 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.benasher44.uuid.uuid4
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable
expect class StorageFile {
val contentType: String
data class StorageFileInfo(
val contentType: String,
val fileName: String
fun generateCustomName(): String
fun asInput(): Input
) {
fun generateCustomName() = "${uuid4()}.${fileName.fileExtension}"
}
data class StorageFile(
val storageFileInfo: StorageFileInfo,
private val inputSource: () -> Input
) {
fun asInput() = inputSource()
}

View File

@ -0,0 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
private val extensionRegex = Regex("[^.]*$")
val String.fileExtension
get() = extensionRegex.find(this) ?.value ?: ""

View File

@ -120,7 +120,7 @@ fun String.mentionHTML(): String = mention(String::toHtml)
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common)
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common()
fun String.hashTagHTML(): String = hashTag(String::toHtml)

View File

@ -16,9 +16,9 @@ fun String.toMarkdown(): String {
)
}
private val markdownV2LinkEscapes = mutableSetOf(')', '\\')
private val markdownV2PreAndCodeEscapes = mutableSetOf('`', '\\')
private val markdownV2CommonEscapes = mutableSetOf(
private val markdownV2LinkEscapes = setOf(')', '\\')
private val markdownV2PreAndCodeEscapes = setOf('`', '\\')
private val markdownV2CommonEscapes = setOf(
'_',
'*',
'[', ']',

View File

@ -1,19 +0,0 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.benasher44.uuid.uuid4
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
@Serializable
actual data class StorageFile(
actual val contentType: String,
actual val fileName: String,
@Transient
val inputGetter: () -> Input = throw IllegalStateException("Can't create object without input"),
@Transient
val extension: String = throw IllegalStateException("Can't create object without extension")
) {
actual fun asInput(): Input = inputGetter()
actual fun generateCustomName(): String = "${uuid4()}.$extension"
}

View File

@ -1,20 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.benasher44.uuid.uuid4
import io.ktor.utils.io.core.Input
import io.ktor.utils.io.streams.asInput
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import java.io.File
import java.nio.file.Files
@Serializable
actual class StorageFile(
@Transient
private val file: File = throw IllegalStateException("Can't create object without file")
fun StorageFile(
file: File
) = StorageFile(
StorageFileInfo(
Files.probeContentType(file.toPath()),
file.name
)
) {
actual val contentType: String = Files.probeContentType(file.toPath())
actual val fileName: String = file.name
actual fun generateCustomName(): String = "${uuid4()}.${file.extension}"
actual fun asInput(): Input = Files.newInputStream(file.toPath()).asInput()
file.inputStream().asInput()
}

View File

@ -7,6 +7,6 @@ uuid_version=0.1.0
ktor_version=1.3.2
library_group=com.github.insanusmokrassar
library_version=0.26.0
library_version=0.26.1
gradle_bintray_plugin_version=1.8.4