mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
StringFormattiing replacement
This commit is contained in:
parent
648f1b488b
commit
0a162c4129
@ -58,10 +58,12 @@
|
|||||||
* Fix: for sending requests caption and text lengths limits were updated
|
* Fix: for sending requests caption and text lengths limits were updated
|
||||||
* New variant of `row` was added
|
* New variant of `row` was added
|
||||||
* `makeLinkToMessage` extensions has been deprecated (replaced into `TelegramBotAPI-extensions-utils`)
|
* `makeLinkToMessage` extensions has been deprecated (replaced into `TelegramBotAPI-extensions-utils`)
|
||||||
|
* All `String` formatting public extensions and functions was deprecated and replaced into `TelegramBotAPI-extensions-utils`
|
||||||
* `TelegramBotAPI-extensions-utils`:
|
* `TelegramBotAPI-extensions-utils`:
|
||||||
* `safely` function was introduced. It is in `PreviewFeature` state currently
|
* `safely` function was introduced. It is in `PreviewFeature` state currently
|
||||||
* `makeLinkToMessage` extensions has been added
|
* `makeLinkToMessage` extensions has been added
|
||||||
* `makeLinkToAddStickerSet` function and its variations were added
|
* `makeLinkToAddStickerSet` function and its variations were added
|
||||||
|
* All `String` formatting extensions and functions from `TelegramBotAPI` was added
|
||||||
|
|
||||||
### 0.27.4
|
### 0.27.4
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.formatting
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||||
@ -24,7 +24,8 @@ fun makeLinkToMessage(
|
|||||||
): String? {
|
): String? {
|
||||||
return when {
|
return when {
|
||||||
chat is UsernameChat && chat.username != null -> {
|
chat is UsernameChat && chat.username != null -> {
|
||||||
"$internalLinkBeginning/${chat.username ?.username ?.replace(usernameBeginSymbolRegex, "")}/$messageId"
|
"$internalLinkBeginning/${chat.username ?.username ?.replace(
|
||||||
|
usernameBeginSymbolRegex, "")}/$messageId"
|
||||||
}
|
}
|
||||||
chat !is PrivateChat -> chat.id.chatId.toString().replace(
|
chat !is PrivateChat -> chat.id.chatId.toString().replace(
|
||||||
linkIdRedundantPartRegex,
|
linkIdRedundantPartRegex,
|
||||||
@ -56,21 +57,24 @@ fun makeLinkToAddStickerSet(
|
|||||||
/**
|
/**
|
||||||
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [MarkdownV2]
|
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [MarkdownV2]
|
||||||
*/
|
*/
|
||||||
fun makeLinkToAddStickerSetInMarkdownV2(stickerSetName: StickerSetName) = makeLinkToAddStickerSet(
|
fun makeLinkToAddStickerSetInMarkdownV2(stickerSetName: StickerSetName) =
|
||||||
stickerSetName,
|
makeLinkToAddStickerSet(
|
||||||
MarkdownV2
|
stickerSetName,
|
||||||
)
|
MarkdownV2
|
||||||
|
)
|
||||||
/**
|
/**
|
||||||
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [Markdown]
|
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [Markdown]
|
||||||
*/
|
*/
|
||||||
fun makeLinkToAddStickerSetInMarkdown(stickerSetName: StickerSetName) = makeLinkToAddStickerSet(
|
fun makeLinkToAddStickerSetInMarkdown(stickerSetName: StickerSetName) =
|
||||||
stickerSetName,
|
makeLinkToAddStickerSet(
|
||||||
Markdown
|
stickerSetName,
|
||||||
)
|
Markdown
|
||||||
|
)
|
||||||
/**
|
/**
|
||||||
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [HTML]
|
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [HTML]
|
||||||
*/
|
*/
|
||||||
fun makeLinkToAddStickerSetInHtml(stickerSetName: StickerSetName) = makeLinkToAddStickerSet(
|
fun makeLinkToAddStickerSetInHtml(stickerSetName: StickerSetName) =
|
||||||
stickerSetName,
|
makeLinkToAddStickerSet(
|
||||||
HTML
|
stickerSetName,
|
||||||
)
|
HTML
|
||||||
|
)
|
@ -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()
|
||||||
|
}
|
@ -36,50 +36,71 @@ private fun String.htmlDefault(
|
|||||||
closeControlSymbol: String = openControlSymbol
|
closeControlSymbol: String = openControlSymbol
|
||||||
) = "<$openControlSymbol>${toHtml()}</$closeControlSymbol>"
|
) = "<$openControlSymbol>${toHtml()}</$closeControlSymbol>"
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})"
|
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()})"
|
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>"
|
fun String.linkHTML(link: String): String = "<a href=\"$link\">${toHtml()}</a>"
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl)
|
fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl)
|
fun String.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.boldHTML(): String = htmlDefault(htmlBoldControl)
|
fun String.boldHTML(): String = htmlDefault(htmlBoldControl)
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl, markdownV2ItalicEndControl)
|
fun String.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl, markdownV2ItalicEndControl)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.italicHTML(): String = htmlDefault(htmlItalicControl)
|
fun String.italicHTML(): String = htmlDefault(htmlItalicControl)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crutch for support of strikethrough in default markdown. Simply add modifier, but it will not look like correct
|
* 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("")
|
fun String.strikethroughMarkdown(): String = map { it + "\u0336" }.joinToString("")
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl)
|
fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.strikethroughHTML(): String = htmlDefault(htmlStrikethroughControl)
|
fun String.strikethroughHTML(): String = htmlDefault(htmlStrikethroughControl)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crutch for support of underline in default markdown. Simply add modifier, but it will not look like correct
|
* 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("")
|
fun String.underlineMarkdown(): String = map { it + "\u0347" }.joinToString("")
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl)
|
fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl)
|
fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode)
|
fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.preMarkdown(language: String? = null): String = markdownDefault(
|
fun String.preMarkdown(language: String? = null): String = markdownDefault(
|
||||||
"$markdownPreControl${language ?: ""}\n",
|
"$markdownPreControl${language ?: ""}\n",
|
||||||
"\n$markdownPreControl"
|
"\n$markdownPreControl"
|
||||||
)
|
)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.preMarkdownV2(language: String? = null): String = markdownV2Default(
|
fun String.preMarkdownV2(language: String? = null): String = markdownV2Default(
|
||||||
"$markdownPreControl${language ?: ""}\n",
|
"$markdownPreControl${language ?: ""}\n",
|
||||||
"\n$markdownPreControl",
|
"\n$markdownPreControl",
|
||||||
String::escapeMarkdownV2PreAndCode
|
String::escapeMarkdownV2PreAndCode
|
||||||
)
|
)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.preHTML(language: String? = null): String = htmlDefault(
|
fun String.preHTML(language: String? = null): String = htmlDefault(
|
||||||
language ?.let {
|
language ?.let {
|
||||||
"$htmlPreControl><$htmlCodeControl class=\"language-$language\""
|
"$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()}")
|
fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}")
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.emailMarkdownV2(): String = linkMarkdownV2("mailto://$${toMarkdown()}")
|
fun String.emailMarkdownV2(): String = linkMarkdownV2("mailto://$${toMarkdown()}")
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.emailHTML(): String = linkHTML("mailto://$${toHtml()}")
|
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("@")) {
|
private inline fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
||||||
adapt()
|
adapt()
|
||||||
} else {
|
} 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("#")) {
|
private inline fun String.hashTag(adapt: String.() -> String): String = if (startsWith("#")) {
|
||||||
adapt()
|
adapt()
|
||||||
} else {
|
} 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)
|
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)
|
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)
|
fun String.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.mentionMarkdownV2(): String = mention(String::escapeMarkdownV2Common)
|
fun String.mentionMarkdownV2(): String = mention(String::escapeMarkdownV2Common)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.mentionHTML(): String = mention(String::toHtml)
|
fun String.mentionHTML(): String = mention(String::toHtml)
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common()
|
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common()
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.phoneMarkdown(): String = toMarkdown()
|
fun String.phoneMarkdown(): String = toMarkdown()
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.phoneMarkdownV2(): String = escapeMarkdownV2Common()
|
fun String.phoneMarkdownV2(): String = escapeMarkdownV2Common()
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.phoneHTML(): String = toHtml()
|
fun String.phoneHTML(): String = toHtml()
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.command(adapt: String.() -> String): String = if (startsWith("/")) {
|
fun String.command(adapt: String.() -> String): String = if (startsWith("/")) {
|
||||||
adapt()
|
adapt()
|
||||||
} else {
|
} else {
|
||||||
"/${adapt()}"
|
"/${adapt()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.commandMarkdown(): String = command(String::toMarkdown)
|
fun String.commandMarkdown(): String = command(String::toMarkdown)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common)
|
fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common)
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.commandHTML(): String = command(String::toHtml)
|
fun String.commandHTML(): String = command(String::toHtml)
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.regularMarkdown(): String = toMarkdown()
|
fun String.regularMarkdown(): String = toMarkdown()
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()
|
fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.regularHtml(): String = toHtml()
|
fun String.regularHtml(): String = toHtml()
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.cashTagMarkdown(): String = toMarkdown()
|
fun String.cashTagMarkdown(): String = toMarkdown()
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.cashTagMarkdownV2(): String = escapeMarkdownV2Common()
|
fun String.cashTagMarkdownV2(): String = escapeMarkdownV2Common()
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.cashTagHtml(): String = toHtml()
|
fun String.cashTagHtml(): String = toHtml()
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.bold(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.bold(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> boldHTML()
|
is HTML -> boldHTML()
|
||||||
is Markdown -> boldMarkdown()
|
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) {
|
infix fun String.italic(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> italicHTML()
|
is HTML -> italicHTML()
|
||||||
is Markdown -> italicMarkdown()
|
is Markdown -> italicMarkdown()
|
||||||
is MarkdownV2 -> italicMarkdownV2()
|
is MarkdownV2 -> italicMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.hashTag(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.hashTag(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> hashTagHTML()
|
is HTML -> hashTagHTML()
|
||||||
is Markdown -> hashTagMarkdown()
|
is Markdown -> hashTagMarkdown()
|
||||||
is MarkdownV2 -> hashTagMarkdownV2()
|
is MarkdownV2 -> hashTagMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.code(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.code(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> codeHTML()
|
is HTML -> codeHTML()
|
||||||
is Markdown -> codeMarkdown()
|
is Markdown -> codeMarkdown()
|
||||||
is MarkdownV2 -> codeMarkdownV2()
|
is MarkdownV2 -> codeMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
fun String.pre(parseMode: ParseMode, language: String? = null): String = when (parseMode) {
|
fun String.pre(parseMode: ParseMode, language: String? = null): String = when (parseMode) {
|
||||||
is HTML -> preHTML(language)
|
is HTML -> preHTML(language)
|
||||||
is Markdown -> preMarkdown(language)
|
is Markdown -> preMarkdown(language)
|
||||||
is MarkdownV2 -> preMarkdownV2(language)
|
is MarkdownV2 -> preMarkdownV2(language)
|
||||||
}
|
}
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.pre(parseMode: ParseMode): String = pre(parseMode, null)
|
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) {
|
infix fun String.email(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> emailHTML()
|
is HTML -> emailHTML()
|
||||||
is Markdown -> emailMarkdown()
|
is Markdown -> emailMarkdown()
|
||||||
is MarkdownV2 -> emailMarkdownV2()
|
is MarkdownV2 -> emailMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun Pair<String, String>.link(parseMode: ParseMode): String = when (parseMode) {
|
infix fun Pair<String, String>.link(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> first.linkHTML(second)
|
is HTML -> first.linkHTML(second)
|
||||||
is Markdown -> first.linkMarkdown(second)
|
is Markdown -> first.linkMarkdown(second)
|
||||||
is MarkdownV2 -> first.linkMarkdownV2(second)
|
is MarkdownV2 -> first.linkMarkdownV2(second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.mention(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> mentionHTML()
|
is HTML -> mentionHTML()
|
||||||
is Markdown -> mentionMarkdown()
|
is Markdown -> mentionMarkdown()
|
||||||
is MarkdownV2 -> mentionMarkdownV2()
|
is MarkdownV2 -> mentionMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun Pair<String, ChatId>.mention(parseMode: ParseMode): String = when (parseMode) {
|
infix fun Pair<String, ChatId>.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> first.textMentionHTML(second)
|
is HTML -> first.textMentionHTML(second)
|
||||||
is Markdown -> first.textMentionMarkdown(second)
|
is Markdown -> first.textMentionMarkdown(second)
|
||||||
is MarkdownV2 -> first.textMentionMarkdownV2(second)
|
is MarkdownV2 -> first.textMentionMarkdownV2(second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.phone(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.phone(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> phoneHTML()
|
is HTML -> phoneHTML()
|
||||||
is Markdown -> phoneMarkdown()
|
is Markdown -> phoneMarkdown()
|
||||||
is MarkdownV2 -> phoneMarkdownV2()
|
is MarkdownV2 -> phoneMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> commandHTML()
|
is HTML -> commandHTML()
|
||||||
is Markdown -> commandMarkdown()
|
is Markdown -> commandMarkdown()
|
||||||
is MarkdownV2 -> commandMarkdownV2()
|
is MarkdownV2 -> commandMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> underlineHTML()
|
is HTML -> underlineHTML()
|
||||||
is Markdown -> underlineMarkdown()
|
is Markdown -> underlineMarkdown()
|
||||||
is MarkdownV2 -> underlineMarkdownV2()
|
is MarkdownV2 -> underlineMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.strikethrough(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.strikethrough(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> strikethroughHTML()
|
is HTML -> strikethroughHTML()
|
||||||
is Markdown -> strikethroughMarkdown()
|
is Markdown -> strikethroughMarkdown()
|
||||||
is MarkdownV2 -> strikethroughMarkdownV2()
|
is MarkdownV2 -> strikethroughMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.regular(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.regular(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> regularHtml()
|
is HTML -> regularHtml()
|
||||||
is Markdown -> regularMarkdown()
|
is Markdown -> regularMarkdown()
|
||||||
is MarkdownV2 -> regularMarkdownV2()
|
is MarkdownV2 -> regularMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||||
infix fun String.cashtag(parseMode: ParseMode): String = when (parseMode) {
|
infix fun String.cashtag(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> cashTagHtml()
|
is HTML -> cashTagHtml()
|
||||||
is Markdown -> cashTagMarkdown()
|
is Markdown -> cashTagMarkdown()
|
||||||
|
Loading…
Reference in New Issue
Block a user