mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
commit
7375894645
37
CHANGELOG.md
37
CHANGELOG.md
@ -49,6 +49,43 @@
|
||||
* `closePollExactAfter`
|
||||
* `closePollAfter`
|
||||
|
||||
### 0.27.5
|
||||
|
||||
* `Common`:
|
||||
* Versions:
|
||||
* `Klock`: `1.11.1` -> `1.11.3`
|
||||
* `TelegramotAPI`:
|
||||
* Fix: for sending requests caption and text lengths limits were updated
|
||||
* New variant of `row` was added
|
||||
* `makeLinkToMessage` extensions has been deprecated (replaced into `TelegramBotAPI-extensions-utils`)
|
||||
* Next things was deprecated and replaced into `TelegramBotAPI-extensions-utils`:
|
||||
* All `String` formatting public extensions and functions
|
||||
* All extensions like `CaptionedInput#toHtmlCaptions`
|
||||
* All helper extensions for `List<BaseMessageUpdate>`
|
||||
* All `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe`
|
||||
* `BotCommand` now more strictly check commands which passed to it
|
||||
* Regex `BotCommandNameRegex` was added
|
||||
* `TelegramBotAPI-extensions-api`:
|
||||
* A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing
|
||||
* New `RequesstExecutor#setMyCommands` extension was added
|
||||
* New field `BotBuilder#ktorClientEngineFactory` introduced
|
||||
* Field `BotBuilder#ktorClientEngine` now is deprecated
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
* `safely` function was introduced. It is in `PreviewFeature` state currently
|
||||
* `makeLinkToMessage` extensions has been added
|
||||
* `makeLinkToAddStickerSet` function and its variations were added
|
||||
* Next tools was added from `TelegramBotAPI`:
|
||||
* All `String` formatting extensions and functions
|
||||
* All extensions like `CaptionedInput#toHtmlCaptions`
|
||||
* All helper extensions for `List<BaseMessageUpdate>`
|
||||
* Several new extensions for `SentMediaGroupUpdate` were added:
|
||||
* `SentMediaGroupUpdate#forwardInfo`
|
||||
* `SentMediaGroupUpdate#replyTo`
|
||||
* `SentMediaGroupUpdate#chat`
|
||||
* `SentMediaGroupUpdate#mediaGroupId`
|
||||
* Several `List<MediaGroupMessage>.createResend` extensions were added
|
||||
* `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe`
|
||||
|
||||
### 0.27.4
|
||||
|
||||
* `TelegramBotAPI-extensions-utils`:
|
||||
|
@ -4,8 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.engine.ProxyConfig
|
||||
import io.ktor.client.engine.*
|
||||
|
||||
/**
|
||||
* @param proxy Standard ktor [ProxyConfig]
|
||||
@ -14,20 +13,30 @@ import io.ktor.client.engine.ProxyConfig
|
||||
*/
|
||||
data class BotBuilder internal constructor(
|
||||
var proxy: ProxyConfig? = null,
|
||||
@Deprecated("ktorClientEngineFactory parameter will be used preferable. In future this parameter will be removed")
|
||||
var ktorClientEngine: HttpClientEngine? = null,
|
||||
var ktorClientEngineFactory: HttpClientEngineFactory<out HttpClientEngineConfig>? = null,
|
||||
var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null
|
||||
) {
|
||||
internal fun createHttpClient(): HttpClient = ktorClientEngine ?.let { engine ->
|
||||
internal fun createHttpClient(): HttpClient = ktorClientEngineFactory ?.let {
|
||||
HttpClient(
|
||||
it.create {
|
||||
this@create.proxy = this@BotBuilder.proxy ?: this@create.proxy
|
||||
}
|
||||
) {
|
||||
ktorClientConfig ?.let { it() }
|
||||
}
|
||||
} ?: ktorClientEngine ?.let { engine ->
|
||||
HttpClient(engine) {
|
||||
ktorClientConfig ?.let { it() }
|
||||
engine {
|
||||
proxy = this@BotBuilder.proxy ?: proxy
|
||||
this@engine.proxy = this@BotBuilder.proxy ?: this@engine.proxy
|
||||
}
|
||||
}
|
||||
} ?: HttpClient {
|
||||
ktorClientConfig ?.let { it() }
|
||||
engine {
|
||||
proxy = this@BotBuilder.proxy ?: proxy
|
||||
this@engine.proxy = this@BotBuilder.proxy ?: this@engine.proxy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,3 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand
|
||||
suspend fun RequestsExecutor.setMyCommands(
|
||||
commands: List<BotCommand>
|
||||
) = execute(SetMyCommands(commands))
|
||||
|
||||
suspend fun RequestsExecutor.setMyCommands(
|
||||
vararg commands: BotCommand
|
||||
) = setMyCommands(commands.toList())
|
||||
|
@ -2,8 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.chat.get
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get.GetChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.PreviewFeature
|
||||
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chatId: ChatIdentifier
|
||||
@ -12,3 +16,117 @@ suspend fun RequestsExecutor.getChat(
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: Chat
|
||||
) = getChat(chat.id)
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedPublicChat] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: PublicChat
|
||||
) = getChat(chat.id) as ExtendedPublicChat
|
||||
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedChannelChat] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: ChannelChat
|
||||
) = getChat(chat.id) as ExtendedChannelChat
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedChannelChatImpl] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: ChannelChatImpl
|
||||
) = getChat(chat.id) as ExtendedChannelChatImpl
|
||||
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedGroupChat] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: GroupChat
|
||||
) = getChat(chat.id) as ExtendedGroupChat
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedGroupChatImpl] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: GroupChatImpl
|
||||
) = getChat(chat.id) as ExtendedGroupChatImpl
|
||||
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedSupergroupChat] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: SupergroupChat
|
||||
) = getChat(chat.id) as ExtendedSupergroupChat
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedSupergroupChatImpl] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: SupergroupChatImpl
|
||||
) = getChat(chat.id) as ExtendedSupergroupChatImpl
|
||||
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedPrivateChat] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: PrivateChat
|
||||
) = getChat(chat.id) as ExtendedPrivateChat
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedPrivateChatImpl] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: PrivateChatImpl
|
||||
) = getChat(chat.id) as ExtendedPrivateChatImpl
|
||||
|
||||
/**
|
||||
* Will cast incoming [com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat] to a
|
||||
* [ExtendedUser] with unsafe operator "as"
|
||||
*
|
||||
* @throws ClassCastException
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend fun RequestsExecutor.getChat(
|
||||
chat: CommonUser
|
||||
) = getChat(chat.id) as ExtendedUser
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
/**
|
||||
* Shortcut for [handleSafely]. It was created for more comfortable way of handling different things
|
||||
*/
|
||||
@PreviewFeature
|
||||
suspend inline fun <T> safely(
|
||||
noinline onException: ExceptionHandler<T> = { throw it },
|
||||
noinline block: suspend CoroutineScope.() -> T
|
||||
): T = handleSafely(
|
||||
onException,
|
||||
block
|
||||
)
|
@ -0,0 +1,80 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.formatting
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.StickerSetName
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.link
|
||||
|
||||
private const val internalLinkBeginning = "https://t.me"
|
||||
|
||||
fun makeLinkToMessage(
|
||||
username: String,
|
||||
messageId: MessageIdentifier
|
||||
): String = "$internalLinkBeginning/$username/$messageId"
|
||||
|
||||
private val linkIdRedundantPartRegex = Regex("^-100")
|
||||
private val usernameBeginSymbolRegex = Regex("^@")
|
||||
|
||||
fun makeLinkToMessage(
|
||||
chat: ExtendedChat,
|
||||
messageId: MessageIdentifier
|
||||
): String? {
|
||||
return when {
|
||||
chat is UsernameChat && chat.username != null -> {
|
||||
"$internalLinkBeginning/${chat.username ?.username ?.replace(
|
||||
usernameBeginSymbolRegex, "")}/$messageId"
|
||||
}
|
||||
chat !is PrivateChat -> chat.id.chatId.toString().replace(
|
||||
linkIdRedundantPartRegex,
|
||||
""
|
||||
).let { bareId ->
|
||||
"$internalLinkBeginning/c/$bareId/$messageId"
|
||||
}
|
||||
else -> return null
|
||||
}
|
||||
}
|
||||
|
||||
private const val stickerSetAddingLinkPrefix = "$internalLinkBeginning/addstickers"
|
||||
|
||||
/**
|
||||
* Create a link for adding of sticker set with name [stickerSetName]. Was added thanks to user Djaler and based on
|
||||
* https://github.com/Djaler/evil-bot/blob/master/src/main/kotlin/com/github/djaler/evilbot/utils/StickerUtils.kt#L6-L8
|
||||
*
|
||||
* @see [makeLinkToAddStickerSetInMarkdownV2]
|
||||
* @see [makeLinkToAddStickerSetInMarkdown]
|
||||
* @see [makeLinkToAddStickerSetInHtml]
|
||||
*/
|
||||
fun makeLinkToAddStickerSet(
|
||||
stickerSetName: StickerSetName,
|
||||
parseMode: ParseMode
|
||||
) = (stickerSetName to "$stickerSetAddingLinkPrefix/$stickerSetName").link(
|
||||
parseMode
|
||||
)
|
||||
|
||||
/**
|
||||
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [MarkdownV2]
|
||||
*/
|
||||
fun makeLinkToAddStickerSetInMarkdownV2(stickerSetName: StickerSetName) =
|
||||
makeLinkToAddStickerSet(
|
||||
stickerSetName,
|
||||
MarkdownV2
|
||||
)
|
||||
/**
|
||||
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [Markdown]
|
||||
*/
|
||||
fun makeLinkToAddStickerSetInMarkdown(stickerSetName: StickerSetName) =
|
||||
makeLinkToAddStickerSet(
|
||||
stickerSetName,
|
||||
Markdown
|
||||
)
|
||||
/**
|
||||
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [HTML]
|
||||
*/
|
||||
fun makeLinkToAddStickerSetInHtml(stickerSetName: StickerSetName) =
|
||||
makeLinkToAddStickerSet(
|
||||
stickerSetName,
|
||||
HTML
|
||||
)
|
@ -0,0 +1,121 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.formatting
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList
|
||||
|
||||
fun createFormattedText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last,
|
||||
mode: ParseMode = MarkdownParseMode
|
||||
): List<String> {
|
||||
val texts = mutableListOf<String>()
|
||||
val textBuilder = StringBuilder(partLength)
|
||||
for (entity in entities) {
|
||||
val string = when (mode) {
|
||||
is MarkdownParseMode -> entity.asMarkdownSource
|
||||
is MarkdownV2ParseMode -> entity.asMarkdownV2Source
|
||||
is HTMLParseMode -> entity.asHtmlSource
|
||||
}
|
||||
if (textBuilder.length + string.length > partLength) {
|
||||
if (textBuilder.isNotEmpty()) {
|
||||
texts.add(textBuilder.toString())
|
||||
textBuilder.clear()
|
||||
}
|
||||
val chunked = string.chunked(partLength)
|
||||
val last = chunked.last()
|
||||
textBuilder.append(last)
|
||||
val listToAdd = if (chunked.size > 1) {
|
||||
chunked.subList(0, chunked.size - 1)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
listToAdd.forEach {
|
||||
texts.add(it)
|
||||
}
|
||||
} else {
|
||||
textBuilder.append(string)
|
||||
}
|
||||
}
|
||||
if (textBuilder.isNotEmpty()) {
|
||||
texts.add(textBuilder.toString())
|
||||
textBuilder.clear()
|
||||
}
|
||||
return texts
|
||||
}
|
||||
|
||||
|
||||
fun createMarkdownText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
|
||||
|
||||
fun FullTextSourcesList.toMarkdownCaptions(): List<String> = createMarkdownText(
|
||||
this,
|
||||
captionLength.last
|
||||
)
|
||||
fun CaptionedInput.toMarkdownCaptions(): List<String> = fullEntitiesList().toMarkdownCaptions()
|
||||
|
||||
fun FullTextSourcesList.toMarkdownTexts(): List<String> = createMarkdownText(
|
||||
this,
|
||||
textLength.last
|
||||
)
|
||||
fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
|
||||
fun FullTextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
|
||||
|
||||
fun createMarkdownV2Text(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, MarkdownV2ParseMode)
|
||||
|
||||
fun FullTextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
captionLength.last
|
||||
)
|
||||
fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toMarkdownV2Captions()
|
||||
|
||||
fun FullTextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
textLength.last
|
||||
)
|
||||
fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
|
||||
fun FullTextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
|
||||
|
||||
fun createHtmlText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
|
||||
|
||||
fun FullTextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
|
||||
this,
|
||||
captionLength.last
|
||||
)
|
||||
fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCaptions()
|
||||
|
||||
fun FullTextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
|
||||
this,
|
||||
textLength.last
|
||||
)
|
||||
fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
|
||||
|
||||
fun FullTextSourcesList.toHtmlExplanations(): List<String> = createHtmlText(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
fun ExplainedInput.toHtmlExplanations(): List<String> = fullEntitiesList().toHtmlTexts()
|
||||
|
||||
|
@ -0,0 +1,243 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.formatting
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.*
|
||||
|
||||
const val markdownBoldControl = "*"
|
||||
const val markdownItalicControl = "_"
|
||||
const val markdownCodeControl = "`"
|
||||
const val markdownPreControl = "```"
|
||||
|
||||
const val markdownV2ItalicUnderlineDelimiter = "\u0013"
|
||||
const val markdownV2StrikethroughControl = "~"
|
||||
const val markdownV2UnderlineControl = "__"
|
||||
const val markdownV2UnderlineEndControl = "$markdownV2UnderlineControl$markdownV2ItalicUnderlineDelimiter"
|
||||
const val markdownV2ItalicEndControl = "$markdownItalicControl$markdownV2ItalicUnderlineDelimiter"
|
||||
|
||||
const val htmlBoldControl = "b"
|
||||
const val htmlItalicControl = "i"
|
||||
const val htmlCodeControl = "code"
|
||||
const val htmlPreControl = "pre"
|
||||
const val htmlUnderlineControl = "u"
|
||||
const val htmlStrikethroughControl = "s"
|
||||
|
||||
private fun String.markdownDefault(
|
||||
openControlSymbol: String,
|
||||
closeControlSymbol: String = openControlSymbol
|
||||
) = "$openControlSymbol${toMarkdown()}$closeControlSymbol"
|
||||
private fun String.markdownV2Default(
|
||||
openControlSymbol: String,
|
||||
closeControlSymbol: String = openControlSymbol,
|
||||
escapeFun: String.() -> String = String::escapeMarkdownV2Common
|
||||
) = "$openControlSymbol${escapeFun()}$closeControlSymbol"
|
||||
private fun String.htmlDefault(
|
||||
openControlSymbol: String,
|
||||
closeControlSymbol: String = openControlSymbol
|
||||
) = "<$openControlSymbol>${toHtml()}</$closeControlSymbol>"
|
||||
|
||||
fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})"
|
||||
fun String.linkMarkdownV2(link: String): String = "[${escapeMarkdownV2Common()}](${link.escapeMarkdownV2Link()})"
|
||||
fun String.linkHTML(link: String): String = "<a href=\"$link\">${toHtml()}</a>"
|
||||
|
||||
|
||||
fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl)
|
||||
fun String.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl)
|
||||
fun String.boldHTML(): String = htmlDefault(htmlBoldControl)
|
||||
|
||||
|
||||
fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
||||
fun String.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl, markdownV2ItalicEndControl)
|
||||
fun String.italicHTML(): String = htmlDefault(htmlItalicControl)
|
||||
|
||||
/**
|
||||
* Crutch for support of strikethrough in default markdown. Simply add modifier, but it will not look like correct
|
||||
*/
|
||||
fun String.strikethroughMarkdown(): String = map { it + "\u0336" }.joinToString("")
|
||||
fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl)
|
||||
fun String.strikethroughHTML(): String = htmlDefault(htmlStrikethroughControl)
|
||||
|
||||
|
||||
/**
|
||||
* Crutch for support of underline in default markdown. Simply add modifier, but it will not look like correct
|
||||
*/
|
||||
fun String.underlineMarkdown(): String = map { it + "\u0347" }.joinToString("")
|
||||
fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl)
|
||||
fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
||||
|
||||
|
||||
fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl)
|
||||
fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode)
|
||||
fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
||||
|
||||
|
||||
fun String.preMarkdown(language: String? = null): String = markdownDefault(
|
||||
"$markdownPreControl${language ?: ""}\n",
|
||||
"\n$markdownPreControl"
|
||||
)
|
||||
fun String.preMarkdownV2(language: String? = null): String = markdownV2Default(
|
||||
"$markdownPreControl${language ?: ""}\n",
|
||||
"\n$markdownPreControl",
|
||||
String::escapeMarkdownV2PreAndCode
|
||||
)
|
||||
fun String.preHTML(language: String? = null): String = htmlDefault(
|
||||
language ?.let {
|
||||
"$htmlPreControl><$htmlCodeControl class=\"language-$language\""
|
||||
} ?: htmlPreControl,
|
||||
language ?.let {
|
||||
"$htmlCodeControl></$htmlPreControl"
|
||||
} ?: htmlPreControl
|
||||
)
|
||||
|
||||
|
||||
fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}")
|
||||
fun String.emailMarkdownV2(): String = linkMarkdownV2("mailto://$${toMarkdown()}")
|
||||
fun String.emailHTML(): String = linkHTML("mailto://$${toHtml()}")
|
||||
|
||||
|
||||
private inline fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
||||
adapt()
|
||||
} else {
|
||||
"@${adapt()}"
|
||||
}
|
||||
|
||||
|
||||
private inline fun String.hashTag(adapt: String.() -> String): String = if (startsWith("#")) {
|
||||
adapt()
|
||||
} else {
|
||||
"#${adapt()}"
|
||||
}
|
||||
|
||||
|
||||
fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
||||
fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
||||
fun String.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
|
||||
|
||||
|
||||
fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
||||
fun String.mentionMarkdownV2(): String = mention(String::escapeMarkdownV2Common)
|
||||
fun String.mentionHTML(): String = mention(String::toHtml)
|
||||
|
||||
|
||||
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
||||
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common()
|
||||
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
||||
|
||||
|
||||
fun String.phoneMarkdown(): String = toMarkdown()
|
||||
fun String.phoneMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
fun String.phoneHTML(): String = toHtml()
|
||||
|
||||
|
||||
fun String.command(adapt: String.() -> String): String = if (startsWith("/")) {
|
||||
adapt()
|
||||
} else {
|
||||
"/${adapt()}"
|
||||
}
|
||||
|
||||
fun String.commandMarkdown(): String = command(String::toMarkdown)
|
||||
fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common)
|
||||
fun String.commandHTML(): String = command(String::toHtml)
|
||||
|
||||
|
||||
fun String.regularMarkdown(): String = toMarkdown()
|
||||
fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
fun String.regularHtml(): String = toHtml()
|
||||
|
||||
|
||||
fun String.cashTagMarkdown(): String = toMarkdown()
|
||||
fun String.cashTagMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
fun String.cashTagHtml(): String = toHtml()
|
||||
|
||||
|
||||
infix fun String.bold(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> boldHTML()
|
||||
is Markdown -> boldMarkdown()
|
||||
is MarkdownV2 -> boldMarkdownV2()
|
||||
}
|
||||
|
||||
|
||||
infix fun String.italic(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> italicHTML()
|
||||
is Markdown -> italicMarkdown()
|
||||
is MarkdownV2 -> italicMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun String.hashTag(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> hashTagHTML()
|
||||
is Markdown -> hashTagMarkdown()
|
||||
is MarkdownV2 -> hashTagMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun String.code(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> codeHTML()
|
||||
is Markdown -> codeMarkdown()
|
||||
is MarkdownV2 -> codeMarkdownV2()
|
||||
}
|
||||
|
||||
fun String.pre(parseMode: ParseMode, language: String? = null): String = when (parseMode) {
|
||||
is HTML -> preHTML(language)
|
||||
is Markdown -> preMarkdown(language)
|
||||
is MarkdownV2 -> preMarkdownV2(language)
|
||||
}
|
||||
infix fun String.pre(parseMode: ParseMode): String = pre(parseMode, null)
|
||||
|
||||
infix fun String.email(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> emailHTML()
|
||||
is Markdown -> emailMarkdown()
|
||||
is MarkdownV2 -> emailMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun Pair<String, String>.link(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> first.linkHTML(second)
|
||||
is Markdown -> first.linkMarkdown(second)
|
||||
is MarkdownV2 -> first.linkMarkdownV2(second)
|
||||
}
|
||||
|
||||
infix fun String.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> mentionHTML()
|
||||
is Markdown -> mentionMarkdown()
|
||||
is MarkdownV2 -> mentionMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun Pair<String, ChatId>.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> first.textMentionHTML(second)
|
||||
is Markdown -> first.textMentionMarkdown(second)
|
||||
is MarkdownV2 -> first.textMentionMarkdownV2(second)
|
||||
}
|
||||
|
||||
infix fun String.phone(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> phoneHTML()
|
||||
is Markdown -> phoneMarkdown()
|
||||
is MarkdownV2 -> phoneMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> commandHTML()
|
||||
is Markdown -> commandMarkdown()
|
||||
is MarkdownV2 -> commandMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> underlineHTML()
|
||||
is Markdown -> underlineMarkdown()
|
||||
is MarkdownV2 -> underlineMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun String.strikethrough(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> strikethroughHTML()
|
||||
is Markdown -> strikethroughMarkdown()
|
||||
is MarkdownV2 -> strikethroughMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun String.regular(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> regularHtml()
|
||||
is Markdown -> regularMarkdown()
|
||||
is MarkdownV2 -> regularMarkdownV2()
|
||||
}
|
||||
|
||||
infix fun String.cashtag(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> cashTagHtml()
|
||||
is Markdown -> cashTagMarkdown()
|
||||
is MarkdownV2 -> cashTagMarkdownV2()
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendMediaGroup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.SentMediaGroupUpdate
|
||||
|
||||
val List<MediaGroupMessage>.forwardInfo: ForwardInfo?
|
||||
get() = firstOrNull() ?.forwardInfo
|
||||
val List<MediaGroupMessage>.replyTo: Message?
|
||||
get() = firstOrNull() ?.replyTo
|
||||
val List<MediaGroupMessage>.chat: Chat?
|
||||
get() = firstOrNull() ?.chat
|
||||
val List<MediaGroupMessage>.mediaGroupId: MediaGroupIdentifier?
|
||||
get() = firstOrNull() ?.mediaGroupId
|
||||
|
||||
val SentMediaGroupUpdate.forwardInfo: ForwardInfo?
|
||||
get() = data.first().forwardInfo
|
||||
val SentMediaGroupUpdate.replyTo: Message?
|
||||
get() = data.first().replyTo
|
||||
val SentMediaGroupUpdate.chat: Chat
|
||||
get() = data.chat!!
|
||||
val SentMediaGroupUpdate.mediaGroupId: MediaGroupIdentifier
|
||||
get() = data.mediaGroupId!!
|
||||
|
||||
fun List<MediaGroupMessage>.createResend(
|
||||
chatId: ChatId,
|
||||
disableNotification: Boolean = false,
|
||||
replyTo: MessageIdentifier? = null
|
||||
) = SendMediaGroup(
|
||||
chatId,
|
||||
map { it.content.toMediaGroupMemberInputMedia() },
|
||||
disableNotification,
|
||||
replyTo
|
||||
)
|
||||
|
||||
fun List<MediaGroupMessage>.createResend(
|
||||
chat: Chat,
|
||||
disableNotification: Boolean = false,
|
||||
replyTo: MessageIdentifier? = null
|
||||
) = createResend(
|
||||
chat.id,
|
||||
disableNotification,
|
||||
replyTo
|
||||
)
|
||||
|
||||
fun SentMediaGroupUpdate.createResend(
|
||||
disableNotification: Boolean = false,
|
||||
replyTo: MessageIdentifier? = null
|
||||
) = data.createResend(
|
||||
chat,
|
||||
disableNotification,
|
||||
replyTo
|
||||
)
|
@ -0,0 +1,45 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
fun <T: Any> RequestsExecutor.executeAsync(
|
||||
request: Request<T>,
|
||||
scope: CoroutineScope
|
||||
): Deferred<T> = scope.async {
|
||||
handleSafely {
|
||||
execute(request)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun <T: Any> RequestsExecutor.executeAsync(
|
||||
request: Request<T>
|
||||
): Deferred<T> = coroutineScope {
|
||||
executeAsync(request, this)
|
||||
}
|
||||
|
||||
suspend fun <T: Any> RequestsExecutor.executeUnsafe(
|
||||
request: Request<T>,
|
||||
retries: Int = 0,
|
||||
retriesDelay: Long = 1000L,
|
||||
onAllFailed: (suspend (exceptions: Array<Exception>) -> Unit)? = null
|
||||
): T? {
|
||||
var leftRetries = retries
|
||||
val exceptions = onAllFailed ?.let { mutableListOf<Exception>() }
|
||||
do {
|
||||
return handleSafely(
|
||||
{
|
||||
leftRetries--
|
||||
delay(retriesDelay)
|
||||
exceptions ?.add(it)
|
||||
null
|
||||
}
|
||||
) {
|
||||
execute(request)
|
||||
} ?: continue
|
||||
} while(leftRetries >= 0)
|
||||
onAllFailed ?.invoke(exceptions ?.toTypedArray() ?: emptyArray())
|
||||
return null
|
||||
}
|
@ -13,8 +13,8 @@ import io.ktor.utils.io.core.Closeable
|
||||
interface RequestsExecutor : Closeable {
|
||||
/**
|
||||
* Unsafe execution of incoming [request]. Can throw almost any exception. So, it is better to use
|
||||
* something like [com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.executeAsync] or
|
||||
* [com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.executeUnsafe]
|
||||
* something like [com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts.executeAsync] or
|
||||
* [com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts.executeUnsafe]
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
internal val TextContentMessageResultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
|
||||
@ -37,7 +38,7 @@ data class SendTextMessage(
|
||||
{
|
||||
init {
|
||||
if (text.length !in textLength) {
|
||||
throw IllegalArgumentException("Text must be in $textLength range")
|
||||
throwRangeError("Text length", textLength, text.length)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.AnimationContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendAnimation(
|
||||
@ -93,7 +94,7 @@ data class SendAnimationData internal constructor(
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throw IllegalArgumentException("Caption must be in $captionLength range")
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.AudioContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendAudio(
|
||||
@ -95,7 +96,7 @@ data class SendAudioData internal constructor(
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throw IllegalArgumentException("Caption must be in $captionLength range")
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.DocumentContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendDocument(
|
||||
@ -79,7 +80,7 @@ data class SendDocumentData internal constructor(
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throw IllegalArgumentException("Caption must be in $captionLength range")
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
|
||||
val membersCountInMediaGroup: IntRange = 2 .. 10
|
||||
@Deprecated("Replaced and renamed", ReplaceWith("mediaCountInMediaGroup", "com.github.insanusmokrassar.TelegramBotAPI.types.mediaCountInMediaGroup"))
|
||||
val membersCountInMediaGroup
|
||||
get() = mediaCountInMediaGroup
|
||||
|
||||
fun SendMediaGroup(
|
||||
chatId: ChatIdentifier,
|
||||
@ -21,8 +24,8 @@ fun SendMediaGroup(
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null
|
||||
): Request<List<MediaGroupMessage>> {
|
||||
if (media.size !in membersCountInMediaGroup) {
|
||||
throw IllegalArgumentException("Count of members for media group must be in $membersCountInMediaGroup range")
|
||||
if (media.size !in mediaCountInMediaGroup) {
|
||||
throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size)
|
||||
}
|
||||
|
||||
val files: List<MultipartFile> = media.flatMap {
|
||||
|
@ -10,6 +10,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.PhotoContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendPhoto(
|
||||
@ -65,7 +66,7 @@ data class SendPhotoData internal constructor(
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throw IllegalArgumentException("Caption must be in $captionLength range")
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VideoContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendVideo(
|
||||
@ -97,7 +98,7 @@ data class SendVideoData internal constructor(
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throw IllegalArgumentException("Caption must be in $captionLength range")
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VideoNoteContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendVideoNote(
|
||||
@ -92,7 +93,7 @@ data class SendVideoNoteData internal constructor(
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throw IllegalArgumentException("Caption must be in $captionLength range")
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Conten
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.VoiceContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mapOfNotNull
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun SendVoice(
|
||||
@ -84,7 +85,7 @@ data class SendVoiceData internal constructor(
|
||||
init {
|
||||
text ?.let {
|
||||
if (it.length !in captionLength) {
|
||||
throw IllegalArgumentException("Caption must be in $captionLength range")
|
||||
throwRangeError("Caption length", captionLength, it.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
val BotCommandNameRegex = Regex("^[a-z_0-9]{${botCommandLengthLimit.first},${botCommandLengthLimit.last}}$")
|
||||
|
||||
@Serializable
|
||||
data class BotCommand(
|
||||
@SerialName(botCommandField)
|
||||
@ -12,10 +15,13 @@ data class BotCommand(
|
||||
) {
|
||||
init {
|
||||
if (command.length !in botCommandLengthLimit) {
|
||||
error("Command size must be in range $botCommandLengthLimit, but actually have length ${command.length}")
|
||||
throwRangeError("Command name size", botCommandLengthLimit, command.length)
|
||||
}
|
||||
if (!command.matches(BotCommandNameRegex)) {
|
||||
error("Bot command must contains only lowercase English letters, digits and underscores, but incoming command was $command")
|
||||
}
|
||||
if (description.length !in botCommandDescriptionLimit) {
|
||||
error("Command description size must be in range $botCommandDescriptionLimit, but actually have length ${description.length}")
|
||||
throwRangeError("Command description size", botCommandDescriptionLimit, description.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ typealias LongSeconds = Long
|
||||
|
||||
val getUpdatesLimit = 1 .. 100
|
||||
val callbackQueryAnswerLength = 0 until 200
|
||||
val captionLength = 0 until 1024
|
||||
val textLength = 0 until 4096
|
||||
val captionLength = 0 .. 1024
|
||||
val textLength = 1 .. 4096
|
||||
val userProfilePhotosRequestLimit = 0 .. 100
|
||||
val chatTitleLength = 1 until 255
|
||||
val chatDescriptionLength = 0 until 256
|
||||
@ -55,6 +55,8 @@ val botCommandLimit = botCommandLengthLimit
|
||||
val botCommandDescriptionLimit = 3 .. 256
|
||||
val botCommandsLimit = 0 .. 100
|
||||
|
||||
val mediaCountInMediaGroup: IntRange = 2 .. 10
|
||||
|
||||
val explanationLimit = 0 .. 200
|
||||
@Deprecated("Will be removed in near updates", ReplaceWith("explanationLimit"))
|
||||
val quizPollExplanationLimit = explanationLimit
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
@RequiresOptIn(
|
||||
"It is possible, that behaviour of this thing will be changed later",
|
||||
"It is possible, that behaviour of this thing will be changed later or this feature will be removed",
|
||||
RequiresOptIn.Level.WARNING
|
||||
)
|
||||
@Target(
|
||||
|
@ -6,9 +6,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createFormattedText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = 4096,
|
||||
partLength: Int = textLength.last,
|
||||
mode: ParseMode = MarkdownParseMode
|
||||
): List<String> {
|
||||
val texts = mutableListOf<String>()
|
||||
@ -47,75 +48,96 @@ fun createFormattedText(
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createMarkdownText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = 4096
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownCaptions(): List<String> = createMarkdownText(
|
||||
this,
|
||||
captionLength.last + 1
|
||||
captionLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun CaptionedInput.toMarkdownCaptions(): List<String> = fullEntitiesList().toMarkdownCaptions()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownTexts(): List<String> = createMarkdownText(
|
||||
this,
|
||||
textLength.last + 1
|
||||
textLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
|
||||
this,
|
||||
explanationLimit.last + 1
|
||||
explanationLimit.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createMarkdownV2Text(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = 4096
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, MarkdownV2ParseMode)
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
captionLength.last + 1
|
||||
captionLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toMarkdownV2Captions()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
textLength.last + 1
|
||||
textLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
explanationLimit.last + 1
|
||||
explanationLimit.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createHtmlText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = 4096
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
|
||||
this,
|
||||
captionLength.last + 1
|
||||
captionLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCaptions()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
|
||||
this,
|
||||
textLength.last + 1
|
||||
textLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toHtmlExplanations(): List<String> = createHtmlText(
|
||||
this,
|
||||
explanationLimit.last + 1
|
||||
explanationLimit.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun ExplainedInput.toHtmlExplanations(): List<String> = fullEntitiesList().toHtmlTexts()
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.
|
||||
|
||||
private const val internalLinkBeginning = "https://t.me"
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils project")
|
||||
fun makeLinkToMessage(
|
||||
username: String,
|
||||
messageId: MessageIdentifier
|
||||
@ -15,6 +16,7 @@ fun makeLinkToMessage(
|
||||
private val linkIdRedundantPartRegex = Regex("^-100")
|
||||
private val usernameBeginSymbolRegex = Regex("^@")
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils project")
|
||||
fun makeLinkToMessage(
|
||||
chat: ExtendedChat,
|
||||
messageId: MessageIdentifier
|
||||
|
@ -10,6 +10,10 @@ fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
|
||||
add(RowBuilder<T>().also(block).row)
|
||||
}
|
||||
|
||||
fun <T> MatrixBuilder<T>.row(vararg elements: T) {
|
||||
add(elements.toList())
|
||||
}
|
||||
|
||||
fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
|
||||
return MatrixBuilder<T>().also(block).matrix
|
||||
}
|
||||
|
@ -6,18 +6,22 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.forwarded: ForwardInfo?
|
||||
get() = first().let {
|
||||
(it as? PossiblyForwardedMessage) ?.forwardInfo
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.replyTo: Message?
|
||||
get() = first().let {
|
||||
(it as? PossiblyReplyMessage) ?.replyTo
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.chat: Chat?
|
||||
get() = first().data.chat
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.mediaGroupId: MediaGroupIdentifier?
|
||||
get() = (first().data as? MediaGroupMessage) ?.mediaGroupId
|
||||
|
@ -36,50 +36,71 @@ private fun String.htmlDefault(
|
||||
closeControlSymbol: String = openControlSymbol
|
||||
) = "<$openControlSymbol>${toHtml()}</$closeControlSymbol>"
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})"
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.linkMarkdownV2(link: String): String = "[${escapeMarkdownV2Common()}](${link.escapeMarkdownV2Link()})"
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.linkHTML(link: String): String = "<a href=\"$link\">${toHtml()}</a>"
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.boldHTML(): String = htmlDefault(htmlBoldControl)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl, markdownV2ItalicEndControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.italicHTML(): String = htmlDefault(htmlItalicControl)
|
||||
|
||||
/**
|
||||
* Crutch for support of strikethrough in default markdown. Simply add modifier, but it will not look like correct
|
||||
*/
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.strikethroughMarkdown(): String = map { it + "\u0336" }.joinToString("")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.strikethroughHTML(): String = htmlDefault(htmlStrikethroughControl)
|
||||
|
||||
|
||||
/**
|
||||
* Crutch for support of underline in default markdown. Simply add modifier, but it will not look like correct
|
||||
*/
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.underlineMarkdown(): String = map { it + "\u0347" }.joinToString("")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.preMarkdown(language: String? = null): String = markdownDefault(
|
||||
"$markdownPreControl${language ?: ""}\n",
|
||||
"\n$markdownPreControl"
|
||||
)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.preMarkdownV2(language: String? = null): String = markdownV2Default(
|
||||
"$markdownPreControl${language ?: ""}\n",
|
||||
"\n$markdownPreControl",
|
||||
String::escapeMarkdownV2PreAndCode
|
||||
)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.preHTML(language: String? = null): String = htmlDefault(
|
||||
language ?.let {
|
||||
"$htmlPreControl><$htmlCodeControl class=\"language-$language\""
|
||||
@ -90,11 +111,15 @@ fun String.preHTML(language: String? = null): String = htmlDefault(
|
||||
)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.emailMarkdownV2(): String = linkMarkdownV2("mailto://$${toMarkdown()}")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.emailHTML(): String = linkHTML("mailto://$${toHtml()}")
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
private inline fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
||||
adapt()
|
||||
} else {
|
||||
@ -102,6 +127,7 @@ private inline fun String.mention(adapt: String.() -> String): String = if (star
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
private inline fun String.hashTag(adapt: String.() -> String): String = if (startsWith("#")) {
|
||||
adapt()
|
||||
} else {
|
||||
@ -109,47 +135,70 @@ private inline fun String.hashTag(adapt: String.() -> String): String = if (star
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.mentionMarkdownV2(): String = mention(String::escapeMarkdownV2Common)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.mentionHTML(): String = mention(String::toHtml)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.phoneMarkdown(): String = toMarkdown()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.phoneMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.phoneHTML(): String = toHtml()
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.command(adapt: String.() -> String): String = if (startsWith("/")) {
|
||||
adapt()
|
||||
} else {
|
||||
"/${adapt()}"
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.commandMarkdown(): String = command(String::toMarkdown)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.commandHTML(): String = command(String::toHtml)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.regularMarkdown(): String = toMarkdown()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.regularHtml(): String = toHtml()
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.cashTagMarkdown(): String = toMarkdown()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.cashTagMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.cashTagHtml(): String = toHtml()
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.bold(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> boldHTML()
|
||||
is Markdown -> boldMarkdown()
|
||||
@ -157,85 +206,100 @@ infix fun String.bold(parseMode: ParseMode): String = when (parseMode) {
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.italic(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> italicHTML()
|
||||
is Markdown -> italicMarkdown()
|
||||
is MarkdownV2 -> italicMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.hashTag(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> hashTagHTML()
|
||||
is Markdown -> hashTagMarkdown()
|
||||
is MarkdownV2 -> hashTagMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.code(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> codeHTML()
|
||||
is Markdown -> codeMarkdown()
|
||||
is MarkdownV2 -> codeMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.pre(parseMode: ParseMode, language: String? = null): String = when (parseMode) {
|
||||
is HTML -> preHTML(language)
|
||||
is Markdown -> preMarkdown(language)
|
||||
is MarkdownV2 -> preMarkdownV2(language)
|
||||
}
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.pre(parseMode: ParseMode): String = pre(parseMode, null)
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.email(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> emailHTML()
|
||||
is Markdown -> emailMarkdown()
|
||||
is MarkdownV2 -> emailMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun Pair<String, String>.link(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> first.linkHTML(second)
|
||||
is Markdown -> first.linkMarkdown(second)
|
||||
is MarkdownV2 -> first.linkMarkdownV2(second)
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> mentionHTML()
|
||||
is Markdown -> mentionMarkdown()
|
||||
is MarkdownV2 -> mentionMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun Pair<String, ChatId>.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> first.textMentionHTML(second)
|
||||
is Markdown -> first.textMentionMarkdown(second)
|
||||
is MarkdownV2 -> first.textMentionMarkdownV2(second)
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.phone(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> phoneHTML()
|
||||
is Markdown -> phoneMarkdown()
|
||||
is MarkdownV2 -> phoneMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> commandHTML()
|
||||
is Markdown -> commandMarkdown()
|
||||
is MarkdownV2 -> commandMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> underlineHTML()
|
||||
is Markdown -> underlineMarkdown()
|
||||
is MarkdownV2 -> underlineMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.strikethrough(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> strikethroughHTML()
|
||||
is Markdown -> strikethroughMarkdown()
|
||||
is MarkdownV2 -> strikethroughMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.regular(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> regularHtml()
|
||||
is Markdown -> regularMarkdown()
|
||||
is MarkdownV2 -> regularMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.cashtag(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> cashTagHtml()
|
||||
is Markdown -> cashTagMarkdown()
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
internal fun throwRangeError(
|
||||
valueName: String,
|
||||
range: IntRange,
|
||||
actualValue: Int
|
||||
): Nothing = error("$valueName must be in range $range, but was $actualValue")
|
@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
|
||||
@Deprecated("Will be removed in next major update")
|
||||
fun <T: Any> RequestsExecutor.executeAsync(
|
||||
request: Request<T>,
|
||||
onFail: (suspend (Response) -> Unit)? = null,
|
||||
@ -24,6 +24,7 @@ fun <T: Any> RequestsExecutor.executeAsync(
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and modified inside of TelegramBotAPI-extensions-utils")
|
||||
fun <T: Any> RequestsExecutor.executeAsync(
|
||||
request: Request<T>,
|
||||
scope: CoroutineScope = GlobalScope
|
||||
@ -31,6 +32,7 @@ fun <T: Any> RequestsExecutor.executeAsync(
|
||||
return scope.async { execute(request) }
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and modified inside of TelegramBotAPI-extensions-utils")
|
||||
suspend fun <T: Any> RequestsExecutor.executeUnsafe(
|
||||
request: Request<T>,
|
||||
retries: Int = 0,
|
||||
|
@ -2,13 +2,13 @@ kotlin.code.style=official
|
||||
kotlin_version=1.3.72
|
||||
kotlin_coroutines_version=1.3.6
|
||||
kotlin_serialisation_runtime_version=0.20.0
|
||||
klock_version=1.11.1
|
||||
klock_version=1.11.3
|
||||
uuid_version=0.1.0
|
||||
ktor_version=1.3.2
|
||||
|
||||
javax_activation_version=1.1.1
|
||||
|
||||
library_group=com.github.insanusmokrassar
|
||||
library_version=0.27.4
|
||||
library_version=0.27.5
|
||||
|
||||
gradle_bintray_plugin_version=1.8.4
|
||||
|
Loading…
Reference in New Issue
Block a user