mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-24 01:27:13 +00:00
commit
685e4af8f5
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,5 +1,15 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.33.1
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Kotlin`: `1.4.31` -> `1.4.32`
|
||||
* `MicroUtils`: `0.4.29` -> `0.4.30`
|
||||
* `Klocks`: `2.0.6` -> `2.0.7`
|
||||
* `Utils Extensions`:
|
||||
* Add extensions `parseCommandsWithParams`
|
||||
|
||||
## 0.33.0
|
||||
|
||||
**UPDATE UP TO Telegram Bot API 5.1**
|
||||
|
@ -5,18 +5,18 @@ kotlin.js.generate.externals=true
|
||||
kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
kotlin_version=1.4.31
|
||||
kotlin_version=1.4.32
|
||||
kotlin_coroutines_version=1.4.3
|
||||
kotlin_serialisation_runtime_version=1.1.0
|
||||
klock_version=2.0.6
|
||||
klock_version=2.0.7
|
||||
uuid_version=0.2.3
|
||||
ktor_version=1.5.2
|
||||
|
||||
micro_utils_version=0.4.29
|
||||
micro_utils_version=0.4.30
|
||||
|
||||
javax_activation_version=1.1.1
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=0.33.0
|
||||
library_version=0.33.1
|
||||
|
||||
github_release_plugin_version=2.2.12
|
||||
|
@ -6,6 +6,7 @@ interface Captioned {
|
||||
val caption: String?
|
||||
}
|
||||
|
||||
@Deprecated("This interface is not used in library and will be removed soon")
|
||||
interface CaptionedOutput : Captioned {
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ fun newRequestException(
|
||||
cause: Throwable? = null
|
||||
) = response.description ?.let { description ->
|
||||
when {
|
||||
description == "Bad Request: reply message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause)
|
||||
description == "Bad Request: reply message not found" || description == "Bad Request: replied message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause)
|
||||
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)
|
||||
|
@ -0,0 +1,62 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
|
||||
|
||||
val defaultArgsSeparator = Regex(" ")
|
||||
/**
|
||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||
*/
|
||||
fun List<TextSource>.parseCommandsWithParams(
|
||||
argsSeparator: Regex = defaultArgsSeparator
|
||||
): MutableMap<String, Array<String>> {
|
||||
val result = mutableMapOf<String, Array<String>>()
|
||||
var currentBotCommandSource: BotCommandTextSource? = null
|
||||
var currentArgs = ""
|
||||
fun includeCurrent() = currentBotCommandSource ?.let {
|
||||
result[it.command] = currentArgs.split(argsSeparator).toTypedArray()
|
||||
currentArgs = ""
|
||||
}
|
||||
for (textSource in this) {
|
||||
if (textSource is BotCommandTextSource) {
|
||||
includeCurrent()
|
||||
currentBotCommandSource = textSource
|
||||
} else {
|
||||
currentArgs += textSource.source
|
||||
}
|
||||
}
|
||||
includeCurrent()
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||
*/
|
||||
fun TextedInput.parseCommandsWithParams(
|
||||
argsSeparator: Regex = defaultArgsSeparator
|
||||
) = textSources.parseCommandsWithParams(argsSeparator)
|
||||
|
||||
/**
|
||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||
*/
|
||||
fun TextedOutput.parseCommandsWithParams(
|
||||
argsSeparator: Regex = defaultArgsSeparator
|
||||
) = entities ?.parseCommandsWithParams(argsSeparator) ?: emptyMap()
|
||||
|
||||
/**
|
||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||
*/
|
||||
fun CaptionedInput.parseCommandsWithParams(
|
||||
argsSeparator: Regex = defaultArgsSeparator
|
||||
) = textSources.parseCommandsWithParams(argsSeparator)
|
||||
|
||||
/**
|
||||
* Parse commands and their args. Logic will find command, get all subsequent data as args until new command
|
||||
*/
|
||||
fun ContentMessage<TextContent>.parseCommandsWithParams(
|
||||
argsSeparator: Regex = defaultArgsSeparator
|
||||
) = content.parseCommandsWithParams(argsSeparator)
|
Loading…
Reference in New Issue
Block a user