diff --git a/CHANGELOG.md b/CHANGELOG.md index d693385ccf..8dac4d4575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ ## 0.21.0 TelegramBotAPI 4.5 +* Added support of strikethrough and underline + * Added `UnderlineTextSource` and `UnderlineMessageEntity` + * Added `StrikethroughTextSource` and `StrikethroughMessageEntity` + * Added support in `RawMessageEntity` +* Now `TextSource` have its `rawSource` const + * `sourceString` in `MessageEntity` now is deprecated + * All `MessageEntity` classes now have no income parameter `sourceString` + * In most part of `TextSource` classes `asMarkdownSource` and `asHtmlSource` now are getters instead if fields + * All parseMode-specific functions in `StringFormatting` now are not `infix` +* Removed constructor of `TextMentionMessageEntity`, which was deprecated previously +* Removed constructor of `TextMentionTextSource`, which was deprecated previously * All `TelegramMediaFile` instances now have field `fileUniqueId`, which represents `file_unique_id` field from API * Now `ChatPhoto` have two additional fields: `smallFileUniqueId` and `bigFileUniqueId` * Now any administrator object instance have `customTitle` nullable field @@ -11,10 +22,6 @@ bot. ## 0.20.0 MPP Migration -* Added support of strikethrough and underline - * Added `UnderlineTextSource` and `UnderlineMessageEntity` - * Added `StrikethroughTextSource` and `StrikethroughMessageEntity` - * Added support in `RawMessageEntity` * Time library change: `joda-time` -> `com.soywiz.korlibs.klock:klock` * `Currencied` now using as `currency` value with type `String` * For `Java` there is `Currencied#javaCurrency` extension function, which will give an old currency work way diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt index 6a40155809..0369f0dbc8 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts interface TextSource { + val rawSource: String val asMarkdownSource: String val asHtmlSource: String } \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BoldTextMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BoldTextMessageEntity.kt index 2e02d6b935..ef5b0dbc96 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BoldTextMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BoldTextMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.boldMarkdown data class BoldTextMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by BoldTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by BoldTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt index 088956a44b..8e755225db 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt @@ -8,8 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown data class BotCommandMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String, - private val botCommandTextSource: BotCommandTextSource = BotCommandTextSource(sourceString) + override val rawSource: String, + private val botCommandTextSource: BotCommandTextSource = BotCommandTextSource(rawSource) ) : MessageEntity, TextSource by botCommandTextSource { val command: String get() = botCommandTextSource.command diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/CodeTextMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/CodeTextMessageEntity.kt index bb45546d75..6b65c2e0a7 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/CodeTextMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/CodeTextMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.codeMarkdown data class CodeTextMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by CodeTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by CodeTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/EMailMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/EMailMessageEntity.kt index f5456fbdea..342bd7b5d4 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/EMailMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/EMailMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.emailMarkdown data class EMailMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by EMailTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by EMailTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/HashTagMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/HashTagMessageEntity.kt index 63733e5d8a..65dd2c2ac1 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/HashTagMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/HashTagMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagMarkdown data class HashTagMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by HashTagTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by HashTagTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/ItalicTextMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/ItalicTextMessageEntity.kt index db25785295..38d9510bb3 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/ItalicTextMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/ItalicTextMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.italicMarkdown data class ItalicTextMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by ItalicTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by ItalicTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MentionMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MentionMessageEntity.kt index 9886f4592e..de484c6925 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MentionMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MentionMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown class MentionMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by MentionTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by MentionTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt index 79a68f9997..0021ec72a1 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt @@ -5,5 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource interface MessageEntity : TextSource { val offset: Int val length: Int + @Deprecated("Due to opportunity to get the same string from rawSource const", ReplaceWith("rawSource")) val sourceString: String + get() = rawSource } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PhoneNumberMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PhoneNumberMessageEntity.kt index 79a5fb5357..dfc3710bab 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PhoneNumberMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PhoneNumberMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneMarkdown data class PhoneNumberMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by PhoneNumberTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by PhoneNumberTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PreTextMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PreTextMessageEntity.kt index 80943d942b..b28c189c26 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PreTextMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/PreTextMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.preMarkdown data class PreTextMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by PreTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by PreTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RawMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RawMessageEntity.kt index 83fc584dd5..b732fcb1dc 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RawMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RawMessageEntity.kt @@ -29,7 +29,7 @@ internal data class RawMessageEntity( "code" -> CodeTextMessageEntity(offset, length, sourceSubstring) "pre" -> PreTextMessageEntity(offset, length, sourceSubstring) "text_link" -> TextLinkMessageEntity(offset, length, sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link")) - "text_mention" -> TextMentionMessageEntity(offset, length, sourceSubstring, user as PrivateChat) + "text_mention" -> TextMentionMessageEntity(offset, length, sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention")) "underline" -> UnderlineMessageEntity(offset, length, sourceSubstring) "strikethrough" -> StrikethroughMessageEntity(offset, length, sourceSubstring) else -> throw IllegalArgumentException("Unknown type of message entity") diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RegularTextMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RegularTextMessageEntity.kt index b7e683f80a..b9834832d0 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RegularTextMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/RegularTextMessageEntity.kt @@ -8,5 +8,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown data class RegularTextMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by RegularTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by RegularTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/StrikethroughMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/StrikethroughMessageEntity.kt index 494980e8d0..315abd4309 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/StrikethroughMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/StrikethroughMessageEntity.kt @@ -6,5 +6,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsource class StrikethroughMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by StrikethroughTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by StrikethroughTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextLinkMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextLinkMessageEntity.kt index 576f8043bc..4a8f704ded 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextLinkMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextLinkMessageEntity.kt @@ -8,6 +8,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown data class TextLinkMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String, + override val rawSource: String, val url: String -) : MessageEntity, TextSource by TextLinkTextSource(sourceString, url) +) : MessageEntity, TextSource by TextLinkTextSource(rawSource, url) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt index ad7334e9af..7a4f8aaa89 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/TextMentionMessageEntity.kt @@ -10,14 +10,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown class TextMentionMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String, + override val rawSource: String, val privateChat: PrivateChat -) : MessageEntity, TextSource by TextMentionTextSource(sourceString, privateChat) { - @Deprecated("Deprecated due to the fact that there is more common constructor") - constructor( - offset: Int, - length: Int, - sourceString: String, - user: User - ) : this(offset, length, sourceString, user as PrivateChat) -} +) : MessageEntity, TextSource by TextMentionTextSource(rawSource, privateChat) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/URLMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/URLMessageEntity.kt index 482ad28fe6..61df04059b 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/URLMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/URLMessageEntity.kt @@ -8,7 +8,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown data class URLMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by URLTextSource(sourceString) { - val url: String = sourceString + override val rawSource: String +) : MessageEntity, TextSource by URLTextSource(rawSource) { + val url: String + get() = rawSource } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/UnderlineMessageEntity.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/UnderlineMessageEntity.kt index 7f630187cb..29519fdf64 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/UnderlineMessageEntity.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/UnderlineMessageEntity.kt @@ -6,5 +6,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsource class UnderlineMessageEntity( override val offset: Int, override val length: Int, - override val sourceString: String -) : MessageEntity, TextSource by UnderlineTextSource(sourceString) + override val rawSource: String +) : MessageEntity, TextSource by UnderlineTextSource(rawSource) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BoldTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BoldTextSource.kt index 9d1a1f7d7e..fda182dc83 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BoldTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BoldTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.boldHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.boldMarkdown class BoldTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.boldMarkdown() - override val asHtmlSource: String = sourceString.boldHTML() + override val asMarkdownSource: String + get() = rawSource.boldMarkdown() + override val asHtmlSource: String + get() = rawSource.boldHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BotCommandTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BotCommandTextSource.kt index 2c6eb4e0a3..0eb749548f 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -7,12 +7,14 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown private val commandRegex = Regex("[/!][^@\\s]*") class BotCommandTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.commandMarkdown() - override val asHtmlSource: String = sourceString.commandHTML() + override val asMarkdownSource: String + get() = rawSource.commandMarkdown() + override val asHtmlSource: String + get() = rawSource.commandHTML() val command: String by lazy { - commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!" + commandRegex.find(rawSource) ?.value ?.substring(1) ?: rawSource.substring(1)// skip first symbol like "/" or "!" } } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/CodeTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/CodeTextSource.kt index ab0066a60b..0ff5d3334a 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/CodeTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/CodeTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.codeHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.codeMarkdown class CodeTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.codeMarkdown() - override val asHtmlSource: String = sourceString.codeHTML() + override val asMarkdownSource: String + get() = rawSource.codeMarkdown() + override val asHtmlSource: String + get() = rawSource.codeHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/EMailTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/EMailTextSource.kt index 34b5ed34ce..135b31df98 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/EMailTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/EMailTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.emailHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.emailMarkdown class EMailTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.emailMarkdown() - override val asHtmlSource: String = sourceString.emailHTML() + override val asMarkdownSource: String + get() = rawSource.emailMarkdown() + override val asHtmlSource: String + get() = rawSource.emailHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/HashTagTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/HashTagTextSource.kt index 4894fabecf..fb5302d769 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/HashTagTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagMarkdown class HashTagTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.hashTagMarkdown() - override val asHtmlSource: String = sourceString.hashTagHTML() + override val asMarkdownSource: String + get() = rawSource.hashTagMarkdown() + override val asHtmlSource: String + get() = rawSource.hashTagHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/ItalicTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/ItalicTextSource.kt index 2e1d1170e0..2027728f64 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/ItalicTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.italicHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.italicMarkdown class ItalicTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.italicMarkdown() - override val asHtmlSource: String = sourceString.italicHTML() + override val asMarkdownSource: String + get() = rawSource.italicMarkdown() + override val asHtmlSource: String + get() = rawSource.italicHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/MentionTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/MentionTextSource.kt index 8d2b0cc71a..a865ef6df4 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/MentionTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/MentionTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown class MentionTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.mentionMarkdown() - override val asHtmlSource: String = sourceString.mentionHTML() + override val asMarkdownSource: String + get() = rawSource.mentionMarkdown() + override val asHtmlSource: String + get() = rawSource.mentionHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PhoneNumberTextSource.kt index f5004fa7d5..d9948a3ea2 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneMarkdown class PhoneNumberTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.phoneMarkdown() - override val asHtmlSource: String = sourceString.phoneHTML() + override val asMarkdownSource: String + get() = rawSource.phoneMarkdown() + override val asHtmlSource: String + get() = rawSource.phoneHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PreTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PreTextSource.kt index 7a0fea96dc..dd8abe9637 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PreTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/PreTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.preHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.preMarkdown class PreTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.preMarkdown() - override val asHtmlSource: String = sourceString.preHTML() + override val asMarkdownSource: String + get() = rawSource.preMarkdown() + override val asHtmlSource: String + get() = rawSource.preHTML() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/RegularTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/RegularTextSource.kt index 0125346add..e35c6bd53b 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/RegularTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/RegularTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown class RegularTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.toMarkdown() - override val asHtmlSource: String = sourceString.toHtml() + override val asMarkdownSource: String + get() = rawSource.toMarkdown() + override val asHtmlSource: String + get() = rawSource.toHtml() } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/StrikethroughTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/StrikethroughTextSource.kt index 2cd6305be3..fa7d3b74cd 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.strikethroughHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.strikethroughMarkdown class StrikethroughTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asHtmlSource: String = sourceString.strikethroughHTML() - override val asMarkdownSource: String = sourceString.strikethroughMarkdown() + override val asHtmlSource: String + get() = rawSource.strikethroughHTML() + override val asMarkdownSource: String + get() = rawSource.strikethroughMarkdown() } \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextLinkTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextLinkTextSource.kt index a9e7ae225a..7356ac0b31 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextLinkTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextLinkTextSource.kt @@ -5,9 +5,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown class TextLinkTextSource( - sourceString: String, + override val rawSource: String, url: String ) : TextSource { - override val asMarkdownSource: String = sourceString.linkMarkdown(url) - override val asHtmlSource: String = sourceString.linkHTML(url) + override val asMarkdownSource: String = rawSource.linkMarkdown(url) + override val asHtmlSource: String = rawSource.linkHTML(url) } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextMentionTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextMentionTextSource.kt index 720436e8d7..3cc4643d55 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -7,15 +7,9 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown class TextMentionTextSource( - sourceString: String, + override val rawSource: String, privateChat: PrivateChat ) : TextSource { - @Deprecated("Deprecated due to the fact that there is more common constructor") - constructor( - sourceString: String, - user: User - ) : this(sourceString, user as PrivateChat) - - override val asMarkdownSource: String = sourceString.mentionMarkdown(privateChat.id) - override val asHtmlSource: String = sourceString.mentionHTML(privateChat.id) + override val asMarkdownSource: String = rawSource.mentionMarkdown(privateChat.id) + override val asHtmlSource: String = rawSource.mentionHTML(privateChat.id) } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/URLTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/URLTextSource.kt index 581af0f015..f96a169373 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/URLTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/URLTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown class URLTextSource( - sourceString: String + override val rawSource: String ) : TextSource{ - override val asMarkdownSource: String = sourceString.linkMarkdown(sourceString) - override val asHtmlSource: String = sourceString.linkHTML(sourceString) + override val asMarkdownSource: String + get() = rawSource.linkMarkdown(rawSource) + override val asHtmlSource: String + get() = rawSource.linkHTML(rawSource) } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/UnderlineTextSource.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/UnderlineTextSource.kt index f0d6ed4904..d7cef33cdc 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -5,8 +5,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.underlineHTML import com.github.insanusmokrassar.TelegramBotAPI.utils.underlineMarkdown class UnderlineTextSource( - sourceString: String + override val rawSource: String ) : TextSource { - override val asMarkdownSource: String = sourceString.underlineMarkdown() - override val asHtmlSource: String = sourceString.underlineHTML() + override val asMarkdownSource: String + get() = rawSource.underlineMarkdown() + override val asHtmlSource: String + get() = rawSource.underlineHTML() } \ No newline at end of file diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt index 7a1c6e7238..d9c5266817 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/StringFormatting.kt @@ -14,12 +14,14 @@ 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 infix fun String.markdownDefault(controlSymbol: String) = "$controlSymbol$this$controlSymbol" -private infix fun String.htmlDefault(controlSymbol: String) = "<$controlSymbol>$this" +private fun String.markdownDefault(controlSymbol: String) = "$controlSymbol$this$controlSymbol" +private fun String.htmlDefault(controlSymbol: String) = "<$controlSymbol>$this" -infix fun String.linkMarkdown(link: String): String = "[$this]($link)" -infix fun String.linkHTML(link: String): String = "$this" +fun String.linkMarkdown(link: String): String = "[$this]($link)" +fun String.linkHTML(link: String): String = "$this" fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl) @@ -45,32 +47,32 @@ fun String.emailHTML(): String = linkHTML("mailto://$this") * 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.strikethroughHTML(): String = htmlDefault("s") +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.underlineHTML(): String = htmlDefault("u") +fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl) -private inline infix fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) { +private inline fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) { this } else { "@${adapt()}" } -private inline infix fun String.hashTag(adapt: String.() -> String): String = if (startsWith("#")) { +private inline fun String.hashTag(adapt: String.() -> String): String = if (startsWith("#")) { this } else { "#${adapt()}" } -infix fun String.mentionMarkdown(userId: UserId): String = linkMarkdown(userId.link) -infix fun String.mentionHTML(userId: UserId): String = linkHTML(userId.link) +fun String.mentionMarkdown(userId: UserId): String = linkMarkdown(userId.link) +fun String.mentionHTML(userId: UserId): String = linkHTML(userId.link) fun String.mentionMarkdown(): String = mention(String::toMarkdown) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt index 9c2c4d9c33..040c6aa846 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt @@ -7,6 +7,12 @@ fun String.toMarkdown(): String { ).replace( "_", "\\_" + ).replace( + "`", + "\\`" + ).replace( + "[", + "\\[" ) }