mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-02-18 04:31:52 +00:00
added support of strikethrough and underline
This commit is contained in:
parent
bba37d8889
commit
e7495468a2
@ -11,6 +11,10 @@ bot.
|
|||||||
|
|
||||||
## 0.20.0 MPP Migration
|
## 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`
|
* Time library change: `joda-time` -> `com.soywiz.korlibs.klock:klock`
|
||||||
* `Currencied` now using as `currency` value with type `String`
|
* `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
|
* For `Java` there is `Currencied#javaCurrency` extension function, which will give an old currency work way
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.internal.ArrayListSerializer
|
import kotlinx.serialization.internal.ArrayListSerializer
|
||||||
@ -28,7 +29,9 @@ internal data class RawMessageEntity(
|
|||||||
"code" -> CodeTextMessageEntity(offset, length, sourceSubstring)
|
"code" -> CodeTextMessageEntity(offset, length, sourceSubstring)
|
||||||
"pre" -> PreTextMessageEntity(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_link" -> TextLinkMessageEntity(offset, length, sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link"))
|
||||||
"text_mention" -> TextMentionMessageEntity(offset, length, sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"))
|
"text_mention" -> TextMentionMessageEntity(offset, length, sourceSubstring, user as PrivateChat)
|
||||||
|
"underline" -> UnderlineMessageEntity(offset, length, sourceSubstring)
|
||||||
|
"strikethrough" -> StrikethroughMessageEntity(offset, length, sourceSubstring)
|
||||||
else -> throw IllegalArgumentException("Unknown type of message entity")
|
else -> throw IllegalArgumentException("Unknown type of message entity")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.StrikethroughTextSource
|
||||||
|
|
||||||
|
class StrikethroughMessageEntity(
|
||||||
|
override val offset: Int,
|
||||||
|
override val length: Int,
|
||||||
|
override val sourceString: String
|
||||||
|
) : MessageEntity, TextSource by StrikethroughTextSource(sourceString)
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.UnderlineTextSource
|
||||||
|
|
||||||
|
class UnderlineMessageEntity(
|
||||||
|
override val offset: Int,
|
||||||
|
override val length: Int,
|
||||||
|
override val sourceString: String
|
||||||
|
) : MessageEntity, TextSource by UnderlineTextSource(sourceString)
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.strikethroughHTML
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.strikethroughMarkdown
|
||||||
|
|
||||||
|
class StrikethroughTextSource(
|
||||||
|
sourceString: String
|
||||||
|
) : TextSource {
|
||||||
|
override val asHtmlSource: String = sourceString.strikethroughHTML()
|
||||||
|
override val asMarkdownSource: String = sourceString.strikethroughMarkdown()
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.underlineHTML
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.underlineMarkdown
|
||||||
|
|
||||||
|
class UnderlineTextSource(
|
||||||
|
sourceString: String
|
||||||
|
) : TextSource {
|
||||||
|
override val asMarkdownSource: String = sourceString.underlineMarkdown()
|
||||||
|
override val asHtmlSource: String = sourceString.underlineHTML()
|
||||||
|
}
|
@ -41,6 +41,19 @@ fun String.preHTML(): String = htmlDefault(htmlPreControl)
|
|||||||
fun String.emailMarkdown(): String = linkMarkdown("mailto://$this")
|
fun String.emailMarkdown(): String = linkMarkdown("mailto://$this")
|
||||||
fun String.emailHTML(): String = linkHTML("mailto://$this")
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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")
|
||||||
|
|
||||||
|
|
||||||
private inline infix fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
private inline infix fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
||||||
this
|
this
|
||||||
|
Loading…
x
Reference in New Issue
Block a user