mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-29 13:38:43 +00:00
fixes
This commit is contained in:
parent
e45f9cf46a
commit
00a75801a8
@ -13,8 +13,6 @@ import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
|||||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val ResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<*>>()
|
|
||||||
|
|
||||||
fun CopyMessage(
|
fun CopyMessage(
|
||||||
fromChatId: ChatIdentifier,
|
fromChatId: ChatIdentifier,
|
||||||
toChatId: ChatIdentifier,
|
toChatId: ChatIdentifier,
|
||||||
@ -60,8 +58,8 @@ data class CopyMessage internal constructor(
|
|||||||
override val allowSendingWithoutReply: Boolean? = null,
|
override val allowSendingWithoutReply: Boolean? = null,
|
||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: KeyboardMarkup? = null
|
override val replyMarkup: KeyboardMarkup? = null
|
||||||
): SimpleRequest<ContentMessage<*>>,
|
): SimpleRequest<MessageIdentifier>,
|
||||||
ReplyingMarkupSendMessageRequest<ContentMessage<*>>,
|
ReplyingMarkupSendMessageRequest<MessageIdentifier>,
|
||||||
MessageAction,
|
MessageAction,
|
||||||
TextedOutput {
|
TextedOutput {
|
||||||
override val chatId: ChatIdentifier
|
override val chatId: ChatIdentifier
|
||||||
@ -72,8 +70,8 @@ data class CopyMessage internal constructor(
|
|||||||
|
|
||||||
override fun method(): String = "copyMessage"
|
override fun method(): String = "copyMessage"
|
||||||
|
|
||||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<*>>
|
override val resultDeserializer: DeserializationStrategy<MessageIdentifier>
|
||||||
get() = ResultDeserializer
|
get() = MessageIdSerializer
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
@ -84,22 +84,23 @@ internal fun createTextPart(from: String, entities: RawMessageEntities): List<Te
|
|||||||
|
|
||||||
internal fun List<TextPart>.asRawMessageEntities(): List<RawMessageEntity> = mapNotNull {
|
internal fun List<TextPart>.asRawMessageEntities(): List<RawMessageEntity> = mapNotNull {
|
||||||
val source = it.source
|
val source = it.source
|
||||||
|
val length = it.range.last - it.range.first + 1
|
||||||
when (source) {
|
when (source) {
|
||||||
is MentionTextSource -> RawMessageEntity("mention", it.range.first, it.range.last - it.range.first)
|
is MentionTextSource -> RawMessageEntity("mention", it.range.first, length)
|
||||||
is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, it.range.last - it.range.first)
|
is HashTagTextSource -> RawMessageEntity("hashtag", it.range.first, length)
|
||||||
is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, it.range.last - it.range.first)
|
is CashTagTextSource -> RawMessageEntity("cashtag", it.range.first, length)
|
||||||
is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, it.range.last - it.range.first)
|
is BotCommandTextSource -> RawMessageEntity("bot_command", it.range.first, length)
|
||||||
is URLTextSource -> RawMessageEntity("url", it.range.first, it.range.last - it.range.first)
|
is URLTextSource -> RawMessageEntity("url", it.range.first, length)
|
||||||
is EMailTextSource -> RawMessageEntity("email", it.range.first, it.range.last - it.range.first)
|
is EMailTextSource -> RawMessageEntity("email", it.range.first, length)
|
||||||
is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, it.range.last - it.range.first)
|
is PhoneNumberTextSource -> RawMessageEntity("phone_number", it.range.first, length)
|
||||||
is BoldTextSource -> RawMessageEntity("bold", it.range.first, it.range.last - it.range.first)
|
is BoldTextSource -> RawMessageEntity("bold", it.range.first, length)
|
||||||
is ItalicTextSource -> RawMessageEntity("italic", it.range.first, it.range.last - it.range.first)
|
is ItalicTextSource -> RawMessageEntity("italic", it.range.first, length)
|
||||||
is CodeTextSource -> RawMessageEntity("code", it.range.first, it.range.last - it.range.first)
|
is CodeTextSource -> RawMessageEntity("code", it.range.first, length)
|
||||||
is PreTextSource -> RawMessageEntity("pre", it.range.first, it.range.last - it.range.first, language = source.language)
|
is PreTextSource -> RawMessageEntity("pre", it.range.first, length, language = source.language)
|
||||||
is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, it.range.last - it.range.first, source.url)
|
is TextLinkTextSource -> RawMessageEntity("text_link", it.range.first, length, source.url)
|
||||||
is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, it.range.last - it.range.first, user = source.user)
|
is TextMentionTextSource -> RawMessageEntity("text_mention", it.range.first, length, user = source.user)
|
||||||
is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, it.range.last - it.range.first)
|
is UnderlineTextSource -> RawMessageEntity("underline", it.range.first, length)
|
||||||
is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, it.range.last - it.range.first)
|
is StrikethroughTextSource -> RawMessageEntity("strikethrough", it.range.first, length)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +109,7 @@ internal fun List<TextSource>.toRawMessageEntities(): List<RawMessageEntity> {
|
|||||||
var i = 0
|
var i = 0
|
||||||
return map {
|
return map {
|
||||||
TextPart(
|
TextPart(
|
||||||
i until it.source.length,
|
i until (i + it.source.length),
|
||||||
it
|
it
|
||||||
).also {
|
).also {
|
||||||
i = it.range.last + 1
|
i = it.range.last + 1
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package dev.inmo.tgbotapi.types
|
||||||
|
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
import kotlinx.serialization.json.*
|
||||||
|
|
||||||
|
object MessageIdSerializer : KSerializer<MessageIdentifier> {
|
||||||
|
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): MessageIdentifier = JsonObject.serializer().deserialize(decoder)[messageIdField]!!.jsonPrimitive.long
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: MessageIdentifier) {
|
||||||
|
JsonObject.serializer().serialize(
|
||||||
|
encoder,
|
||||||
|
JsonObject(
|
||||||
|
mapOf(
|
||||||
|
messageIdField to JsonPrimitive(value)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ import dev.inmo.tgbotapi.types.payments.Invoice
|
|||||||
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||||
import dev.inmo.tgbotapi.types.polls.Poll
|
import dev.inmo.tgbotapi.types.polls.Poll
|
||||||
import dev.inmo.tgbotapi.types.venue.Venue
|
import dev.inmo.tgbotapi.types.venue.Venue
|
||||||
|
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
@ -91,11 +92,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 ?.asTextParts(caption)
|
it.fullListOfSubSource(caption_entities ?.asTextParts(caption) ?: emptyList())
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
when {
|
when {
|
||||||
text != null -> TextContent(text, entities ?.asTextParts(text) ?: emptyList())
|
text != null -> TextContent(text, text.fullListOfSubSource(entities ?.asTextParts(text) ?: emptyList()))
|
||||||
audio != null -> AudioContent(
|
audio != null -> AudioContent(
|
||||||
audio,
|
audio,
|
||||||
caption,
|
caption,
|
||||||
|
Loading…
Reference in New Issue
Block a user