1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

add support of custom emojies in mv2 and html

This commit is contained in:
InsanusMokrassar 2023-04-21 20:47:13 +06:00
parent 68f6d8553c
commit 9a5a196e41
4 changed files with 11 additions and 6 deletions

View File

@ -13,8 +13,9 @@ import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.longOrNull
import kotlin.jvm.JvmInline
const val internalTgLinksBeginning = "tg://"
const val internalLinkBeginning = "https://t.me"
const val internalUserLinkBeginning = "tg://user?id="
const val internalUserLinkBeginning = "${internalTgLinksBeginning}user?id="
@Serializable(ChatIdentifierSerializer::class)
@ClassCastsIncluded

View File

@ -41,7 +41,10 @@ typealias WebAppQueryId = String
@JvmInline
value class CustomEmojiId(
val string: String
)
) {
val appLink
get() = "${internalTgLinksBeginning}emoji?id=$this"
}
typealias Seconds = Int
typealias MilliSeconds = Long

View File

@ -16,8 +16,8 @@ data class CustomEmojiTextSource @RiskFeature(DirectInvocationOfTextSourceConstr
override val subsources: TextSourcesList
) : MultilevelTextSource {
override val markdown: String by lazy { source.customEmojiMarkdown() }
override val markdownV2: String by lazy { source.customEmojiMarkdownV2() }
override val html: String by lazy { source.customEmojiHTML() }
override val markdownV2: String by lazy { source.customEmojiMarkdownV2(customEmojiId) }
override val html: String by lazy { source.customEmojiHTML(customEmojiId) }
}
@Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_API_USAGE")

View File

@ -24,6 +24,7 @@ const val htmlCodeControl = "code"
const val htmlPreControl = "pre"
const val htmlUnderlineControl = "u"
const val htmlStrikethroughControl = "s"
const val htmlCustomEmojiControl = "tg-emoji"
private fun String.markdownDefault(
openControlSymbol: String,
@ -120,8 +121,8 @@ internal fun String.commandMarkdownV2(): String = command(String::escapeMarkdown
internal fun String.commandHTML(): String = command(String::toHtml)
internal fun String.customEmojiMarkdown(): String = toMarkdown()
internal fun String.customEmojiMarkdownV2(): String = escapeMarkdownV2Common()
internal fun String.customEmojiHTML(): String = toHtml()
internal fun String.customEmojiMarkdownV2(customEmojiId: CustomEmojiId): String = "!${linkMarkdownV2(customEmojiId.appLink)}"
internal fun String.customEmojiHTML(customEmojiId: CustomEmojiId): String = "<$htmlCustomEmojiControl $htmlCustomEmojiControl=\"${customEmojiId.string}\">$this</$htmlCustomEmojiControl>"
internal fun String.regularMarkdown(): String = toMarkdown()
internal fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()