2020-10-04 11:06:30 +00:00
|
|
|
package dev.inmo.tgbotapi.types.message.content
|
2018-12-26 08:07:24 +00:00
|
|
|
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.CommonAbstracts.FullTextSourcesList
|
|
|
|
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
|
|
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
|
|
|
import dev.inmo.tgbotapi.requests.send.SendTextMessage
|
|
|
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
|
|
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
|
|
|
import dev.inmo.tgbotapi.types.ParseMode.*
|
|
|
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
|
|
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
|
|
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
|
|
|
import dev.inmo.tgbotapi.utils.*
|
2018-12-26 08:07:24 +00:00
|
|
|
|
|
|
|
data class TextContent(
|
|
|
|
val text: String,
|
2020-05-11 14:32:14 +00:00
|
|
|
/**
|
2020-10-04 11:06:30 +00:00
|
|
|
* Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
2020-05-11 14:32:14 +00:00
|
|
|
* @see [TextContent.fullEntitiesList]
|
|
|
|
*/
|
2020-01-05 13:24:17 +00:00
|
|
|
val entities: List<TextPart> = emptyList()
|
2019-01-17 02:40:37 +00:00
|
|
|
) : MessageContent {
|
|
|
|
override fun createResend(
|
|
|
|
chatId: ChatIdentifier,
|
|
|
|
disableNotification: Boolean,
|
|
|
|
replyToMessageId: MessageIdentifier?,
|
2020-11-05 17:48:23 +00:00
|
|
|
allowSendingWithoutReply: Boolean?,
|
2019-01-17 02:40:37 +00:00
|
|
|
replyMarkup: KeyboardMarkup?
|
2020-01-15 05:17:53 +00:00
|
|
|
): Request<ContentMessage<TextContent>> = SendTextMessage(
|
2019-01-17 02:40:37 +00:00
|
|
|
chatId,
|
2019-03-30 12:12:00 +00:00
|
|
|
toHtmlTexts().first(),
|
|
|
|
HTMLParseMode,
|
2019-01-17 02:40:37 +00:00
|
|
|
false,
|
|
|
|
disableNotification,
|
|
|
|
replyToMessageId,
|
2020-11-05 17:48:23 +00:00
|
|
|
allowSendingWithoutReply,
|
2019-01-17 02:40:37 +00:00
|
|
|
replyMarkup
|
|
|
|
)
|
2019-01-29 02:22:09 +00:00
|
|
|
|
|
|
|
override fun createResends(
|
|
|
|
chatId: ChatIdentifier,
|
|
|
|
disableNotification: Boolean,
|
|
|
|
replyToMessageId: MessageIdentifier?,
|
2020-11-05 17:48:23 +00:00
|
|
|
allowSendingWithoutReply: Boolean?,
|
2019-01-29 02:22:09 +00:00
|
|
|
replyMarkup: KeyboardMarkup?
|
2020-01-15 05:17:53 +00:00
|
|
|
): List<Request<ContentMessage<TextContent>>> = createResends(
|
2019-03-30 12:12:00 +00:00
|
|
|
chatId,
|
|
|
|
disableNotification,
|
|
|
|
replyToMessageId,
|
2020-11-05 17:48:23 +00:00
|
|
|
allowSendingWithoutReply,
|
2019-03-30 12:12:00 +00:00
|
|
|
replyMarkup,
|
|
|
|
HTMLParseMode
|
|
|
|
)
|
|
|
|
|
|
|
|
fun createResends(
|
|
|
|
chatId: ChatIdentifier,
|
|
|
|
disableNotification: Boolean,
|
|
|
|
replyToMessageId: MessageIdentifier?,
|
2020-11-05 17:48:23 +00:00
|
|
|
allowSendingWithoutReply: Boolean?,
|
2019-03-30 12:12:00 +00:00
|
|
|
replyMarkup: KeyboardMarkup?,
|
|
|
|
parseMode: ParseMode = HTMLParseMode
|
2020-01-15 05:17:53 +00:00
|
|
|
): List<Request<ContentMessage<TextContent>>> = when (parseMode) {
|
2019-03-30 12:12:00 +00:00
|
|
|
is MarkdownParseMode -> toMarkdownTexts()
|
2020-01-05 13:24:17 +00:00
|
|
|
is MarkdownV2ParseMode -> toMarkdownV2Texts()
|
2019-03-30 12:12:00 +00:00
|
|
|
is HTMLParseMode -> toHtmlTexts()
|
|
|
|
}.map {
|
2020-01-15 05:17:53 +00:00
|
|
|
SendTextMessage(
|
2019-01-29 02:22:09 +00:00
|
|
|
chatId,
|
|
|
|
it,
|
2019-03-30 12:12:00 +00:00
|
|
|
parseMode,
|
2019-01-29 02:22:09 +00:00
|
|
|
false,
|
|
|
|
disableNotification,
|
|
|
|
replyToMessageId,
|
2020-11-05 17:48:23 +00:00
|
|
|
allowSendingWithoutReply,
|
2019-01-29 02:22:09 +00:00
|
|
|
replyMarkup
|
|
|
|
)
|
|
|
|
}
|
2019-01-17 02:40:37 +00:00
|
|
|
}
|
2020-01-05 13:24:17 +00:00
|
|
|
|
2020-05-11 14:32:14 +00:00
|
|
|
/**
|
2020-10-04 11:06:30 +00:00
|
|
|
* Convert its [TextContent.entities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
|
|
|
|
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
2020-05-11 14:32:14 +00:00
|
|
|
*/
|
2020-04-25 03:57:59 +00:00
|
|
|
fun TextContent.fullEntitiesList(): FullTextSourcesList = text.fullListOfSubSource(entities).map { it.source }
|