mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
Merge pull request #54 from InsanusMokrassar/0.21.0
0.21.0 TelegramBotAPI 4.5
This commit is contained in:
commit
031c61a872
25
CHANGELOG.md
25
CHANGELOG.md
@ -1,5 +1,30 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 0.21.0 TelegramBotAPI 4.5
|
||||||
|
|
||||||
|
* _**All `MessageEntity`'es now are replaced with `TextPart`**_
|
||||||
|
* Added support of strikethrough and underline
|
||||||
|
* Added `UnderlineTextSource`
|
||||||
|
* Added `StrikethroughTextSource`
|
||||||
|
* Added support in `RawMessageEntity`
|
||||||
|
* Added support of `MarkdownV2`
|
||||||
|
* Now will not be thrown exception when there is income unknown type of `RawMessageEntity`. Instead of this will be
|
||||||
|
created `RegularTextSource` with the same text
|
||||||
|
* Fixed problem that usually string formatting did not trigger escaping of control characters
|
||||||
|
* Actualized work with `pre` type of text - now it is possible to use `language` for formatting of text
|
||||||
|
* 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
|
||||||
|
* Added the new request `SetChatAdministratorCustomTitle` to manage the custom titles of administrators promoted by the
|
||||||
|
bot.
|
||||||
|
* Added the field `slowModeDelay` to the `ExtendedSupergroupChat` objects.
|
||||||
|
|
||||||
|
* `CaptionedInput` now have extension `fullEntitiesList` which will return list of `TextPart` with `RegularSource`'s
|
||||||
|
* `TextPart` added - it will be used as part of some text and can be not related to telegram bot
|
||||||
|
* `MultilevelTextSource` was added - it is type of `TextSource`, which can have subsources as parts of this text
|
||||||
|
* In all `TextSource`s all fields now are lazy for avoiding of potential risk for performance issues
|
||||||
|
|
||||||
## 0.20.0 MPP Migration
|
## 0.20.0 MPP Migration
|
||||||
|
|
||||||
* Time library change: `joda-time` -> `com.soywiz.korlibs.klock:klock`
|
* Time library change: `joda-time` -> `com.soywiz.korlibs.klock:klock`
|
||||||
|
@ -17,7 +17,7 @@ plugins {
|
|||||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
project.version = "0.20.4"
|
project.version = "0.21.0"
|
||||||
project.group = "com.github.insanusmokrassar"
|
project.group = "com.github.insanusmokrassar"
|
||||||
|
|
||||||
apply from: "publish.gradle"
|
apply from: "publish.gradle"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
|
||||||
|
|
||||||
interface Captioned {
|
interface Captioned {
|
||||||
val caption: String?
|
val caption: String?
|
||||||
@ -12,5 +12,7 @@ interface CaptionedOutput : Captioned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface CaptionedInput : Captioned {
|
interface CaptionedInput : Captioned {
|
||||||
val captionEntities: List<MessageEntity>
|
val captionEntities: List<TextPart>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun CaptionedInput.fullEntitiesList() = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()
|
||||||
|
@ -2,5 +2,16 @@ package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
|||||||
|
|
||||||
interface TextSource {
|
interface TextSource {
|
||||||
val asMarkdownSource: String
|
val asMarkdownSource: String
|
||||||
|
val asMarkdownV2Source: String
|
||||||
val asHtmlSource: String
|
val asHtmlSource: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface MultilevelTextSource : TextSource {
|
||||||
|
val textParts: List<TextPart>
|
||||||
|
}
|
||||||
|
|
||||||
|
data class TextPart(
|
||||||
|
val range: IntRange,
|
||||||
|
val source: TextSource
|
||||||
|
)
|
||||||
|
@ -9,8 +9,6 @@ import io.ktor.client.request.accept
|
|||||||
import io.ktor.client.request.url
|
import io.ktor.client.request.url
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
import io.ktor.http.HttpMethod
|
import io.ktor.http.HttpMethod
|
||||||
import kotlin.collections.MutableMap
|
|
||||||
import kotlin.collections.mutableMapOf
|
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.internal.BooleanSerializer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
||||||
|
*
|
||||||
|
* Please, remember about restrictions for characters in custom title
|
||||||
|
*/
|
||||||
|
@Serializable
|
||||||
|
data class SetChatAdministratorCustomTitle(
|
||||||
|
@SerialName(chatIdField)
|
||||||
|
override val chatId: ChatId,
|
||||||
|
@SerialName(userIdField)
|
||||||
|
override val userId: UserId,
|
||||||
|
@SerialName(customTitleField)
|
||||||
|
val customTitle: String
|
||||||
|
) : ChatMemberRequest<Boolean> {
|
||||||
|
override fun method(): String = "setChatAdministratorCustomTitle"
|
||||||
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
|
get() = BooleanSerializer
|
||||||
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
get() = RestrictChatMember.serializer()
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (customTitle.length !in customTitleLength) {
|
||||||
|
throw IllegalArgumentException("Custom title length must be in range $customTitleLength, but was ${customTitle.length}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,5 +13,6 @@ data class AdministratorChatMemberImpl(
|
|||||||
override val canInviteUsers: Boolean,
|
override val canInviteUsers: Boolean,
|
||||||
override val canRestrictMembers: Boolean,
|
override val canRestrictMembers: Boolean,
|
||||||
override val canPinMessages: Boolean,
|
override val canPinMessages: Boolean,
|
||||||
override val canPromoteMembers: Boolean
|
override val canPromoteMembers: Boolean,
|
||||||
|
override val customTitle: String?
|
||||||
) : AdministratorChatMember
|
) : AdministratorChatMember
|
||||||
|
@ -3,8 +3,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.AdministratorChatMember
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||||
|
|
||||||
data class CreatorChatMember(override val user: User) :
|
data class CreatorChatMember(
|
||||||
AdministratorChatMember {
|
override val user: User,
|
||||||
|
override val customTitle: String?
|
||||||
|
) : AdministratorChatMember {
|
||||||
override val canBeEdited: Boolean = true
|
override val canBeEdited: Boolean = true
|
||||||
override val canChangeInfo: Boolean = true
|
override val canChangeInfo: Boolean = true
|
||||||
override val canPostMessages: Boolean = true
|
override val canPostMessages: Boolean = true
|
||||||
|
@ -39,11 +39,13 @@ internal data class RawChatMember(
|
|||||||
@SerialName(canSendOtherMessagesField)
|
@SerialName(canSendOtherMessagesField)
|
||||||
private val canSendOtherMessages: Boolean = false,
|
private val canSendOtherMessages: Boolean = false,
|
||||||
@SerialName(canAddWebPagePreviewsField)
|
@SerialName(canAddWebPagePreviewsField)
|
||||||
private val canAddWebPagePreviews: Boolean = false
|
private val canAddWebPagePreviews: Boolean = false,
|
||||||
|
@SerialName(customTitleField)
|
||||||
|
private val customTitle: String? = null
|
||||||
) {
|
) {
|
||||||
val asChatMember: ChatMember by lazy {
|
val asChatMember: ChatMember by lazy {
|
||||||
when (status) {
|
when (status) {
|
||||||
"creator" -> CreatorChatMember(user)
|
"creator" -> CreatorChatMember(user, customTitle)
|
||||||
"administrator" -> AdministratorChatMemberImpl(
|
"administrator" -> AdministratorChatMemberImpl(
|
||||||
user,
|
user,
|
||||||
canBeEdited,
|
canBeEdited,
|
||||||
@ -54,7 +56,8 @@ internal data class RawChatMember(
|
|||||||
canInviteUsers,
|
canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages,
|
||||||
canPromoteMembers
|
canPromoteMembers,
|
||||||
|
customTitle
|
||||||
)
|
)
|
||||||
"member" -> MemberChatMember(user)
|
"member" -> MemberChatMember(user)
|
||||||
"restricted" -> RestrictedChatMember(
|
"restricted" -> RestrictedChatMember(
|
||||||
|
@ -7,4 +7,5 @@ interface AdministratorChatMember : SpecialRightsChatMember {
|
|||||||
val canRemoveMessages: Boolean
|
val canRemoveMessages: Boolean
|
||||||
val canRestrictMembers: Boolean
|
val canRestrictMembers: Boolean
|
||||||
val canPromoteMembers: Boolean
|
val canPromoteMembers: Boolean
|
||||||
|
val customTitle: String?
|
||||||
}
|
}
|
@ -5,8 +5,12 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ChatPhoto(
|
data class ChatPhoto(
|
||||||
@SerialName("small_file_id")
|
@SerialName(smallFileIdField)
|
||||||
val smallFileId: String,
|
val smallFileId: String,
|
||||||
@SerialName("big_file_id")
|
@SerialName(bigFileIdField)
|
||||||
val bigFileId: String
|
val bigFileId: String,
|
||||||
|
@SerialName(smallFileUniqueIdField)
|
||||||
|
val smallFileUniqueId: FileUniqueId,
|
||||||
|
@SerialName(bigFileUniqueIdField)
|
||||||
|
val bigFileUniqueId: FileUniqueId
|
||||||
)
|
)
|
||||||
|
@ -18,6 +18,7 @@ typealias StartParameter = String
|
|||||||
typealias InlineMessageIdentifier = String
|
typealias InlineMessageIdentifier = String
|
||||||
typealias PollIdentifier = String
|
typealias PollIdentifier = String
|
||||||
typealias StickerSetName = String
|
typealias StickerSetName = String
|
||||||
|
typealias FileUniqueId = String
|
||||||
|
|
||||||
val callbackQueryAnswerLength = 0 until 200
|
val callbackQueryAnswerLength = 0 until 200
|
||||||
val captionLength = 0 until 1024
|
val captionLength = 0 until 1024
|
||||||
@ -40,6 +41,8 @@ val livePeriodLimit = 60 .. 86400
|
|||||||
|
|
||||||
val inlineQueryAnswerResultsLimit = 0 .. 50
|
val inlineQueryAnswerResultsLimit = 0 .. 50
|
||||||
|
|
||||||
|
val customTitleLength = 0 .. 16
|
||||||
|
|
||||||
const val chatIdField = "chat_id"
|
const val chatIdField = "chat_id"
|
||||||
const val messageIdField = "message_id"
|
const val messageIdField = "message_id"
|
||||||
const val updateIdField = "update_id"
|
const val updateIdField = "update_id"
|
||||||
@ -57,6 +60,7 @@ const val languageCodeField = "language_code"
|
|||||||
const val textEntitiesField = "text_entities"
|
const val textEntitiesField = "text_entities"
|
||||||
const val stickerSetNameField = "set_name"
|
const val stickerSetNameField = "set_name"
|
||||||
const val stickerSetNameFullField = "sticker_set_name"
|
const val stickerSetNameFullField = "sticker_set_name"
|
||||||
|
const val slowModeDelayField = "slow_mode_delay"
|
||||||
const val maskPositionField = "mask_position"
|
const val maskPositionField = "mask_position"
|
||||||
const val phoneNumberField = "phone_number"
|
const val phoneNumberField = "phone_number"
|
||||||
const val userIdField = "user_id"
|
const val userIdField = "user_id"
|
||||||
@ -94,6 +98,7 @@ const val switchInlineQueryField = "switch_inline_query"
|
|||||||
const val isAnimatedField = "is_animated"
|
const val isAnimatedField = "is_animated"
|
||||||
const val inviteLinkField = "invite_link"
|
const val inviteLinkField = "invite_link"
|
||||||
const val pinnedMessageField = "pinned_message"
|
const val pinnedMessageField = "pinned_message"
|
||||||
|
const val customTitleField = "custom_title"
|
||||||
|
|
||||||
|
|
||||||
const val requestWriteAccessField = "request_write_access"
|
const val requestWriteAccessField = "request_write_access"
|
||||||
@ -217,6 +222,14 @@ const val yShiftField = "y_shift"
|
|||||||
const val scaleField = "scale"
|
const val scaleField = "scale"
|
||||||
|
|
||||||
|
|
||||||
|
const val smallFileIdField = "small_file_id"
|
||||||
|
const val bigFileIdField = "big_file_id"
|
||||||
|
const val smallFileUniqueIdField = "small_file_unique_id"
|
||||||
|
const val bigFileUniqueIdField = "big_file_unique_id"
|
||||||
|
|
||||||
|
const val fileUniqueIdField = "file_unique_id"
|
||||||
|
|
||||||
|
|
||||||
const val currencyField = "currency"
|
const val currencyField = "currency"
|
||||||
const val startParameterField = "start_parameter"
|
const val startParameterField = "start_parameter"
|
||||||
const val totalAmountField = "total_amount"
|
const val totalAmountField = "total_amount"
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.BoldTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.boldHTML
|
|
||||||
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)
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.BotCommandTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandHTML
|
|
||||||
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)
|
|
||||||
) : MessageEntity, TextSource by botCommandTextSource {
|
|
||||||
val command: String
|
|
||||||
get() = botCommandTextSource.command
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.CodeTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.codeHTML
|
|
||||||
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)
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.EMailTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.emailHTML
|
|
||||||
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)
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.HashTagTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagHTML
|
|
||||||
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)
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.ItalicTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.italicHTML
|
|
||||||
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)
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.MentionTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
|
||||||
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)
|
|
@ -1,9 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
|
|
||||||
interface MessageEntity : TextSource {
|
|
||||||
val offset: Int
|
|
||||||
val length: Int
|
|
||||||
val sourceString: String
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.PhoneNumberTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneHTML
|
|
||||||
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)
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.PreTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.preHTML
|
|
||||||
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)
|
|
@ -1,9 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||||
import kotlinx.serialization.KSerializer
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.shiftSourcesToTheLeft
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.internal.ArrayListSerializer
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
internal data class RawMessageEntity(
|
internal data class RawMessageEntity(
|
||||||
@ -12,30 +14,74 @@ internal data class RawMessageEntity(
|
|||||||
val length: Int,
|
val length: Int,
|
||||||
val url: String? = null,
|
val url: String? = null,
|
||||||
val user: User? = null
|
val user: User? = null
|
||||||
) {
|
)
|
||||||
fun asMessageEntity(source: String): MessageEntity {
|
|
||||||
|
internal fun RawMessageEntity.asTextParts(source: String, subParts: List<TextPart>): List<TextPart> {
|
||||||
val sourceSubstring = source.substring(offset, offset + length)
|
val sourceSubstring = source.substring(offset, offset + length)
|
||||||
|
val range = offset until (offset + length)
|
||||||
|
val shiftedSubParts = subParts.shiftSourcesToTheLeft(offset)
|
||||||
return when (type) {
|
return when (type) {
|
||||||
"mention" -> MentionMessageEntity(offset, length, sourceSubstring)
|
"mention" -> MentionTextSource(sourceSubstring, shiftedSubParts)
|
||||||
"hashtag" -> HashTagMessageEntity(offset, length, sourceSubstring)
|
"hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubParts)
|
||||||
"cashtag" -> TODO()
|
"cashtag" -> TODO()
|
||||||
"bot_command" -> BotCommandMessageEntity(offset, length, sourceSubstring)
|
"bot_command" -> BotCommandTextSource(sourceSubstring, shiftedSubParts)
|
||||||
"url" -> URLMessageEntity(offset, length, sourceSubstring)
|
"url" -> URLTextSource(sourceSubstring)
|
||||||
"email" -> EMailMessageEntity(offset, length, sourceSubstring)
|
"email" -> EMailTextSource(sourceSubstring, shiftedSubParts)
|
||||||
"phone_number" -> PhoneNumberMessageEntity(offset, length, sourceSubstring)
|
"phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubParts)
|
||||||
"bold" -> BoldTextMessageEntity(offset, length, sourceSubstring)
|
"bold" -> BoldTextSource(sourceSubstring, shiftedSubParts)
|
||||||
"italic" -> ItalicTextMessageEntity(offset, length, sourceSubstring)
|
"italic" -> ItalicTextSource(sourceSubstring, shiftedSubParts)
|
||||||
"code" -> CodeTextMessageEntity(offset, length, sourceSubstring)
|
"code" -> CodeTextSource(sourceSubstring)
|
||||||
"pre" -> PreTextMessageEntity(offset, length, sourceSubstring)
|
"pre" -> PreTextSource(sourceSubstring)
|
||||||
"text_link" -> TextLinkMessageEntity(offset, length, sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link"))
|
"text_link" -> TextLinkTextSource(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" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), shiftedSubParts)
|
||||||
else -> throw IllegalArgumentException("Unknown type of message entity")
|
"underline" -> UnderlineTextSource(sourceSubstring, shiftedSubParts)
|
||||||
|
"strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubParts)
|
||||||
|
else -> RegularTextSource(sourceSubstring)
|
||||||
|
}.let {
|
||||||
|
val part = TextPart(range, it)
|
||||||
|
if (it !is MultilevelTextSource && subParts.isNotEmpty()) {
|
||||||
|
(subParts + part).sortedBy { currentPart -> currentPart.range.first }
|
||||||
|
} else {
|
||||||
|
listOf(part)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal typealias RawMessageEntities = List<RawMessageEntity>
|
internal fun createTextPart(from: String, entities: RawMessageEntities): List<TextPart> {
|
||||||
|
val mutableEntities = entities.toMutableList()
|
||||||
|
mutableEntities.sortBy { it.offset }
|
||||||
|
val resultList = mutableListOf<TextPart>()
|
||||||
|
|
||||||
internal object RawMessageEntitiesSerializer : KSerializer<List<RawMessageEntity>> by ArrayListSerializer(
|
while (mutableEntities.isNotEmpty()) {
|
||||||
RawMessageEntity.serializer()
|
val currentFirst = mutableEntities.removeAt(0)
|
||||||
)
|
val subEntities = if (mutableEntities.isNotEmpty()) {
|
||||||
|
val lastIndex = currentFirst.offset + currentFirst.length
|
||||||
|
val subEntities = mutableListOf<RawMessageEntity>()
|
||||||
|
while (mutableEntities.isNotEmpty()) {
|
||||||
|
val currentPossibleSubEntity = mutableEntities.first()
|
||||||
|
if (currentPossibleSubEntity.offset < lastIndex) {
|
||||||
|
subEntities.add(currentPossibleSubEntity)
|
||||||
|
mutableEntities.removeAt(0)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subEntities
|
||||||
|
} else {
|
||||||
|
emptyList<RawMessageEntity>()
|
||||||
|
}
|
||||||
|
|
||||||
|
resultList.addAll(
|
||||||
|
currentFirst.asTextParts(
|
||||||
|
from,
|
||||||
|
createTextPart(from, subEntities)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultList
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun RawMessageEntities.asTextParts(sourceString: String): List<TextPart> = createTextPart(sourceString, this)
|
||||||
|
|
||||||
|
internal typealias RawMessageEntities = List<RawMessageEntity>
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml
|
|
||||||
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)
|
|
@ -1,13 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.TextLinkTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown
|
|
||||||
|
|
||||||
data class TextLinkMessageEntity(
|
|
||||||
override val offset: Int,
|
|
||||||
override val length: Int,
|
|
||||||
override val sourceString: String,
|
|
||||||
val url: String
|
|
||||||
) : MessageEntity, TextSource by TextLinkTextSource(sourceString, url)
|
|
@ -1,23 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.TextMentionTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown
|
|
||||||
|
|
||||||
class TextMentionMessageEntity(
|
|
||||||
override val offset: Int,
|
|
||||||
override val length: Int,
|
|
||||||
override val sourceString: 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)
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.URLTextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
|
||||||
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
|
|
||||||
}
|
|
@ -1,12 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.boldHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.boldMarkdown
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
class BoldTextSource(
|
class BoldTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
override val asMarkdownSource: String = sourceString.boldMarkdown()
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String = sourceString.boldHTML()
|
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
|
||||||
|
override val asMarkdownSource: String by lazy { source.boldMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { boldMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { boldHTML() }
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,25 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
private val commandRegex = Regex("[/!][^@\\s]*")
|
private val commandRegex = Regex("[/!][^@\\s]*")
|
||||||
|
|
||||||
class BotCommandTextSource(
|
class BotCommandTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
override val asMarkdownSource: String = sourceString.commandMarkdown()
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String = sourceString.commandHTML()
|
|
||||||
|
|
||||||
val command: String by lazy {
|
val command: String by lazy {
|
||||||
commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!"
|
commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val textParts: List<TextPart> by lazy {
|
||||||
|
command.fullListOfSubSource(
|
||||||
|
textParts.shiftSourcesToTheLeft(1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
override val asMarkdownSource: String by lazy { source.commandMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { commandMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { commandHTML() }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.codeHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.codeMarkdown
|
|
||||||
|
|
||||||
class CodeTextSource(
|
class CodeTextSource(
|
||||||
sourceString: String
|
source: String
|
||||||
) : TextSource {
|
) : TextSource {
|
||||||
override val asMarkdownSource: String = sourceString.codeMarkdown()
|
override val asMarkdownSource: String by lazy { source.codeMarkdown() }
|
||||||
override val asHtmlSource: String = sourceString.codeHTML()
|
override val asMarkdownV2Source: String by lazy { source.codeMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { source.codeHTML() }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.emailHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.emailMarkdown
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
class EMailTextSource(
|
class EMailTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
override val asMarkdownSource: String = sourceString.emailMarkdown()
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String = sourceString.emailHTML()
|
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
|
||||||
|
override val asMarkdownSource: String by lazy { source.emailMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) }
|
||||||
|
override val asHtmlSource: String by lazy { emailHTML(source) }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,26 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.hashTagMarkdown
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
|
private val String.withoutSharp
|
||||||
|
get() = if (startsWith("#")){
|
||||||
|
substring(1)
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
class HashTagTextSource(
|
class HashTagTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
override val asMarkdownSource: String = sourceString.hashTagMarkdown()
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String = sourceString.hashTagHTML()
|
override val textParts: List<TextPart> by lazy {
|
||||||
|
source.withoutSharp.fullListOfSubSource(
|
||||||
|
textParts.shiftSourcesToTheLeft(1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
override val asMarkdownSource: String by lazy { source.hashTagMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { hashTagHTML() }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.italicHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.italicMarkdown
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
class ItalicTextSource(
|
class ItalicTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
override val asMarkdownSource: String = sourceString.italicMarkdown()
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String = sourceString.italicHTML()
|
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
|
||||||
|
override val asMarkdownSource: String by lazy { source.italicMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { italicMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { italicHTML() }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,26 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
|
private val String.withoutCommercialAt
|
||||||
|
get() = if (startsWith("@")) {
|
||||||
|
substring(1)
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
class MentionTextSource(
|
class MentionTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
override val asMarkdownSource: String = sourceString.mentionMarkdown()
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String = sourceString.mentionHTML()
|
override val textParts: List<TextPart> by lazy {
|
||||||
|
source.withoutCommercialAt.fullListOfSubSource(
|
||||||
|
textParts.shiftSourcesToTheLeft(1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
override val asMarkdownSource: String by lazy { source.mentionMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { mentionHTML() }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.phoneMarkdown
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
class PhoneNumberTextSource(
|
class PhoneNumberTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
override val asMarkdownSource: String = sourceString.phoneMarkdown()
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String = sourceString.phoneHTML()
|
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
|
||||||
|
override val asMarkdownSource: String by lazy { source.phoneMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { phoneHTML() }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.preHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.preMarkdown
|
|
||||||
|
|
||||||
class PreTextSource(
|
class PreTextSource(
|
||||||
sourceString: String
|
source: String,
|
||||||
|
val language: String? = null
|
||||||
) : TextSource {
|
) : TextSource {
|
||||||
override val asMarkdownSource: String = sourceString.preMarkdown()
|
override val asMarkdownSource: String by lazy { source.preMarkdown(language) }
|
||||||
override val asHtmlSource: String = sourceString.preHTML()
|
override val asMarkdownV2Source: String by lazy { source.preMarkdownV2(language) }
|
||||||
|
override val asHtmlSource: String by lazy { source.preHTML(language) }
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
|
|
||||||
|
|
||||||
class RegularTextSource(
|
class RegularTextSource(
|
||||||
sourceString: String
|
source: String
|
||||||
) : TextSource {
|
) : TextSource {
|
||||||
override val asMarkdownSource: String = sourceString.toMarkdown()
|
override val asMarkdownSource: String by lazy { source.regularMarkdown() }
|
||||||
override val asHtmlSource: String = sourceString.toHtml()
|
override val asMarkdownV2Source: String by lazy { source.regularMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { source.regularHtml() }
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
|
class StrikethroughTextSource(
|
||||||
|
source: String,
|
||||||
|
textParts: List<TextPart>
|
||||||
|
) : MultilevelTextSource {
|
||||||
|
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
|
||||||
|
override val asHtmlSource: String by lazy { strikethroughHTML() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() }
|
||||||
|
override val asMarkdownSource: String by lazy { source.strikethroughMarkdown() }
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown
|
|
||||||
|
|
||||||
class TextLinkTextSource(
|
class TextLinkTextSource(
|
||||||
sourceString: String,
|
source: String,
|
||||||
url: String
|
url: String
|
||||||
) : TextSource {
|
) : TextSource {
|
||||||
override val asMarkdownSource: String = sourceString.linkMarkdown(url)
|
override val asMarkdownSource: String by lazy { source.linkMarkdown(url) }
|
||||||
override val asHtmlSource: String = sourceString.linkHTML(url)
|
override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(url) }
|
||||||
|
override val asHtmlSource: String by lazy { source.linkHTML(url) }
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.mentionMarkdown
|
|
||||||
|
|
||||||
class TextMentionTextSource(
|
class TextMentionTextSource(
|
||||||
sourceString: String,
|
source: String,
|
||||||
privateChat: PrivateChat
|
privateChat: PrivateChat,
|
||||||
) : TextSource {
|
textParts: List<TextPart>
|
||||||
@Deprecated("Deprecated due to the fact that there is more common constructor")
|
) : MultilevelTextSource {
|
||||||
constructor(
|
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
|
||||||
sourceString: String,
|
override val asMarkdownSource: String by lazy { source.textMentionMarkdown(privateChat.id) }
|
||||||
user: User
|
override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(privateChat.id) }
|
||||||
) : this(sourceString, user as PrivateChat)
|
override val asHtmlSource: String by lazy { textMentionHTML(privateChat.id) }
|
||||||
|
|
||||||
override val asMarkdownSource: String = sourceString.mentionMarkdown(privateChat.id)
|
|
||||||
override val asHtmlSource: String = sourceString.mentionHTML(privateChat.id)
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkHTML
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.linkMarkdown
|
|
||||||
|
|
||||||
class URLTextSource(
|
class URLTextSource(
|
||||||
sourceString: String
|
source: String
|
||||||
) : TextSource{
|
) : TextSource {
|
||||||
override val asMarkdownSource: String = sourceString.linkMarkdown(sourceString)
|
override val asMarkdownSource: String by lazy { source.linkMarkdown(source) }
|
||||||
override val asHtmlSource: String = sourceString.linkHTML(sourceString)
|
override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(source) }
|
||||||
|
override val asHtmlSource: String by lazy { source.linkHTML(source) }
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
|
||||||
|
class UnderlineTextSource(
|
||||||
|
source: String,
|
||||||
|
textParts: List<TextPart>
|
||||||
|
) : MultilevelTextSource {
|
||||||
|
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
|
||||||
|
override val asMarkdownSource: String by lazy { source.underlineMarkdown() }
|
||||||
|
override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() }
|
||||||
|
override val asHtmlSource: String by lazy { underlineHTML() }
|
||||||
|
}
|
@ -16,6 +16,12 @@ object MarkdownParseMode : ParseMode() {
|
|||||||
override val parseModeName: String = "Markdown"
|
override val parseModeName: String = "Markdown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable(ParseModeSerializerObject::class)
|
||||||
|
object MarkdownV2ParseMode : ParseMode() {
|
||||||
|
@Serializable
|
||||||
|
@SerialName(parseModeField)
|
||||||
|
override val parseModeName: String = "MarkdownV2"
|
||||||
|
}
|
||||||
@Serializable(ParseModeSerializerObject::class)
|
@Serializable(ParseModeSerializerObject::class)
|
||||||
object HTMLParseMode : ParseMode() {
|
object HTMLParseMode : ParseMode() {
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -24,6 +30,7 @@ object HTMLParseMode : ParseMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typealias Markdown = MarkdownParseMode
|
typealias Markdown = MarkdownParseMode
|
||||||
|
typealias MarkdownV2 = MarkdownV2ParseMode
|
||||||
typealias HTML = HTMLParseMode
|
typealias HTML = HTMLParseMode
|
||||||
|
|
||||||
@Serializer(ParseMode::class)
|
@Serializer(ParseMode::class)
|
||||||
|
@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.StickerSetName
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
||||||
|
|
||||||
interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat {
|
interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat {
|
||||||
|
val slowModeDelay: Long?
|
||||||
val stickerSetName: StickerSetName?
|
val stickerSetName: StickerSetName?
|
||||||
val canSetStickerSet: Boolean
|
val canSetStickerSet: Boolean
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ data class ExtendedSupergroupChatImpl(
|
|||||||
override val pinnedMessage: Message? = null,
|
override val pinnedMessage: Message? = null,
|
||||||
@SerialName(stickerSetNameFullField)
|
@SerialName(stickerSetNameFullField)
|
||||||
override val stickerSetName: StickerSetName? = null,
|
override val stickerSetName: StickerSetName? = null,
|
||||||
|
@SerialName(slowModeDelayField)
|
||||||
|
override val slowModeDelay: Long? = null,
|
||||||
@SerialName(canSetStickerSetField)
|
@SerialName(canSetStickerSetField)
|
||||||
override val canSetStickerSet: Boolean = false
|
override val canSetStickerSet: Boolean = false
|
||||||
) : ExtendedSupergroupChat
|
) : ExtendedSupergroupChat
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -9,6 +11,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class AnimationFile(
|
data class AnimationFile(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
override val width: Int,
|
override val width: Int,
|
||||||
override val height: Int,
|
override val height: Int,
|
||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
|
@ -2,6 +2,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Performerable
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Performerable
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -10,6 +12,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class AudioFile(
|
data class AudioFile(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
override val performer: String? = null,
|
override val performer: String? = null,
|
||||||
override val title: String? = null,
|
override val title: String? = null,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -9,6 +11,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class DocumentFile(
|
data class DocumentFile(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null,
|
override val fileSize: Long? = null,
|
||||||
override val thumb: PhotoSize? = null,
|
override val thumb: PhotoSize? = null,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -9,6 +11,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class File(
|
data class File(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null
|
override val fileSize: Long? = null
|
||||||
): TelegramMediaFile
|
): TelegramMediaFile
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -10,6 +12,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class PathedFile(
|
data class PathedFile(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
@SerialName(filePathField)
|
@SerialName(filePathField)
|
||||||
val filePath: String,
|
val filePath: String,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.internal.ArrayListSerializer
|
import kotlinx.serialization.internal.ArrayListSerializer
|
||||||
@ -19,6 +21,8 @@ object PhotoSerializer : KSerializer<Photo> by ArrayListSerializer(
|
|||||||
data class PhotoSize(
|
data class PhotoSize(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null,
|
override val fileSize: Long? = null,
|
||||||
override val width: Int,
|
override val width: Int,
|
||||||
|
@ -11,6 +11,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class Sticker(
|
data class Sticker(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
@SerialName(widthField)
|
@SerialName(widthField)
|
||||||
override val width: Int,
|
override val width: Int,
|
||||||
@SerialName(heightField)
|
@SerialName(heightField)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -9,6 +11,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class VideoFile(
|
data class VideoFile(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
override val width: Int,
|
override val width: Int,
|
||||||
override val height: Int,
|
override val height: Int,
|
||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -9,6 +11,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class VideoNoteFile(
|
data class VideoNoteFile(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
@SerialName("length")
|
@SerialName("length")
|
||||||
override val width: Int,
|
override val width: Int,
|
||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -9,6 +11,8 @@ import kotlinx.serialization.Serializable
|
|||||||
data class VoiceFile(
|
data class VoiceFile(
|
||||||
@SerialName(fileIdField)
|
@SerialName(fileIdField)
|
||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
|
@SerialName(fileUniqueIdField)
|
||||||
|
override val fileUniqueId: FileUniqueId,
|
||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String? = null,
|
override val mimeType: String? = null,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
|
|
||||||
internal const val fileIdField = "file_id"
|
internal const val fileIdField = "file_id"
|
||||||
internal const val fileSizeField = "file_size"
|
internal const val fileSizeField = "file_size"
|
||||||
@ -11,5 +12,6 @@ internal const val filePathField = "file_path"
|
|||||||
*/
|
*/
|
||||||
interface TelegramMediaFile {
|
interface TelegramMediaFile {
|
||||||
val fileId: FileId
|
val fileId: FileId
|
||||||
|
val fileUniqueId: FileUniqueId
|
||||||
val fileSize: Long?
|
val fileSize: Long?
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.games
|
package com.github.insanusmokrassar.TelegramBotAPI.types.games
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Titled
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AnimationFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AnimationFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.Photo
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.Photo
|
||||||
|
|
||||||
@ -11,6 +9,6 @@ data class Game(
|
|||||||
val description: String,
|
val description: String,
|
||||||
val photo: Photo,
|
val photo: Photo,
|
||||||
override val caption: String? = null,
|
override val caption: String? = null,
|
||||||
override val captionEntities: List<MessageEntity> = emptyList(),
|
override val captionEntities: List<TextPart> = emptyList(),
|
||||||
val animation: AnimationFile? = null
|
val animation: AnimationFile? = null
|
||||||
) : Titled, CaptionedInput
|
) : Titled, CaptionedInput
|
||||||
|
@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.games
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.asTextParts
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ internal data class RawGame(
|
|||||||
description,
|
description,
|
||||||
photo,
|
photo,
|
||||||
caption,
|
caption,
|
||||||
caption ?.let { _ -> captionEntities.map { it.asMessageEntity(caption) } } ?: emptyList(),
|
caption ?.let { _ -> captionEntities.asTextParts(caption) } ?: emptyList(),
|
||||||
animation
|
animation
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.asTextParts
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
||||||
@ -85,13 +86,11 @@ internal data class RawMessage(
|
|||||||
) {
|
) {
|
||||||
private val content: MessageContent? by lazy {
|
private val content: MessageContent? by lazy {
|
||||||
val adaptedCaptionEntities = caption ?.let {
|
val adaptedCaptionEntities = caption ?.let {
|
||||||
caption_entities ?.map {
|
caption_entities ?.asTextParts(caption)
|
||||||
it.asMessageEntity(caption)
|
|
||||||
}
|
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
text != null -> TextContent(text, entities ?.map { it.asMessageEntity(text) } ?: emptyList())
|
text != null -> TextContent(text, entities ?.asTextParts(text) ?: emptyList())
|
||||||
audio != null -> AudioContent(
|
audio != null -> AudioContent(
|
||||||
audio,
|
audio,
|
||||||
caption,
|
caption,
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendMessage
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
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.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlTexts
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownTexts
|
|
||||||
|
|
||||||
data class TextContent(
|
data class TextContent(
|
||||||
val text: String,
|
val text: String,
|
||||||
val entities: List<MessageEntity> = emptyList()
|
val entities: List<TextPart> = emptyList()
|
||||||
) : MessageContent {
|
) : MessageContent {
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
@ -52,6 +51,7 @@ data class TextContent(
|
|||||||
parseMode: ParseMode = HTMLParseMode
|
parseMode: ParseMode = HTMLParseMode
|
||||||
): List<Request<Message>> = when (parseMode) {
|
): List<Request<Message>> = when (parseMode) {
|
||||||
is MarkdownParseMode -> toMarkdownTexts()
|
is MarkdownParseMode -> toMarkdownTexts()
|
||||||
|
is MarkdownV2ParseMode -> toMarkdownV2Texts()
|
||||||
is HTMLParseMode -> toHtmlTexts()
|
is HTMLParseMode -> toHtmlTexts()
|
||||||
}.map {
|
}.map {
|
||||||
SendMessage(
|
SendMessage(
|
||||||
@ -65,3 +65,5 @@ data class TextContent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun TextContent.fullEntitiesList() = text.fullListOfSubSource(entities).map { it.source }
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAnimation
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAnimation
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
@ -18,7 +18,7 @@ data class AnimationContent(
|
|||||||
override val media: AnimationFile,
|
override val media: AnimationFile,
|
||||||
val includedDocument: DocumentFile?,
|
val includedDocument: DocumentFile?,
|
||||||
override val caption: String?,
|
override val caption: String?,
|
||||||
override val captionEntities: List<MessageEntity>
|
override val captionEntities: List<TextPart>
|
||||||
) : MediaContent, CaptionedInput {
|
) : MediaContent, CaptionedInput {
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAudio
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAudio
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
@ -16,7 +16,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
|||||||
data class AudioContent(
|
data class AudioContent(
|
||||||
override val media: AudioFile,
|
override val media: AudioFile,
|
||||||
override val caption: String? = null,
|
override val caption: String? = null,
|
||||||
override val captionEntities: List<MessageEntity> = emptyList()
|
override val captionEntities: List<TextPart> = emptyList()
|
||||||
) : MediaContent, CaptionedInput {
|
) : MediaContent, CaptionedInput {
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendDocument
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendDocument
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
@ -16,7 +16,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
|||||||
data class DocumentContent(
|
data class DocumentContent(
|
||||||
override val media: DocumentFile,
|
override val media: DocumentFile,
|
||||||
override val caption: String? = null,
|
override val caption: String? = null,
|
||||||
override val captionEntities: List<MessageEntity> = emptyList()
|
override val captionEntities: List<TextPart> = emptyList()
|
||||||
) : MediaContent, CaptionedInput {
|
) : MediaContent, CaptionedInput {
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaPhoto
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaPhoto
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
@ -19,7 +19,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
|||||||
data class PhotoContent(
|
data class PhotoContent(
|
||||||
override val mediaCollection: List<PhotoSize>,
|
override val mediaCollection: List<PhotoSize>,
|
||||||
override val caption: String? = null,
|
override val caption: String? = null,
|
||||||
override val captionEntities: List<MessageEntity> = emptyList()
|
override val captionEntities: List<TextPart> = emptyList()
|
||||||
) : MediaCollectionContent<PhotoSize>, MediaGroupContent {
|
) : MediaCollectionContent<PhotoSize>, MediaGroupContent {
|
||||||
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
|
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaVideo
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaVideo
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
@ -17,7 +17,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
|||||||
data class VideoContent(
|
data class VideoContent(
|
||||||
override val media: VideoFile,
|
override val media: VideoFile,
|
||||||
override val caption: String? = null,
|
override val caption: String? = null,
|
||||||
override val captionEntities: List<MessageEntity> = emptyList()
|
override val captionEntities: List<TextPart> = emptyList()
|
||||||
) : MediaGroupContent {
|
) : MediaGroupContent {
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVoice
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVoice
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||||
@ -16,7 +16,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
|
|||||||
data class VoiceContent(
|
data class VoiceContent(
|
||||||
override val media: VoiceFile,
|
override val media: VoiceFile,
|
||||||
override val caption: String? = null,
|
override val caption: String? = null,
|
||||||
override val captionEntities: List<MessageEntity> = emptyList()
|
override val captionEntities: List<TextPart> = emptyList()
|
||||||
) : MediaContent, CaptionedInput {
|
) : MediaContent, CaptionedInput {
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
|
@ -0,0 +1,98 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
|
||||||
|
|
||||||
|
fun createFormattedText(
|
||||||
|
entities: List<TextSource>,
|
||||||
|
partLength: Int = 4096,
|
||||||
|
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: List<TextSource>,
|
||||||
|
partLength: Int = 4096
|
||||||
|
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
|
||||||
|
|
||||||
|
fun CaptionedInput.toMarkdownCaptions(): List<String> = createMarkdownText(
|
||||||
|
fullEntitiesList(),
|
||||||
|
captionLength.last + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
fun TextContent.toMarkdownTexts(): List<String> = createMarkdownText(
|
||||||
|
fullEntitiesList(),
|
||||||
|
textLength.last + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
fun createMarkdownV2Text(
|
||||||
|
entities: List<TextSource>,
|
||||||
|
partLength: Int = 4096
|
||||||
|
): List<String> = createFormattedText(entities, partLength, MarkdownV2ParseMode)
|
||||||
|
|
||||||
|
fun CaptionedInput.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
|
||||||
|
fullEntitiesList(),
|
||||||
|
captionLength.last + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
fun TextContent.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
|
||||||
|
fullEntitiesList(),
|
||||||
|
textLength.last + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
fun createHtmlText(
|
||||||
|
entities: List<TextSource>,
|
||||||
|
partLength: Int = 4096
|
||||||
|
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
|
||||||
|
|
||||||
|
fun CaptionedInput.toHtmlCaptions(): List<String> = createHtmlText(
|
||||||
|
fullEntitiesList(),
|
||||||
|
captionLength.last + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
fun TextContent.toHtmlTexts(): List<String> = createHtmlText(
|
||||||
|
fullEntitiesList(),
|
||||||
|
textLength.last + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RegularTextMessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
|
||||||
|
|
||||||
fun CaptionedInput.fullEntitiesList(): List<MessageEntity> = caption ?.let {
|
|
||||||
convertToFullMessageEntityList(it, captionEntities)
|
|
||||||
} ?: emptyList()
|
|
||||||
|
|
||||||
fun TextContent.fullEntitiesList(): List<MessageEntity> = convertToFullMessageEntityList(text, entities)
|
|
||||||
|
|
||||||
fun convertToFullMessageEntityList(
|
|
||||||
text: String,
|
|
||||||
messageEntities: List<MessageEntity>
|
|
||||||
): List<MessageEntity> {
|
|
||||||
val result = mutableListOf<MessageEntity>()
|
|
||||||
|
|
||||||
var offset = 0
|
|
||||||
for (entity in messageEntities) {
|
|
||||||
val newEntitySize = entity.offset - offset
|
|
||||||
if (newEntitySize > 0) {
|
|
||||||
val regularEntity = RegularTextMessageEntity(offset, newEntitySize, text.substring(offset, entity.offset))
|
|
||||||
result.add(regularEntity)
|
|
||||||
offset += regularEntity.length
|
|
||||||
}
|
|
||||||
result.add(entity)
|
|
||||||
offset += entity.length
|
|
||||||
}
|
|
||||||
val newEntitySize = text.length - offset
|
|
||||||
if (newEntitySize > 0) {
|
|
||||||
result.add(RegularTextMessageEntity(offset, newEntitySize, text.substring(offset, text.length)))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createFormattedText(
|
|
||||||
entities: List<TextSource>,
|
|
||||||
partLength: Int = 4096,
|
|
||||||
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 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
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
|
|
||||||
|
|
||||||
fun createHtmlText(
|
|
||||||
entities: List<TextSource>,
|
|
||||||
partLength: Int = 4096
|
|
||||||
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
|
|
||||||
|
|
||||||
fun CaptionedInput.toHtmlCaptions(): List<String> = createHtmlText(
|
|
||||||
fullEntitiesList(),
|
|
||||||
captionLength.endInclusive + 1
|
|
||||||
)
|
|
||||||
|
|
||||||
fun TextContent.toHtmlTexts(): List<String> = createHtmlText(
|
|
||||||
fullEntitiesList(),
|
|
||||||
textLength.endInclusive + 1
|
|
||||||
)
|
|
@ -1,24 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextSource
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
|
|
||||||
|
|
||||||
fun createMarkdownText(
|
|
||||||
entities: List<TextSource>,
|
|
||||||
partLength: Int = 4096
|
|
||||||
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
|
|
||||||
|
|
||||||
fun CaptionedInput.toMarkdownCaptions(): List<String> = createMarkdownText(
|
|
||||||
fullEntitiesList(),
|
|
||||||
captionLength.endInclusive + 1
|
|
||||||
)
|
|
||||||
|
|
||||||
fun TextContent.toMarkdownTexts(): List<String> = createMarkdownText(
|
|
||||||
fullEntitiesList(),
|
|
||||||
textLength.endInclusive + 1
|
|
||||||
)
|
|
@ -0,0 +1,139 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.RegularTextSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.link
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.escapeMarkdownV2Link
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml
|
||||||
|
|
||||||
|
internal fun String.fullListOfSubSource(sourceList: List<TextPart>): List<TextPart> {
|
||||||
|
val sortedSourceList = sourceList.sortedBy { it.range.first }.toMutableList()
|
||||||
|
|
||||||
|
var previousLastIndex = 0
|
||||||
|
|
||||||
|
val newSubSources = mutableListOf<TextPart>()
|
||||||
|
|
||||||
|
while (sortedSourceList.isNotEmpty()) {
|
||||||
|
val topSource = sortedSourceList.removeAt(0)
|
||||||
|
if (topSource.range.first - previousLastIndex > 0) {
|
||||||
|
val range = previousLastIndex until topSource.range.first
|
||||||
|
newSubSources.add(
|
||||||
|
TextPart(
|
||||||
|
range,
|
||||||
|
RegularTextSource(
|
||||||
|
substring(range)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
newSubSources.add(topSource)
|
||||||
|
previousLastIndex = topSource.range.last + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length > previousLastIndex) {
|
||||||
|
val range = previousLastIndex until length
|
||||||
|
newSubSources.add(
|
||||||
|
TextPart(
|
||||||
|
range,
|
||||||
|
RegularTextSource(
|
||||||
|
substring(range)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newSubSources
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun List<TextPart>.shiftSourcesToTheLeft(shiftCount: Int = 1): List<TextPart> {
|
||||||
|
return mapNotNull {
|
||||||
|
val first = (it.range.first - shiftCount).let { firstCalculated ->
|
||||||
|
if (firstCalculated < 0) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
firstCalculated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val last = (it.range.last - shiftCount).let { lastCalculated ->
|
||||||
|
if (lastCalculated < 0) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
lastCalculated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it.copy(range = first .. last).let { newSubSource ->
|
||||||
|
if (newSubSource.range.isEmpty()) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
newSubSource
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun List<TextPart>.joinSubSourcesMarkdownV2() = joinToString("") {
|
||||||
|
it.source.asMarkdownV2Source
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun List<TextPart>.joinSubSourcesHtml() = joinToString("") {
|
||||||
|
it.source.asHtmlSource
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.markdownV2Default(
|
||||||
|
openControlSymbol: String,
|
||||||
|
closeControlSymbol: String = openControlSymbol
|
||||||
|
) = "$openControlSymbol${textParts.joinSubSourcesMarkdownV2()}$closeControlSymbol"
|
||||||
|
internal fun MultilevelTextSource.htmlDefault(
|
||||||
|
openControlSymbol: String,
|
||||||
|
closeControlSymbol: String = openControlSymbol
|
||||||
|
) = "<$openControlSymbol>${textParts.joinSubSourcesHtml()}</$closeControlSymbol>"
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.linkMarkdownV2(
|
||||||
|
link: String
|
||||||
|
) = "[${textParts.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})"
|
||||||
|
internal fun MultilevelTextSource.linkHTML(
|
||||||
|
link: String
|
||||||
|
) = "<a href=\"${link.toHtml()}\">${textParts.joinSubSourcesHtml()}</a>"
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.emailMarkdownV2(address: String): String = linkMarkdownV2("mailto://$address")
|
||||||
|
internal fun MultilevelTextSource.emailHTML(address: String): String = linkHTML("mailto://$address}")
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl)
|
||||||
|
internal fun MultilevelTextSource.boldHTML(): String = htmlDefault(htmlBoldControl)
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl)
|
||||||
|
internal fun MultilevelTextSource.italicHTML(): String = htmlDefault(htmlItalicControl)
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl)
|
||||||
|
internal fun MultilevelTextSource.strikethroughHTML(): String = htmlDefault(htmlStrikethroughControl)
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl)
|
||||||
|
internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
||||||
|
internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.mentionMarkdownV2(): String = "@${textParts.joinSubSourcesMarkdownV2()}"
|
||||||
|
internal fun MultilevelTextSource.mentionHTML(): String = "@${textParts.joinSubSourcesHtml()}"
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.hashTagMarkdownV2(): String = "\\#${textParts.joinSubSourcesMarkdownV2()}"
|
||||||
|
internal fun MultilevelTextSource.hashTagHTML(): String = "#${textParts.joinSubSourcesHtml()}"
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.phoneMarkdownV2(): String = textParts.joinSubSourcesMarkdownV2()
|
||||||
|
internal fun MultilevelTextSource.phoneHTML(): String = textParts.joinSubSourcesHtml()
|
||||||
|
|
||||||
|
|
||||||
|
internal fun MultilevelTextSource.commandMarkdownV2(): String = "/${textParts.joinSubSourcesMarkdownV2()}"
|
||||||
|
internal fun MultilevelTextSource.commandHTML(): String = "/${textParts.joinSubSourcesHtml()}"
|
||||||
|
|
@ -2,138 +2,231 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toHtml
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
|
|
||||||
|
|
||||||
const val markdownBoldControl = "*"
|
const val markdownBoldControl = "*"
|
||||||
const val markdownItalicControl = "_"
|
const val markdownItalicControl = "_"
|
||||||
const val markdownCodeControl = "`"
|
const val markdownCodeControl = "`"
|
||||||
const val markdownPreControl = "```"
|
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 htmlBoldControl = "b"
|
||||||
const val htmlItalicControl = "i"
|
const val htmlItalicControl = "i"
|
||||||
const val htmlCodeControl = "code"
|
const val htmlCodeControl = "code"
|
||||||
const val htmlPreControl = "pre"
|
const val htmlPreControl = "pre"
|
||||||
|
const val htmlUnderlineControl = "u"
|
||||||
|
const val htmlStrikethroughControl = "s"
|
||||||
|
|
||||||
private infix fun String.markdownDefault(controlSymbol: String) = "$controlSymbol$this$controlSymbol"
|
private fun String.markdownDefault(
|
||||||
private infix fun String.htmlDefault(controlSymbol: String) = "<$controlSymbol>$this</$controlSymbol>"
|
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>"
|
||||||
|
|
||||||
infix fun String.linkMarkdown(link: String): String = "[$this]($link)"
|
fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})"
|
||||||
infix fun String.linkHTML(link: String): String = "<a href=\"$link\">$this</a>"
|
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.boldMarkdown(): String = markdownDefault(markdownBoldControl)
|
||||||
|
fun String.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl)
|
||||||
fun String.boldHTML(): String = htmlDefault(htmlBoldControl)
|
fun String.boldHTML(): String = htmlDefault(htmlBoldControl)
|
||||||
|
|
||||||
|
|
||||||
fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
||||||
fun String.italicHTML(): String =htmlDefault(htmlItalicControl)
|
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.codeMarkdown(): String = markdownDefault(markdownCodeControl)
|
||||||
|
fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode)
|
||||||
fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
||||||
|
|
||||||
|
|
||||||
fun String.preMarkdown(): String = markdownDefault(markdownPreControl)
|
fun String.preMarkdown(language: String? = null): String = markdownDefault(
|
||||||
fun String.preHTML(): String = htmlDefault(htmlPreControl)
|
"$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://$this")
|
fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}")
|
||||||
fun String.emailHTML(): String = linkHTML("mailto://$this")
|
fun String.emailMarkdownV2(): String = linkMarkdownV2("mailto://$${toMarkdown()}")
|
||||||
|
fun String.emailHTML(): String = linkHTML("mailto://$${toHtml()}")
|
||||||
|
|
||||||
|
|
||||||
private inline infix fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
private inline fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
||||||
this
|
adapt()
|
||||||
} else {
|
} else {
|
||||||
"@${adapt()}"
|
"@${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
|
adapt()
|
||||||
} else {
|
} else {
|
||||||
"#${adapt()}"
|
"#${adapt()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
infix fun String.mentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
||||||
infix fun String.mentionHTML(userId: UserId): String = linkHTML(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.mentionMarkdown(): String = mention(String::toMarkdown)
|
||||||
|
fun String.mentionMarkdownV2(): String = mention(String::escapeMarkdownV2Common)
|
||||||
fun String.mentionHTML(): String = mention(String::toHtml)
|
fun String.mentionHTML(): String = mention(String::toHtml)
|
||||||
|
|
||||||
|
|
||||||
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
||||||
|
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common)
|
||||||
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
||||||
|
|
||||||
|
|
||||||
fun String.phoneMarkdown(): String = toMarkdown()
|
fun String.phoneMarkdown(): String = toMarkdown()
|
||||||
|
fun String.phoneMarkdownV2(): String = escapeMarkdownV2Common()
|
||||||
fun String.phoneHTML(): String = toHtml()
|
fun String.phoneHTML(): String = toHtml()
|
||||||
|
|
||||||
|
|
||||||
fun String.command(): String = if (startsWith("/")) {
|
fun String.command(adapt: String.() -> String): String = if (startsWith("/")) {
|
||||||
this
|
adapt()
|
||||||
} else {
|
} else {
|
||||||
"/$this"
|
"/${adapt()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.commandMarkdown(): String = command()
|
fun String.commandMarkdown(): String = command(String::toMarkdown)
|
||||||
fun String.commandHTML(): String = command()
|
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()
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
|
is MarkdownV2 -> boldMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
infix fun String.pre(parseMode: ParseMode): String = when (parseMode) {
|
fun String.pre(parseMode: ParseMode, language: String? = null): String = when (parseMode) {
|
||||||
is HTML -> preHTML()
|
is HTML -> preHTML(language)
|
||||||
is Markdown -> preMarkdown()
|
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) {
|
infix fun String.email(parseMode: ParseMode): String = when (parseMode) {
|
||||||
is HTML -> emailHTML()
|
is HTML -> emailHTML()
|
||||||
is Markdown -> emailMarkdown()
|
is Markdown -> emailMarkdown()
|
||||||
|
is MarkdownV2 -> emailMarkdownV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
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.mentionHTML(second)
|
is HTML -> first.textMentionHTML(second)
|
||||||
is Markdown -> first.mentionMarkdown(second)
|
is Markdown -> first.textMentionMarkdown(second)
|
||||||
|
is MarkdownV2 -> first.textMentionMarkdownV2(second)
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,42 @@ fun String.toMarkdown(): String {
|
|||||||
).replace(
|
).replace(
|
||||||
"_",
|
"_",
|
||||||
"\\_"
|
"\\_"
|
||||||
|
).replace(
|
||||||
|
"`",
|
||||||
|
"\\`"
|
||||||
|
).replace(
|
||||||
|
"[",
|
||||||
|
"\\["
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val markdownV2LinkEscapes = mutableSetOf(')', '\\')
|
||||||
|
private val markdownV2PreAndCodeEscapes = mutableSetOf('`', '\\')
|
||||||
|
private val markdownV2CommonEscapes = mutableSetOf(
|
||||||
|
'_',
|
||||||
|
'*',
|
||||||
|
'[', ']',
|
||||||
|
'(', ')',
|
||||||
|
'~',
|
||||||
|
'`',
|
||||||
|
'>',
|
||||||
|
'#',
|
||||||
|
'+', '-', '=',
|
||||||
|
'|',
|
||||||
|
'{', '}',
|
||||||
|
'.', '!'
|
||||||
|
)
|
||||||
|
private fun String.escapeMarkdownV2(escapeCharacters: Iterable<Char>): String = map {
|
||||||
|
if (it in escapeCharacters) {
|
||||||
|
"\\$it"
|
||||||
|
} else {
|
||||||
|
"$it"
|
||||||
|
}
|
||||||
|
}.joinToString("")
|
||||||
|
fun String.escapeMarkdownV2Link() = escapeMarkdownV2(markdownV2LinkEscapes)
|
||||||
|
fun String.escapeMarkdownV2PreAndCode() = escapeMarkdownV2(markdownV2PreAndCodeEscapes)
|
||||||
|
fun String.escapeMarkdownV2Common() = escapeMarkdownV2(markdownV2CommonEscapes)
|
||||||
|
|
||||||
fun String.toHtml(): String = replace(
|
fun String.toHtml(): String = replace(
|
||||||
"<",
|
"<",
|
||||||
"<"
|
"<"
|
||||||
@ -19,7 +52,4 @@ fun String.toHtml(): String = replace(
|
|||||||
).replace(
|
).replace(
|
||||||
"&",
|
"&",
|
||||||
"&"
|
"&"
|
||||||
).replace(
|
|
||||||
"\"",
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,142 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownV2
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
class TextPartsCreatingTests {
|
||||||
|
@Test
|
||||||
|
fun testThatTextWithMultilevelPartsCorrectlyCreating() {
|
||||||
|
val text = "It is simple hello world"
|
||||||
|
val formattedV2Text = "It *_is_ ~__simple__~* hello world"
|
||||||
|
val entities = listOf(
|
||||||
|
RawMessageEntity(
|
||||||
|
"bold",
|
||||||
|
3,
|
||||||
|
9
|
||||||
|
),
|
||||||
|
RawMessageEntity(
|
||||||
|
"italic",
|
||||||
|
3,
|
||||||
|
2
|
||||||
|
),
|
||||||
|
RawMessageEntity(
|
||||||
|
"strikethrough",
|
||||||
|
6,
|
||||||
|
6
|
||||||
|
),
|
||||||
|
RawMessageEntity(
|
||||||
|
"underline",
|
||||||
|
6,
|
||||||
|
6
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val textParts = createTextPart(text, entities)
|
||||||
|
|
||||||
|
|
||||||
|
assertTrue (
|
||||||
|
textParts.first().source is BoldTextSource
|
||||||
|
)
|
||||||
|
|
||||||
|
val boldSource = textParts.first().source as BoldTextSource
|
||||||
|
assertTrue (
|
||||||
|
boldSource.textParts.first().source is ItalicTextSource
|
||||||
|
)
|
||||||
|
assertTrue (
|
||||||
|
boldSource.textParts[1].source is RegularTextSource
|
||||||
|
)
|
||||||
|
assertTrue (
|
||||||
|
boldSource.textParts[2].source is StrikethroughTextSource
|
||||||
|
)
|
||||||
|
assertTrue (
|
||||||
|
(boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
val fullTextParts = text.fullListOfSubSource(textParts)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
fullTextParts.first().source is RegularTextSource
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
fullTextParts[1].source is BoldTextSource
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
fullTextParts[2].source is RegularTextSource
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
formattedV2Text,
|
||||||
|
createMarkdownV2Text(fullTextParts.map { it.source }).first()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testThatTextWithMultilevelPartsCorrectlyCreatingInHtml() {
|
||||||
|
val text = "It is simple hello world"
|
||||||
|
val formattedHtmlText = "It <b><i>is</i> <s><u>simple</u></s></b> hello world"
|
||||||
|
val entities = listOf(
|
||||||
|
RawMessageEntity(
|
||||||
|
"bold",
|
||||||
|
3,
|
||||||
|
9
|
||||||
|
),
|
||||||
|
RawMessageEntity(
|
||||||
|
"italic",
|
||||||
|
3,
|
||||||
|
2
|
||||||
|
),
|
||||||
|
RawMessageEntity(
|
||||||
|
"strikethrough",
|
||||||
|
6,
|
||||||
|
6
|
||||||
|
),
|
||||||
|
RawMessageEntity(
|
||||||
|
"underline",
|
||||||
|
6,
|
||||||
|
6
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val textParts = createTextPart(text, entities)
|
||||||
|
|
||||||
|
|
||||||
|
assertTrue (
|
||||||
|
textParts.first().source is BoldTextSource
|
||||||
|
)
|
||||||
|
|
||||||
|
val boldSource = textParts.first().source as BoldTextSource
|
||||||
|
assertTrue (
|
||||||
|
boldSource.textParts.first().source is ItalicTextSource
|
||||||
|
)
|
||||||
|
assertTrue (
|
||||||
|
boldSource.textParts[1].source is RegularTextSource
|
||||||
|
)
|
||||||
|
assertTrue (
|
||||||
|
boldSource.textParts[2].source is StrikethroughTextSource
|
||||||
|
)
|
||||||
|
assertTrue (
|
||||||
|
(boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
val fullTextParts = text.fullListOfSubSource(textParts)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
fullTextParts.first().source is RegularTextSource
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
fullTextParts[1].source is BoldTextSource
|
||||||
|
)
|
||||||
|
assertTrue(
|
||||||
|
fullTextParts[2].source is RegularTextSource
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
formattedHtmlText,
|
||||||
|
createHtmlText(fullTextParts.map { it.source }).first()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class StringFormattingTests {
|
||||||
|
@Test
|
||||||
|
fun testThatPreEscapingWorksCorrectly() {
|
||||||
|
val originalHelloWorld = """
|
||||||
|
fun main() {
|
||||||
|
println("Hello world")
|
||||||
|
}
|
||||||
|
""".replace(" ", "")
|
||||||
|
val helloWorldLanguage = "kotlin"
|
||||||
|
assertEquals(
|
||||||
|
"<pre><code class=\"language-$helloWorldLanguage\">$originalHelloWorld</code></pre>",
|
||||||
|
originalHelloWorld.preHTML(
|
||||||
|
helloWorldLanguage
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"<pre>$originalHelloWorld</pre>",
|
||||||
|
originalHelloWorld.preHTML()
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"```$helloWorldLanguage\n$originalHelloWorld\n```",
|
||||||
|
originalHelloWorld.preMarkdown(
|
||||||
|
helloWorldLanguage
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"```\n$originalHelloWorld\n```",
|
||||||
|
originalHelloWorld.preMarkdown()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user