1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

a lot of types has been converted to sealed

This commit is contained in:
InsanusMokrassar 2021-05-29 14:23:25 +06:00
parent 12184cd2be
commit 7825ec3010
116 changed files with 531 additions and 468 deletions

View File

@ -11,6 +11,8 @@
* `Klock`: `2.0.7` -> `2.1.2` * `Klock`: `2.0.7` -> `2.1.2`
* `UUID`: `0.2.3` -> `0.3.0` * `UUID`: `0.2.3` -> `0.3.0`
* `Ktor`: `1.5.4` -> `1.6.0` * `Ktor`: `1.5.4` -> `1.6.0`
* `Core`:
* `ForceReply` has been renamed to `ReplyForce`
## 0.34.1 ## 0.34.1

View File

@ -1,110 +1,79 @@
package dev.inmo.tgbotapi.CommonAbstracts package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourceSerializer import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.regular import dev.inmo.tgbotapi.types.MessageEntity.textsources.MultilevelTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.captionLength import dev.inmo.tgbotapi.types.captionLength
import dev.inmo.tgbotapi.types.textLength import dev.inmo.tgbotapi.types.textLength
import kotlinx.serialization.Serializable import dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForCaption
import dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForMessage
import dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForText
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods" const val DirectInvocationOfTextSourceConstructor =
"It is strongly not recommended to use constructors directly instead of factory methods"
typealias TextSourcesList = List<TextSource> @Deprecated(
"Replaced",
@Serializable(TextSourceSerializer::class) ReplaceWith("TextSourcesList", "dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList")
interface TextSource {
val markdown: String
val markdownV2: String
val html: String
val source: String
val asText: String
get() = source
companion object {
fun serializer() = TextSourceSerializer
}
}
@Suppress("NOTHING_TO_INLINE")
inline operator fun TextSource.plus(other: TextSource) = listOf(this, other)
@Suppress("NOTHING_TO_INLINE")
inline operator fun TextSource.plus(other: List<TextSource>) = listOf(this) + other
@Suppress("NOTHING_TO_INLINE")
inline operator fun TextSource.plus(text: String) = listOf(this, regular(text))
@Suppress("NOTHING_TO_INLINE")
inline operator fun List<TextSource>.plus(text: String) = this + regular(text)
@Serializable(TextSourceSerializer::class)
interface MultilevelTextSource : TextSource {
val subsources: List<TextSource>
companion object {
fun serializer() = TextSourceSerializer
}
}
@Deprecated("This class will be removed soon. Use TextSources instead")
data class TextPart(
val range: IntRange,
val source: TextSource
) )
typealias TextSourcesList = TextSourcesList
@Deprecated("This method is no longer required to work with TextSources") @Deprecated("Replaced", ReplaceWith("TextSource", "dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource"))
fun List<TextPart>.justTextSources() = map { it.source } typealias TextSource = dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
internal fun List<TextSource>.toTextParts(preOffset: Int = 0): List<TextPart> {
var i = preOffset
return map {
TextPart(
i until (i + it.source.length),
it
).also {
i = it.range.last + 1
}
}
}
fun List<TextSource>.makeString() = joinToString("") { it.source } @Suppress("NOTHING_TO_INLINE")
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> { @Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
if (isEmpty()) { inline operator fun dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource.plus(other: dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource) =
return emptyList() listOf(this, other)
}
val resultList = mutableListOf<MutableList<TextSource>>(mutableListOf()) @Suppress("NOTHING_TO_INLINE")
var currentPartLength = 0 @Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
val maxSize = limit.last + 1 inline operator fun dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource.plus(other: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>) =
listOf(this) + other
for (current in this) { @Suppress("NOTHING_TO_INLINE")
if (current.source.length > maxSize) { @Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
error("Currently unsupported parts with size more than target one-message parts (${current.source.length} > ${maxSize})") inline operator fun dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource.plus(text: String) =
} listOf(this, regular(text))
if (currentPartLength + current.source.length > maxSize) { @Suppress("NOTHING_TO_INLINE")
if (numberOfParts == null || numberOfParts < resultList.size) { @Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
resultList.add(mutableListOf()) inline operator fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.plus(text: String) = this + regular(text)
currentPartLength = 0
} else {
break
}
}
resultList.last().add(current) @Deprecated(
currentPartLength += current.source.length "Replaced",
} ReplaceWith("MultilevelTextSource", "dev.inmo.tgbotapi.types.MessageEntity.textsources.MultilevelTextSource")
)
typealias MultilevelTextSource = MultilevelTextSource
return resultList @Deprecated("Replaced", ReplaceWith("makeString", "dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString"))
} fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.makeString() = makeString()
@Deprecated(
"Replaced",
ReplaceWith("separateForMessage", "dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForMessage")
)
fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null) =
separateForMessage(limit, numberOfParts)
/** /**
* This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with * This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with
* [captionLength] and all others with * [captionLength] and all others with
*/ */
fun List<TextSource>.separateForCaption(): List<List<TextSource>> { @Deprecated(
val captionPart = separateForMessage(captionLength, 1).first() "Replaced",
return listOf(captionPart) + minus(captionPart).separateForMessage(textLength) ReplaceWith("separateForCaption", "dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForCaption")
} )
fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.separateForCaption() = separateForCaption()
/** /**
* This method will prepare [TextSource]s list for messages with [textLength] * This method will prepare [TextSource]s list for messages with [textLength]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun List<TextSource>.separateForText(): List<List<TextSource>> = separateForMessage(textLength) @Deprecated(
"Replaced",
ReplaceWith("separateForText", "dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForText")
)
inline fun List<TextSource>.separateForText() = separateForText()

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.CommonAbstracts package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
interface Texted { interface Texted {
@ -9,7 +10,7 @@ interface TextedWithTextSources : Texted {
/** /**
* Full list of [TextSource] built from source[TextedInput.textEntities] * Full list of [TextSource] built from source[TextedInput.textEntities]
*/ */
val textSources: List<TextSource>? val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>?
} }
interface ParsableOutput : Texted { interface ParsableOutput : Texted {
@ -17,7 +18,7 @@ interface ParsableOutput : Texted {
} }
interface EntitiesOutput : TextedWithTextSources { interface EntitiesOutput : TextedWithTextSources {
val entities: List<TextSource>? val entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>?
get() = textSources get() = textSources
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.edit.caption package dev.inmo.tgbotapi.requests.edit.caption
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.*
import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer
@ -33,7 +32,7 @@ fun EditChatMessageCaption(
fun EditChatMessageCaption( fun EditChatMessageCaption(
chatId: ChatIdentifier, chatId: ChatIdentifier,
messageId: MessageIdentifier, messageId: MessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = EditChatMessageCaption( ) = EditChatMessageCaption(
chatId, chatId,
@ -59,7 +58,7 @@ data class EditChatMessageCaption internal constructor(
@SerialName(replyMarkupField) @SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage<MediaContent>, EditTextChatMessage, EditReplyMessage { ) : EditChatMessage<MediaContent>, EditTextChatMessage, EditReplyMessage {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text) rawEntities ?.asTextSources(text)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.edit.caption package dev.inmo.tgbotapi.requests.edit.caption
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.*
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -25,7 +24,7 @@ fun EditInlineMessageCaption(
fun EditInlineMessageCaption( fun EditInlineMessageCaption(
inlineMessageId: InlineMessageIdentifier, inlineMessageId: InlineMessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = EditInlineMessageCaption( ) = EditInlineMessageCaption(
inlineMessageId, inlineMessageId,
@ -48,7 +47,7 @@ data class EditInlineMessageCaption internal constructor(
@SerialName(replyMarkupField) @SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage { ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text) rawEntities ?.asTextSources(text)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.edit.text package dev.inmo.tgbotapi.requests.edit.text
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.*
import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer
@ -35,7 +34,7 @@ fun EditChatMessageText(
fun EditChatMessageText( fun EditChatMessageText(
chatId: ChatIdentifier, chatId: ChatIdentifier,
messageId: MessageIdentifier, messageId: MessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
disableWebPagePreview: Boolean? = null, disableWebPagePreview: Boolean? = null,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = EditChatMessageText( ) = EditChatMessageText(
@ -65,7 +64,7 @@ data class EditChatMessageText internal constructor(
@SerialName(replyMarkupField) @SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { ) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text) rawEntities ?.asTextSources(text)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.edit.text package dev.inmo.tgbotapi.requests.edit.text
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.edit.abstracts.* import dev.inmo.tgbotapi.requests.edit.abstracts.*
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -27,7 +26,7 @@ fun EditInlineMessageText(
fun EditInlineMessageText( fun EditInlineMessageText(
inlineMessageId: InlineMessageIdentifier, inlineMessageId: InlineMessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
disableWebPagePreview: Boolean? = null, disableWebPagePreview: Boolean? = null,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = EditInlineMessageText( ) = EditInlineMessageText(
@ -54,7 +53,7 @@ data class EditInlineMessageText internal constructor(
@SerialName(replyMarkupField) @SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage { ) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text) rawEntities ?.asTextSources(text)
} }

View File

@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -27,7 +28,7 @@ fun CopyMessage(
fromChatId: ChatIdentifier, fromChatId: ChatIdentifier,
toChatId: ChatIdentifier, toChatId: ChatIdentifier,
messageId: MessageIdentifier, messageId: MessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.send package dev.inmo.tgbotapi.requests.send
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview
import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.*
@ -41,7 +40,7 @@ fun SendTextMessage(
fun SendTextMessage( fun SendTextMessage(
chatId: ChatIdentifier, chatId: ChatIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
disableWebPagePreview: Boolean? = null, disableWebPagePreview: Boolean? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
@ -84,7 +83,7 @@ data class SendTextMessage internal constructor(
TextableSendMessageRequest<ContentMessage<TextContent>>, TextableSendMessageRequest<ContentMessage<TextContent>>,
DisableWebPagePreview DisableWebPagePreview
{ {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text) rawEntities ?.asTextSources(text)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.send.media package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.*
@ -66,7 +65,7 @@ fun SendAnimation(
chatId: ChatIdentifier, chatId: ChatIdentifier,
animation: InputFile, animation: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@ -145,7 +144,7 @@ data class SendAnimationData internal constructor(
DuratedSendMessageRequest<ContentMessage<AnimationContent>>, DuratedSendMessageRequest<ContentMessage<AnimationContent>>,
SizedSendMessageRequest<ContentMessage<AnimationContent>> SizedSendMessageRequest<ContentMessage<AnimationContent>>
{ {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.requests.send.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.* import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -65,7 +66,7 @@ fun SendAudio(
chatId: ChatIdentifier, chatId: ChatIdentifier,
audio: InputFile, audio: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
duration: Long? = null, duration: Long? = null,
performer: String? = null, performer: String? = null,
title: String? = null, title: String? = null,

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.send.media package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.*
@ -80,7 +79,7 @@ fun SendDocument(
chatId: ChatIdentifier, chatId: ChatIdentifier,
document: InputFile, document: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
@ -158,7 +157,7 @@ data class SendDocumentData internal constructor(
TextableSendMessageRequest<ContentMessage<DocumentContent>>, TextableSendMessageRequest<ContentMessage<DocumentContent>>,
ThumbedSendMessageRequest<ContentMessage<DocumentContent>> ThumbedSendMessageRequest<ContentMessage<DocumentContent>>
{ {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.send.media package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.*
@ -48,7 +47,7 @@ fun SendPhoto(
fun SendPhoto( fun SendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photo: InputFile, photo: InputFile,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
@ -101,7 +100,7 @@ data class SendPhotoData internal constructor(
ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>, ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>,
TextableSendMessageRequest<ContentMessage<PhotoContent>> TextableSendMessageRequest<ContentMessage<PhotoContent>>
{ {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.send.media package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.*
@ -68,7 +67,7 @@ fun SendVideo(
chatId: ChatIdentifier, chatId: ChatIdentifier,
video: InputFile, video: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
@ -151,7 +150,7 @@ data class SendVideoData internal constructor(
DuratedSendMessageRequest<ContentMessage<VideoContent>>, DuratedSendMessageRequest<ContentMessage<VideoContent>>,
SizedSendMessageRequest<ContentMessage<VideoContent>> SizedSendMessageRequest<ContentMessage<VideoContent>>
{ {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.requests.send.media package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.*
@ -57,7 +56,7 @@ fun SendVoice(
fun SendVoice( fun SendVoice(
chatId: ChatIdentifier, chatId: ChatIdentifier,
voice: InputFile, voice: InputFile,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
duration: Long? = null, duration: Long? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
@ -121,7 +120,7 @@ data class SendVoiceData internal constructor(
TextableSendMessageRequest<ContentMessage<VoiceContent>>, TextableSendMessageRequest<ContentMessage<VoiceContent>>,
DuratedSendMessageRequest<ContentMessage<VoiceContent>> DuratedSendMessageRequest<ContentMessage<VoiceContent>>
{ {
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageReques
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
@ -267,7 +268,7 @@ fun SendQuizPoll(
correctOptionId: Int, correctOptionId: Int,
isAnonymous: Boolean = true, isAnonymous: Boolean = true,
isClosed: Boolean = false, isClosed: Boolean = false,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
closeInfo: ScheduledCloseInfo? = null, closeInfo: ScheduledCloseInfo? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,

View File

@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.types.CallbackQueryIdentifier import dev.inmo.tgbotapi.types.CallbackQueryIdentifier
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
interface CallbackQuery { sealed interface CallbackQuery {
val id: CallbackQueryIdentifier val id: CallbackQueryIdentifier
val user: User val user: User
val chatInstance: String val chatInstance: String

View File

@ -1,5 +1,5 @@
package dev.inmo.tgbotapi.types.CallbackQuery package dev.inmo.tgbotapi.types.CallbackQuery
interface DataCallbackQuery : CallbackQuery { sealed interface DataCallbackQuery : CallbackQuery {
val data: String val data: String
} }

View File

@ -1,5 +1,5 @@
package dev.inmo.tgbotapi.types.CallbackQuery package dev.inmo.tgbotapi.types.CallbackQuery
interface GameShortNameCallbackQuery : CallbackQuery { sealed interface GameShortNameCallbackQuery : CallbackQuery {
val gameShortName: String val gameShortName: String
} }

View File

@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.types.InlineMessageIdentifier import dev.inmo.tgbotapi.types.InlineMessageIdentifier
interface InlineMessageIdCallbackQuery : CallbackQuery { sealed interface InlineMessageIdCallbackQuery : CallbackQuery {
val inlineMessageId: InlineMessageIdentifier val inlineMessageId: InlineMessageIdentifier
} }

View File

@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.Message
interface MessageCallbackQuery : CallbackQuery { sealed interface MessageCallbackQuery : CallbackQuery {
val message: Message val message: Message
} }

View File

@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
import kotlinx.serialization.*
@Serializable
data class LeftChatMember(@SerialName(userField) override val user: User) : ChatMember {
@SerialName(statusField)
@Required
private val type: String = "left"
}

View File

@ -0,0 +1,16 @@
package dev.inmo.tgbotapi.types.ChatMember
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
import dev.inmo.tgbotapi.types.ChatMember.abstracts.LeftChatMember
import kotlinx.serialization.*
@Serializable
data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember {
@SerialName(statusField)
@Required
private val type: String = "left"
}
@Deprecated("Renamed", ReplaceWith("LeftChatMemberImpl", "dev.inmo.tgbotapi.types.ChatMember.LeftChatMemberImpl"))
typealias LeftChatMember = LeftChatMemberImpl

View File

@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.types.ChatMember
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
import kotlinx.serialization.*
@Serializable
data class MemberChatMember(@SerialName(userField) override val user: User) : ChatMember {
@SerialName(statusField)
@Required
private val type: String = "member"
}

View File

@ -0,0 +1,16 @@
package dev.inmo.tgbotapi.types.ChatMember
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
import dev.inmo.tgbotapi.types.ChatMember.abstracts.MemberChatMember
import kotlinx.serialization.*
@Serializable
data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember {
@SerialName(statusField)
@Required
private val type: String = "member"
}
@Deprecated("Renamed", ReplaceWith("MemberChatMember", "dev.inmo.tgbotapi.types.ChatMember.MemberChatMemberImpl"))
typealias MemberChatMember = MemberChatMemberImpl

View File

@ -13,7 +13,7 @@ import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
@Serializable(ChatMemberSerializer::class) @Serializable(ChatMemberSerializer::class)
interface ChatMember { sealed interface ChatMember {
val user: User val user: User
} }

View File

@ -0,0 +1,3 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
interface LeftChatMember : ChatMember

View File

@ -0,0 +1,3 @@
package dev.inmo.tgbotapi.types.ChatMember.abstracts
interface MemberChatMember : ChatMember

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -26,7 +25,7 @@ fun InlineQueryResultAudioCachedImpl(
fun InlineQueryResultAudioCachedImpl( fun InlineQueryResultAudioCachedImpl(
id: InlineQueryIdentifier, id: InlineQueryIdentifier,
fileId: FileId, fileId: FileId,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultAudioCachedImpl(id, fileId, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultAudioCachedImpl(id, fileId, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -49,7 +48,7 @@ data class InlineQueryResultAudioCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultAudioCached { ) : InlineQueryResultAudioCached {
override val type: String = inlineQueryResultAudioType override val type: String = inlineQueryResultAudioType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudio import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudio
@ -31,7 +30,7 @@ fun InlineQueryResultAudioImpl(
title: String, title: String,
performer: String? = null, performer: String? = null,
duration: Int? = null, duration: Int? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultAudioImpl(id, url, title, performer, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultAudioImpl(id, url, title, performer, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -60,7 +59,7 @@ data class InlineQueryResultAudioImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultAudio { ) : InlineQueryResultAudio {
override val type: String = inlineQueryResultAudioType override val type: String = inlineQueryResultAudioType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -30,7 +29,7 @@ fun InlineQueryResultDocumentCachedImpl(
fileId: FileId, fileId: FileId,
title: String, title: String,
description: String? = null, description: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultDocumentCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -57,7 +56,7 @@ data class InlineQueryResultDocumentCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultDocumentCached { ) : InlineQueryResultDocumentCached {
override val type: String = inlineQueryResultDocumentType override val type: String = inlineQueryResultDocumentType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocument import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocument
@ -39,7 +38,7 @@ fun InlineQueryResultDocumentImpl(
thumbWidth: Int? = null, thumbWidth: Int? = null,
thumbHeight: Int? = null, thumbHeight: Int? = null,
description: String? = null, description: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultDocumentImpl(id, url, title, mimeType, thumbUrl, thumbWidth, thumbHeight, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -74,7 +73,7 @@ data class InlineQueryResultDocumentImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultDocument { ) : InlineQueryResultDocument {
override val type: String = inlineQueryResultDocumentType override val type: String = inlineQueryResultDocumentType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -28,7 +27,7 @@ fun InlineQueryResultGifCachedImpl(
id: InlineQueryIdentifier, id: InlineQueryIdentifier,
fileId: FileId, fileId: FileId,
title: String? = null, title: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultGifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultGifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -53,7 +52,7 @@ data class InlineQueryResultGifCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultGifCached { ) : InlineQueryResultGifCached {
override val type: String = inlineQueryResultGifType override val type: String = inlineQueryResultGifType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGif import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGif
@ -38,7 +37,7 @@ fun InlineQueryResultGifImpl(
height: Int? = null, height: Int? = null,
duration: Int? = null, duration: Int? = null,
title: String? = null, title: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultGifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultGifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -73,7 +72,7 @@ data class InlineQueryResultGifImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultGif { ) : InlineQueryResultGif {
override val type: String = inlineQueryResultGifType override val type: String = inlineQueryResultGifType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -28,7 +27,7 @@ fun InlineQueryResultMpeg4GifCachedImpl(
id: InlineQueryIdentifier, id: InlineQueryIdentifier,
fileId: FileId, fileId: FileId,
title: String? = null, title: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultMpeg4GifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultMpeg4GifCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -53,7 +52,7 @@ data class InlineQueryResultMpeg4GifCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultMpeg4GifCached { ) : InlineQueryResultMpeg4GifCached {
override val type: String = inlineQueryResultMpeg4GifType override val type: String = inlineQueryResultMpeg4GifType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4Gif import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4Gif
@ -38,7 +37,7 @@ fun InlineQueryResultMpeg4GifImpl(
height: Int? = null, height: Int? = null,
duration: Int? = null, duration: Int? = null,
title: String? = null, title: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultMpeg4GifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultMpeg4GifImpl(id, url, thumbUrl, thumbMimeType, width, height, duration, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -73,7 +72,7 @@ data class InlineQueryResultMpeg4GifImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultMpeg4Gif { ) : InlineQueryResultMpeg4Gif {
override val type: String = inlineQueryResultMpeg4GifType override val type: String = inlineQueryResultMpeg4GifType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -30,7 +29,7 @@ fun InlineQueryResultPhotoCachedImpl(
fileId: FileId, fileId: FileId,
title: String? = null, title: String? = null,
description: String? = null, description: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultPhotoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultPhotoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -57,7 +56,7 @@ data class InlineQueryResultPhotoCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultPhotoCached { ) : InlineQueryResultPhotoCached {
override val type: String = inlineQueryResultPhotoType override val type: String = inlineQueryResultPhotoType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhoto import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhoto
@ -35,7 +34,7 @@ fun InlineQueryResultPhotoImpl(
height: Int? = null, height: Int? = null,
title: String? = null, title: String? = null,
description: String? = null, description: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultPhotoImpl(id, url, thumbUrl, width, height, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultPhotoImpl(id, url, thumbUrl, width, height, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -68,7 +67,7 @@ data class InlineQueryResultPhotoImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultPhoto { ) : InlineQueryResultPhoto {
override val type: String = inlineQueryResultPhotoType override val type: String = inlineQueryResultPhotoType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -30,7 +29,7 @@ fun InlineQueryResultVideoCachedImpl(
fileId: FileId, fileId: FileId,
title: String, title: String,
description: String? = null, description: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -57,7 +56,7 @@ data class InlineQueryResultVideoCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVideoCached { ) : InlineQueryResultVideoCached {
override val type: String = inlineQueryResultVideoType override val type: String = inlineQueryResultVideoType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideo import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideo
@ -41,7 +40,7 @@ fun InlineQueryResultVideoImpl(
height: Int? = null, height: Int? = null,
duration: Int? = null, duration: Int? = null,
description: String? = null, description: String? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -78,7 +77,7 @@ data class InlineQueryResultVideoImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVideo { ) : InlineQueryResultVideo {
override val type: String = inlineQueryResultVideoType override val type: String = inlineQueryResultVideoType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
@ -28,7 +27,7 @@ fun InlineQueryResultVoiceCachedImpl(
id: InlineQueryIdentifier, id: InlineQueryIdentifier,
fileId: FileId, fileId: FileId,
title: String, title: String,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVoiceCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultVoiceCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -53,7 +52,7 @@ data class InlineQueryResultVoiceCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVoiceCached { ) : InlineQueryResultVoiceCached {
override val type: String = inlineQueryResultVoiceType override val type: String = inlineQueryResultVoiceType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoice import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoice
@ -39,7 +38,7 @@ fun InlineQueryResultVoiceImpl(
url: String, url: String,
title: String, title: String,
duration: Int? = null, duration: Int? = null,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null, replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVoiceImpl(id, url, title, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent) ) = InlineQueryResultVoiceImpl(id, url, title, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@ -66,7 +65,7 @@ data class InlineQueryResultVoiceImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVoice { ) : InlineQueryResultVoice {
override val type: String = inlineQueryResultVoiceType override val type: String = inlineQueryResultVoiceType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }
} }

View File

@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.CommonAbstracts.CommonContactData import dev.inmo.tgbotapi.CommonAbstracts.CommonContactData
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -16,4 +15,4 @@ data class InputContactMessageContent(
override val lastName: String? = null, override val lastName: String? = null,
@SerialName(vcardField) @SerialName(vcardField)
override val vcard: String? = null override val vcard: String? = null
) : CommonContactData, InputMessageContent ) : CommonContactData, InputMessageContent

View File

@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
import dev.inmo.tgbotapi.types.payments.abstracts.Currency import dev.inmo.tgbotapi.types.payments.abstracts.Currency

View File

@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -20,4 +19,4 @@ data class InputLocationMessageContent(
override val heading: Degrees? = null, override val heading: Degrees? = null,
@SerialName(proximityAlertRadiusField) @SerialName(proximityAlertRadiusField)
override val proximityAlertRadius: Meters? = null override val proximityAlertRadius: Meters? = null
) : Locationed, HorizontallyAccured, ProximityAlertable, Livable, Headed, InputMessageContent ) : Locationed, HorizontallyAccured, ProximityAlertable, Livable, Headed, InputMessageContent

View File

@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContentSerializer
import kotlinx.serialization.Serializable
@Serializable(InputMessageContentSerializer::class)
sealed interface InputMessageContent

View File

@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
@ -23,7 +23,7 @@ fun InputTextMessageContent(
* Represents the [InputMessageContent] of a text message to be sent as the result of an inline query. * Represents the [InputMessageContent] of a text message to be sent as the result of an inline query.
*/ */
fun InputTextMessageContent( fun InputTextMessageContent(
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
disableWebPagePreview: Boolean? = null disableWebPagePreview: Boolean? = null
) = InputTextMessageContent(entities.makeString(), null, entities.toRawMessageEntities(), disableWebPagePreview) ) = InputTextMessageContent(entities.makeString(), null, entities.toRawMessageEntities(), disableWebPagePreview)
@ -41,4 +41,4 @@ data class InputTextMessageContent internal constructor(
override val textSources: List<TextSource>? by lazy { override val textSources: List<TextSource>? by lazy {
rawEntities ?.asTextSources(text) rawEntities ?.asTextSources(text)
} }
} }

View File

@ -3,7 +3,6 @@ package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.CommonAbstracts.CommonVenueData import dev.inmo.tgbotapi.CommonAbstracts.CommonVenueData
import dev.inmo.tgbotapi.CommonAbstracts.Locationed import dev.inmo.tgbotapi.CommonAbstracts.Locationed
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,13 +1,9 @@
package dev.inmo.tgbotapi.types.InlineQueries.abstracts package dev.inmo.tgbotapi.types.InlineQueries.abstracts
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
import dev.inmo.tgbotapi.types.InlineQueryIdentifier import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.ChatType import dev.inmo.tgbotapi.types.chat.ChatType
interface InlineQuery { @Deprecated("Replaced", ReplaceWith("InlineQuery", "dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery"))
val id: InlineQueryIdentifier typealias InlineQuery = InlineQuery
val from: User
val query: String
val offset: String
val chatType: ChatType?
}

View File

@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.types.InlineQueries.abstracts package dev.inmo.tgbotapi.types.InlineQueries.abstracts
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContentSerializer import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContentSerializer
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable(InputMessageContentSerializer::class) @Deprecated("Replaced", ReplaceWith("InputMessageContent", "dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent"))
interface InputMessageContent typealias InputMessageContent = InputMessageContent

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.query package dev.inmo.tgbotapi.types.InlineQueries.query
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery
import dev.inmo.tgbotapi.types.InlineQueryIdentifier import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.ChatType import dev.inmo.tgbotapi.types.chat.ChatType

View File

@ -0,0 +1,13 @@
package dev.inmo.tgbotapi.types.InlineQueries.query
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.ChatType
sealed interface InlineQuery {
val id: InlineQueryIdentifier
val from: User
val query: String
val offset: String
val chatType: ChatType?
}

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.query package dev.inmo.tgbotapi.types.InlineQueries.query
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery
import dev.inmo.tgbotapi.types.InlineQueryIdentifier import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.ChatType import dev.inmo.tgbotapi.types.chat.ChatType

View File

@ -1,5 +1,5 @@
package dev.inmo.tgbotapi.types.InputMedia package dev.inmo.tgbotapi.types.InputMedia
interface DuratedInputMedia : InputMedia { sealed interface DuratedInputMedia : InputMedia {
val duration: Long? val duration: Long?
} }

View File

@ -4,8 +4,8 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable(InputMediaSerializer::class) @Serializable(InputMediaSerializer::class)
interface InputMedia { sealed interface InputMedia {
val type: String val type: String
val file: InputFile val file: InputFile
val media: String val media: String
} }

View File

@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
@ -22,7 +23,7 @@ fun InputMediaAnimation(
fun InputMediaAnimation( fun InputMediaAnimation(
file: InputFile, file: InputFile,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
duration: Long? = null, duration: Long? = null,

View File

@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.files.AudioFile import dev.inmo.tgbotapi.types.files.AudioFile
@ -14,7 +15,7 @@ internal const val audioInputMediaType = "audio"
fun InputMediaAudio( fun InputMediaAudio(
file: InputFile, file: InputFile,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
duration: Long? = null, duration: Long? = null,
performer: String? = null, performer: String? = null,
title: String? = null, title: String? = null,

View File

@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.files.DocumentFile import dev.inmo.tgbotapi.types.files.DocumentFile
@ -21,7 +22,7 @@ fun InputMediaDocument(
fun InputMediaDocument( fun InputMediaDocument(
file: InputFile, file: InputFile,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
thumb: InputFile? = null, thumb: InputFile? = null,
disableContentTypeDetection: Boolean? = null disableContentTypeDetection: Boolean? = null
) = InputMediaDocument(file, entities.makeString(), null, entities.toRawMessageEntities(), thumb, disableContentTypeDetection) ) = InputMediaDocument(file, entities.makeString(), null, entities.toRawMessageEntities(), thumb, disableContentTypeDetection)

View File

@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.files.PhotoSize import dev.inmo.tgbotapi.types.files.PhotoSize
@ -20,7 +21,7 @@ fun InputMediaPhoto(
fun InputMediaPhoto( fun InputMediaPhoto(
file: InputFile, file: InputFile,
entities: List<TextSource> entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>
) = InputMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) ) = InputMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities())
@Serializable @Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InputMedia package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
@ -24,7 +23,7 @@ fun InputMediaVideo(
fun InputMediaVideo( fun InputMediaVideo(
file: InputFile, file: InputFile,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
width: Int? = null, width: Int? = null,
height: Int? = null, height: Int? = null,
duration: Long? = null, duration: Long? = null,
@ -46,7 +45,7 @@ data class InputMediaVideo internal constructor (
override val thumb: InputFile? = null override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, VisualMediaGroupMemberInputMedia { ) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, VisualMediaGroupMemberInputMedia {
override val type: String = videoInputMediaType override val type: String = videoInputMediaType
override val textSources: List<TextSource>? by lazy { override val textSources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null) rawEntities ?.asTextSources(text ?: return@lazy null)
} }

View File

@ -15,12 +15,12 @@ internal fun <T> T.buildArguments(withSerializer: SerializationStrategy<T>) = ar
) )
@Serializable(MediaGroupMemberInputMediaSerializer::class) @Serializable(MediaGroupMemberInputMediaSerializer::class)
interface MediaGroupMemberInputMedia : InputMedia, TextedOutput { sealed interface MediaGroupMemberInputMedia : InputMedia, TextedOutput {
fun serialize(format: StringFormat): String fun serialize(format: StringFormat): String
} }
interface AudioMediaGroupMemberInputMedia: MediaGroupMemberInputMedia sealed interface AudioMediaGroupMemberInputMedia: MediaGroupMemberInputMedia
interface DocumentMediaGroupMemberInputMedia: MediaGroupMemberInputMedia sealed interface DocumentMediaGroupMemberInputMedia: MediaGroupMemberInputMedia
@Serializable(MediaGroupMemberInputMediaSerializer::class) @Serializable(MediaGroupMemberInputMediaSerializer::class)
interface VisualMediaGroupMemberInputMedia : MediaGroupMemberInputMedia sealed interface VisualMediaGroupMemberInputMedia : MediaGroupMemberInputMedia

View File

@ -1,6 +1,6 @@
package dev.inmo.tgbotapi.types.InputMedia package dev.inmo.tgbotapi.types.InputMedia
interface SizedInputMedia : InputMedia { sealed interface SizedInputMedia : InputMedia {
val width: Int? val width: Int?
val height: Int? val height: Int?
} }

View File

@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.abstracts.InputFile
interface ThumbedInputMedia : InputMedia { sealed interface ThumbedInputMedia : InputMedia {
val thumb: InputFile? val thumb: InputFile?
} }

View File

@ -1,5 +1,5 @@
package dev.inmo.tgbotapi.types.InputMedia package dev.inmo.tgbotapi.types.InputMedia
interface TitledInputMedia : InputMedia { sealed interface TitledInputMedia : InputMedia {
val title: String? val title: String?
} }

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -22,8 +21,8 @@ internal data class RawMessageEntity(
internal fun RawMessageEntity.asTextSource( internal fun RawMessageEntity.asTextSource(
source: String, source: String,
subParts: List<TextSource> subParts: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>
): TextSource { ): dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource {
val sourceSubstring: String = source.substring(range) val sourceSubstring: String = source.substring(range)
val subPartsWithRegulars by lazy { val subPartsWithRegulars by lazy {
subParts.fillWithRegulars(sourceSubstring) subParts.fillWithRegulars(sourceSubstring)
@ -40,8 +39,15 @@ internal fun RawMessageEntity.asTextSource(
"italic" -> ItalicTextSource(sourceSubstring, subPartsWithRegulars) "italic" -> ItalicTextSource(sourceSubstring, subPartsWithRegulars)
"code" -> CodeTextSource(sourceSubstring) "code" -> CodeTextSource(sourceSubstring)
"pre" -> PreTextSource(sourceSubstring, language) "pre" -> PreTextSource(sourceSubstring, language)
"text_link" -> TextLinkTextSource(sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link")) "text_link" -> TextLinkTextSource(
"text_mention" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), subPartsWithRegulars) sourceSubstring,
url ?: throw IllegalStateException("URL must not be null for text link")
)
"text_mention" -> TextMentionTextSource(
sourceSubstring,
user ?: throw IllegalStateException("User must not be null for text mention"),
subPartsWithRegulars
)
"underline" -> UnderlineTextSource(sourceSubstring, subPartsWithRegulars) "underline" -> UnderlineTextSource(sourceSubstring, subPartsWithRegulars)
"strikethrough" -> StrikethroughTextSource(sourceSubstring, subPartsWithRegulars) "strikethrough" -> StrikethroughTextSource(sourceSubstring, subPartsWithRegulars)
else -> RegularTextSource(sourceSubstring) else -> RegularTextSource(sourceSubstring)
@ -52,9 +58,9 @@ private inline operator fun <T : Comparable<T>> ClosedRange<T>.contains(other: C
return start <= other.start && endInclusive >= other.endInclusive return start <= other.start && endInclusive >= other.endInclusive
} }
internal fun List<TextSource>.fillWithRegulars(source: String): List<TextSource> { internal fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.fillWithRegulars(source: String): List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource> {
var index = 0 var index = 0
val result = mutableListOf<TextSource>() val result = mutableListOf<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>()
for (i in 0 until size) { for (i in 0 until size) {
val textSource = get(i) val textSource = get(i)
val thisSourceInStart = source.startsWith(textSource.source, index) val thisSourceInStart = source.startsWith(textSource.source, index)
@ -74,9 +80,12 @@ internal fun List<TextSource>.fillWithRegulars(source: String): List<TextSource>
return result return result
} }
private fun createTextSources(originalFullString: String, entities: RawMessageEntities): List<TextSource> { private fun createTextSources(
originalFullString: String,
entities: RawMessageEntities
): List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource> {
val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } } val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } }
val resultList = mutableListOf<TextSource>() val resultList = mutableListOf<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>()
while (mutableEntities.isNotEmpty()) { while (mutableEntities.isNotEmpty()) {
var parent = mutableEntities.removeFirst() var parent = mutableEntities.removeFirst()
@ -130,7 +139,7 @@ private fun createTextSources(originalFullString: String, entities: RawMessageEn
return resultList return resultList
} }
internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEntity> { internal fun dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEntity> {
val source = source val source = source
val length = source.length val length = source.length
return listOfNotNull( return listOfNotNull(
@ -160,23 +169,24 @@ internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEn
} }
internal fun List<TextSource>.toRawMessageEntities(preOffset: Int = 0): List<RawMessageEntity> { internal fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.toRawMessageEntities(preOffset: Int = 0): List<RawMessageEntity> {
var i = preOffset var i = preOffset
return flatMap { textSource -> return flatMap { textSource ->
textSource.toRawMessageEntities(i).also { textSource.toRawMessageEntities(i).also {
i += it.maxByOrNull { it.length } ?.length ?: textSource.source.length i += it.maxByOrNull { it.length }?.length ?: textSource.source.length
} }
} }
} }
fun String.removeLeading(word: String) = if (startsWith(word)){ fun String.removeLeading(word: String) = if (startsWith(word)) {
substring(word.length) substring(word.length)
} else { } else {
this this
} }
internal fun List<TextSource>.toRawMessageEntities(): List<RawMessageEntity> = toRawMessageEntities(0) internal fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.toRawMessageEntities(): List<RawMessageEntity> = toRawMessageEntities(0)
internal fun RawMessageEntities.asTextSources(sourceString: String): List<TextSource> = createTextSources(sourceString, this).fillWithRegulars(sourceString) internal fun RawMessageEntities.asTextSources(sourceString: String): List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource> =
createTextSources(sourceString, this).fillWithRegulars(sourceString)
internal typealias RawMessageEntities = List<RawMessageEntity> internal typealias RawMessageEntities = List<RawMessageEntity>

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -23,4 +22,4 @@ inline fun strikethrough(parts: List<TextSource>) = StrikethroughTextSource(part
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun strikethrough(vararg parts: TextSource) = strikethrough(parts.toList()) inline fun strikethrough(vararg parts: TextSource) = strikethrough(parts.toList())
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun strikethrough(text: String) = strikethrough(regular(text)) inline fun strikethrough(text: String) = strikethrough(regular(text))

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*

View File

@ -0,0 +1,88 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.types.captionLength
import dev.inmo.tgbotapi.types.textLength
import kotlinx.serialization.Serializable
const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods"
typealias TextSourcesList = List<TextSource>
@Serializable(TextSourceSerializer::class)
sealed interface TextSource {
val markdown: String
val markdownV2: String
val html: String
val source: String
val asText: String
get() = source
companion object {
fun serializer() = TextSourceSerializer
}
}
@Suppress("NOTHING_TO_INLINE")
inline operator fun TextSource.plus(other: TextSource) = listOf(this, other)
@Suppress("NOTHING_TO_INLINE")
inline operator fun TextSource.plus(other: List<TextSource>) = listOf(this) + other
@Suppress("NOTHING_TO_INLINE")
inline operator fun TextSource.plus(text: String) = listOf(this, regular(text))
@Suppress("NOTHING_TO_INLINE")
inline operator fun List<TextSource>.plus(text: String) = this + regular(text)
@Serializable(TextSourceSerializer::class)
sealed interface MultilevelTextSource : TextSource {
val subsources: List<TextSource>
companion object {
fun serializer() = TextSourceSerializer
}
}
fun List<TextSource>.makeString() = joinToString("") { it.source }
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
if (isEmpty()) {
return emptyList()
}
val resultList = mutableListOf<MutableList<TextSource>>(mutableListOf())
var currentPartLength = 0
val maxSize = limit.last + 1
for (current in this) {
if (current.source.length > maxSize) {
error("Currently unsupported parts with size more than target one-message parts (${current.source.length} > ${maxSize})")
}
if (currentPartLength + current.source.length > maxSize) {
if (numberOfParts == null || numberOfParts < resultList.size) {
resultList.add(mutableListOf())
currentPartLength = 0
} else {
break
}
}
resultList.last().add(current)
currentPartLength += current.source.length
}
return resultList
}
/**
* This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with
* [captionLength] and all others with
*/
fun List<TextSource>.separateForCaption(): List<List<TextSource>> {
val captionPart = separateForMessage(captionLength, 1).first()
return listOf(captionPart) + minus(captionPart).separateForMessage(textLength)
}
/**
* This method will prepare [TextSource]s list for messages with [textLength]
*/
@Suppress("NOTHING_TO_INLINE")
inline fun List<TextSource>.separateForText(): List<List<TextSource>> = separateForMessage(textLength)

View File

@ -1,14 +1,7 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity
import dev.inmo.tgbotapi.types.MessageEntity.asTextSources
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
private val baseSerializers: Map<String, KSerializer<out TextSource>> = mapOf( private val baseSerializers: Map<String, KSerializer<out TextSource>> = mapOf(
"regular" to RegularTextSource.serializer(), "regular" to RegularTextSource.serializer(),

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -23,4 +22,4 @@ inline fun underline(parts: List<TextSource>) = UnderlineTextSource(parts.makeSt
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun underline(vararg parts: TextSource) = underline(parts.toList()) inline fun underline(vararg parts: TextSource) = underline(parts.toList())
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun underline(text: String) = underline(regular(text)) inline fun underline(text: String) = underline(regular(text))

View File

@ -1,31 +1,33 @@
package dev.inmo.tgbotapi.types.ParseMode package dev.inmo.tgbotapi.types.ParseMode
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
internal const val parseModeField = "parse_mode" internal const val parseModeField = "parse_mode"
@Serializable(ParseModeSerializerObject::class) @Serializable(ParseModeSerializerObject::class)
sealed class ParseMode { sealed interface ParseMode {
abstract val parseModeName: String val parseModeName: String
} }
@Serializable(ParseModeSerializerObject::class) @Serializable(ParseModeSerializerObject::class)
object MarkdownParseMode : ParseMode() { object MarkdownParseMode : ParseMode {
@Serializable @Serializable
@SerialName(parseModeField) @SerialName(parseModeField)
override val parseModeName: String = "Markdown" override val parseModeName: String = "Markdown"
} }
@Serializable(ParseModeSerializerObject::class) @Serializable(ParseModeSerializerObject::class)
object MarkdownV2ParseMode : ParseMode() { object MarkdownV2ParseMode : ParseMode {
@Serializable @Serializable
@SerialName(parseModeField) @SerialName(parseModeField)
override val parseModeName: String = "MarkdownV2" override val parseModeName: String = "MarkdownV2"
} }
@Serializable(ParseModeSerializerObject::class) @Serializable(ParseModeSerializerObject::class)
object HTMLParseMode : ParseMode() { object HTMLParseMode : ParseMode {
@Serializable @Serializable
@SerialName(parseModeField) @SerialName(parseModeField)
override val parseModeName: String = "HTML" override val parseModeName: String = "HTML"
@ -45,6 +47,7 @@ var defaultParseMode: ParseMode = HTML
@Serializer(ParseMode::class) @Serializer(ParseMode::class)
internal object ParseModeSerializerObject : KSerializer<ParseMode> { internal object ParseModeSerializerObject : KSerializer<ParseMode> {
override val descriptor: SerialDescriptor = String.serializer().descriptor
override fun deserialize(decoder: Decoder): ParseMode { override fun deserialize(decoder: Decoder): ParseMode {
return when (decoder.decodeString()) { return when (decoder.decodeString()) {
Markdown.parseModeName -> Markdown Markdown.parseModeName -> Markdown

View File

@ -1,12 +0,0 @@
package dev.inmo.tgbotapi.types.buttons
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ForceReply(
val selective: Boolean? = null
) : KeyboardMarkup {
@SerialName("force_reply")
val forceReply: Boolean = true
}

View File

@ -3,30 +3,31 @@ package dev.inmo.tgbotapi.types.buttons
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.* import kotlinx.serialization.json.*
@Serializable(KeyboardButtonSerializer::class) @Serializable(KeyboardButtonSerializer::class)
sealed class KeyboardButton { sealed interface KeyboardButton {
abstract val text: String val text: String
} }
@Serializable @Serializable
data class SimpleKeyboardButton( data class SimpleKeyboardButton(
override val text: String override val text: String
) : KeyboardButton() ) : KeyboardButton
@Serializable @Serializable
data class UnknownKeyboardButton internal constructor( data class UnknownKeyboardButton internal constructor(
override val text: String, override val text: String,
val raw: String val raw: String
) : KeyboardButton() ) : KeyboardButton
@Serializable @Serializable
data class RequestContactKeyboardButton( data class RequestContactKeyboardButton(
override val text: String override val text: String
) : KeyboardButton() { ) : KeyboardButton {
@SerialName(requestContactField) @SerialName(requestContactField)
val requestContact: Boolean = true val requestContact: Boolean = true
} }
@ -34,7 +35,7 @@ data class RequestContactKeyboardButton(
@Serializable @Serializable
data class RequestLocationKeyboardButton( data class RequestLocationKeyboardButton(
override val text: String override val text: String
) : KeyboardButton() { ) : KeyboardButton {
@SerialName(requestLocationField) @SerialName(requestLocationField)
val requestLocation: Boolean = true val requestLocation: Boolean = true
} }
@ -44,12 +45,15 @@ data class RequestPollKeyboardButton(
override val text: String, override val text: String,
@SerialName(requestPollField) @SerialName(requestPollField)
val requestPoll: KeyboardButtonPollType val requestPoll: KeyboardButtonPollType
) : KeyboardButton() ) : KeyboardButton
@Serializer(KeyboardButton::class) @Serializer(KeyboardButton::class)
internal object KeyboardButtonSerializer : KSerializer<KeyboardButton> { internal object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
private val internalSerializer = JsonElement.serializer()
override val descriptor: SerialDescriptor = internalSerializer.descriptor
override fun deserialize(decoder: Decoder): KeyboardButton { override fun deserialize(decoder: Decoder): KeyboardButton {
val asJson = JsonElement.serializer().deserialize(decoder) val asJson = internalSerializer.deserialize(decoder)
return when { return when {
asJson is JsonPrimitive -> SimpleKeyboardButton(asJson.content) asJson is JsonPrimitive -> SimpleKeyboardButton(asJson.content)
@ -62,7 +66,7 @@ internal object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
asJson is JsonObject && asJson[requestPollField] != null -> RequestPollKeyboardButton( asJson is JsonObject && asJson[requestPollField] != null -> RequestPollKeyboardButton(
asJson[textField]!!.jsonPrimitive.content, asJson[textField]!!.jsonPrimitive.content,
nonstrictJsonFormat.decodeFromJsonElement( nonstrictJsonFormat.decodeFromJsonElement(
KeyboardButtonPollType.serializer(), KeyboardButtonPollTypeSerializer,
asJson[requestPollField] ?.jsonObject ?: buildJsonObject { } asJson[requestPollField] ?.jsonObject ?: buildJsonObject { }
) )
) )

View File

@ -2,34 +2,36 @@ package dev.inmo.tgbotapi.types.buttons
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.* import kotlinx.serialization.json.*
@Serializable(KeyboardButtonPollTypeSerializer::class) @Serializable(KeyboardButtonPollTypeSerializer::class)
sealed class KeyboardButtonPollType { sealed interface KeyboardButtonPollType {
abstract val type: String val type: String
} }
@Serializable @Serializable
class UnknownKeyboardButtonPollType internal constructor(override val type: String): KeyboardButtonPollType() class UnknownKeyboardButtonPollType internal constructor(override val type: String): KeyboardButtonPollType
@Serializable @Serializable
object RegularKeyboardButtonPollType : KeyboardButtonPollType() { object RegularKeyboardButtonPollType : KeyboardButtonPollType {
override val type: String = regularPollType override val type: String = regularPollType
} }
@Serializable @Serializable
object QuizKeyboardButtonPollType : KeyboardButtonPollType() { object QuizKeyboardButtonPollType : KeyboardButtonPollType {
override val type: String = quizPollType override val type: String = quizPollType
} }
@Serializer(KeyboardButtonPollType::class) @Serializer(KeyboardButtonPollType::class)
internal object KeyboardButtonPollTypeSerializer : KSerializer<KeyboardButtonPollType> { internal object KeyboardButtonPollTypeSerializer : KSerializer<KeyboardButtonPollType> {
override fun deserialize(decoder: Decoder): KeyboardButtonPollType { private val internalSerializer = JsonElement.serializer()
val asJson = JsonElement.serializer().deserialize(decoder) override val descriptor: SerialDescriptor = internalSerializer.descriptor
val type = when (asJson) { override fun deserialize(decoder: Decoder): KeyboardButtonPollType {
val type = when (val asJson = internalSerializer.deserialize(decoder)) {
is JsonPrimitive -> asJson.content is JsonPrimitive -> asJson.content
else -> asJson.jsonObject[typeField] ?.jsonPrimitive ?.content ?: "absent" else -> asJson.jsonObject[typeField] ?.jsonPrimitive ?.content ?: "absent"
} }
@ -45,7 +47,7 @@ internal object KeyboardButtonPollTypeSerializer : KSerializer<KeyboardButtonPol
* Crutch due to the fact that direct serialization of objects currently does not work perfectly * Crutch due to the fact that direct serialization of objects currently does not work perfectly
*/ */
override fun serialize(encoder: Encoder, value: KeyboardButtonPollType) { override fun serialize(encoder: Encoder, value: KeyboardButtonPollType) {
JsonObject.serializer().serialize( internalSerializer.serialize(
encoder, encoder,
JsonObject( JsonObject(
mapOf( mapOf(

View File

@ -3,4 +3,4 @@ package dev.inmo.tgbotapi.types.buttons
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable(KeyboardMarkupSerializer::class) @Serializable(KeyboardMarkupSerializer::class)
interface KeyboardMarkup sealed interface KeyboardMarkup

View File

@ -14,7 +14,7 @@ internal object KeyboardMarkupSerializer : KSerializer<KeyboardMarkup> {
) )
override fun serialize(encoder: Encoder, value: KeyboardMarkup) { override fun serialize(encoder: Encoder, value: KeyboardMarkup) {
when(value) { when(value) {
is ForceReply -> ForceReply.serializer().serialize(encoder, value) is ReplyForce -> ReplyForce.serializer().serialize(encoder, value)
is InlineKeyboardMarkup -> InlineKeyboardMarkup.serializer().serialize(encoder, value) is InlineKeyboardMarkup -> InlineKeyboardMarkup.serializer().serialize(encoder, value)
is ReplyKeyboardMarkup -> ReplyKeyboardMarkup.serializer().serialize(encoder, value) is ReplyKeyboardMarkup -> ReplyKeyboardMarkup.serializer().serialize(encoder, value)
is ReplyKeyboardRemove -> ReplyKeyboardRemove.serializer().serialize(encoder, value) is ReplyKeyboardRemove -> ReplyKeyboardRemove.serializer().serialize(encoder, value)

View File

@ -0,0 +1,21 @@
package dev.inmo.tgbotapi.types.buttons
import kotlinx.serialization.*
@Serializable
data class ReplyForce(
val selective: Boolean? = null
) : KeyboardMarkup {
@SerialName("force_reply")
@Required
val forceReply: Boolean = true
companion object {
val ReplyForceSelective = ReplyForce(true)
val ReplyForceNonSelective = ReplyForce(false)
val ReplyForceDefault = ReplyForce()
}
}
@Deprecated("Renamed", ReplaceWith("ReplyForce", "dev.inmo.tgbotapi.types.buttons.ReplyForce"))
typealias ForceReply = ReplyForce

View File

@ -1,12 +1,12 @@
package dev.inmo.tgbotapi.types.buttons package dev.inmo.tgbotapi.types.buttons
import kotlinx.serialization.SerialName import kotlinx.serialization.*
import kotlinx.serialization.Serializable
@Serializable @Serializable
data class ReplyKeyboardRemove( data class ReplyKeyboardRemove(
val selective: Boolean? = null val selective: Boolean? = null
) : KeyboardMarkup { ) : KeyboardMarkup {
@SerialName("remove_keyboard") @SerialName("remove_keyboard")
@Required
val removeKeyboard: Boolean = true val removeKeyboard: Boolean = true
} }

View File

@ -7,42 +7,42 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
sealed class DiceAnimationType { sealed interface DiceAnimationType {
abstract val emoji: String val emoji: String
abstract val valueLimits: IntRange val valueLimits: IntRange
} }
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
object CubeDiceAnimationType : DiceAnimationType() { object CubeDiceAnimationType : DiceAnimationType {
override val emoji: String = "\uD83C\uDFB2" override val emoji: String = "\uD83C\uDFB2"
override val valueLimits: IntRange override val valueLimits: IntRange
get() = dartsCubeAndBowlingDiceResultLimit get() = dartsCubeAndBowlingDiceResultLimit
} }
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
object DartsDiceAnimationType : DiceAnimationType() { object DartsDiceAnimationType : DiceAnimationType {
override val emoji: String = "\uD83C\uDFAF" override val emoji: String = "\uD83C\uDFAF"
override val valueLimits: IntRange override val valueLimits: IntRange
get() = dartsCubeAndBowlingDiceResultLimit get() = dartsCubeAndBowlingDiceResultLimit
} }
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
object BasketballDiceAnimationType : DiceAnimationType() { object BasketballDiceAnimationType : DiceAnimationType {
override val emoji: String = "\uD83C\uDFC0" override val emoji: String = "\uD83C\uDFC0"
override val valueLimits: IntRange override val valueLimits: IntRange
get() = basketballAndFootballDiceResultLimit get() = basketballAndFootballDiceResultLimit
} }
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
object FootballDiceAnimationType : DiceAnimationType() { object FootballDiceAnimationType : DiceAnimationType {
override val emoji: String = "" override val emoji: String = ""
override val valueLimits: IntRange override val valueLimits: IntRange
get() = basketballAndFootballDiceResultLimit get() = basketballAndFootballDiceResultLimit
} }
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
object BowlingDiceAnimationType : DiceAnimationType() { object BowlingDiceAnimationType : DiceAnimationType {
override val emoji: String = "\uD83C\uDFB3" override val emoji: String = "\uD83C\uDFB3"
override val valueLimits: IntRange override val valueLimits: IntRange
get() = dartsCubeAndBowlingDiceResultLimit get() = dartsCubeAndBowlingDiceResultLimit
} }
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
object SlotMachineDiceAnimationType : DiceAnimationType() { object SlotMachineDiceAnimationType : DiceAnimationType {
override val emoji: String = "\uD83C\uDFB0" override val emoji: String = "\uD83C\uDFB0"
override val valueLimits: IntRange override val valueLimits: IntRange
get() = slotMachineDiceResultLimit get() = slotMachineDiceResultLimit
@ -50,7 +50,7 @@ object SlotMachineDiceAnimationType : DiceAnimationType() {
@Serializable(DiceAnimationTypeSerializer::class) @Serializable(DiceAnimationTypeSerializer::class)
data class CustomDiceAnimationType( data class CustomDiceAnimationType(
override val emoji: String override val emoji: String
) : DiceAnimationType() { ) : DiceAnimationType {
override val valueLimits: IntRange override val valueLimits: IntRange
get() = error("Custom dice animation type have unknown value limits") get() = error("Custom dice animation type have unknown value limits")
} }

View File

@ -4,13 +4,14 @@ import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonNull import kotlinx.serialization.json.JsonNull
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
@Serializable(LocationSerializer::class) @Serializable(LocationSerializer::class)
sealed class Location : Locationed, HorizontallyAccured sealed interface Location : Locationed, HorizontallyAccured
@Serializable @Serializable
data class StaticLocation( data class StaticLocation(
@ -20,7 +21,7 @@ data class StaticLocation(
override val latitude: Double, override val latitude: Double,
@SerialName(horizontalAccuracyField) @SerialName(horizontalAccuracyField)
override val horizontalAccuracy: Meters? = null override val horizontalAccuracy: Meters? = null
) : Location() ) : Location
@Serializable @Serializable
data class LiveLocation( data class LiveLocation(
@ -36,11 +37,13 @@ data class LiveLocation(
override val heading: Degrees? = null, override val heading: Degrees? = null,
@SerialName(proximityAlertRadiusField) @SerialName(proximityAlertRadiusField)
override val proximityAlertRadius: Meters? = null override val proximityAlertRadius: Meters? = null
) : Location(), Livable, ProximityAlertable, Headed ) : Location, Livable, ProximityAlertable, Headed
@Serializer(Location::class) @Serializer(Location::class)
object LocationSerializer : KSerializer<Location> { object LocationSerializer : KSerializer<Location> {
override fun deserialize(decoder: Decoder): Location = JsonObject.serializer().deserialize(decoder).let { private val internalSerializer = JsonObject.serializer()
override val descriptor: SerialDescriptor = internalSerializer.descriptor
override fun deserialize(decoder: Decoder): Location = internalSerializer.deserialize(decoder).let {
if (it.containsKey(livePeriodField) && it[livePeriodField] != JsonNull) { if (it.containsKey(livePeriodField) && it[livePeriodField] != JsonNull) {
nonstrictJsonFormat.decodeFromJsonElement(LiveLocation.serializer(), it) nonstrictJsonFormat.decodeFromJsonElement(LiveLocation.serializer(), it)
} else { } else {

View File

@ -2,10 +2,10 @@ package dev.inmo.tgbotapi.types.polls
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
import com.soywiz.klock.TimeSpan import com.soywiz.klock.TimeSpan
import dev.inmo.tgbotapi.CommonAbstracts.ExplainedInput import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.* import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor
@ -13,19 +13,19 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.* import kotlinx.serialization.json.*
sealed class ScheduledCloseInfo { sealed interface ScheduledCloseInfo {
abstract val closeDateTime: DateTime val closeDateTime: DateTime
} }
data class ExactScheduledCloseInfo( data class ExactScheduledCloseInfo(
override val closeDateTime: DateTime override val closeDateTime: DateTime
) : ScheduledCloseInfo() ) : ScheduledCloseInfo
data class ApproximateScheduledCloseInfo( data class ApproximateScheduledCloseInfo(
val openDuration: TimeSpan, val openDuration: TimeSpan,
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
val startPoint: DateTime = DateTime.now() val startPoint: DateTime = DateTime.now()
) : ScheduledCloseInfo() { ) : ScheduledCloseInfo {
override val closeDateTime: DateTime = startPoint + openDuration override val closeDateTime: DateTime = startPoint + openDuration
} }
@ -42,18 +42,18 @@ val LongSeconds.asExactScheduledCloseInfo
) )
@Serializable(PollSerializer::class) @Serializable(PollSerializer::class)
sealed class Poll { sealed interface Poll {
abstract val id: PollIdentifier val id: PollIdentifier
abstract val question: String val question: String
abstract val options: List<PollOption> val options: List<PollOption>
abstract val votesCount: Int val votesCount: Int
abstract val isClosed: Boolean val isClosed: Boolean
abstract val isAnonymous: Boolean val isAnonymous: Boolean
abstract val scheduledCloseInfo: ScheduledCloseInfo? val scheduledCloseInfo: ScheduledCloseInfo?
} }
@Serializable(PollSerializer::class) @Serializable(PollSerializer::class)
sealed class MultipleAnswersPoll : Poll() sealed interface MultipleAnswersPoll : Poll
@Serializable @Serializable
private class RawPoll( private class RawPoll(
@ -105,7 +105,7 @@ data class UnknownPollType internal constructor(
override val isAnonymous: Boolean = false, override val isAnonymous: Boolean = false,
@Serializable @Serializable
val raw: JsonObject val raw: JsonObject
) : Poll() { ) : Poll {
@Transient @Transient
override val scheduledCloseInfo: ScheduledCloseInfo? = (raw[closeDateField] ?: raw[openPeriodField]) override val scheduledCloseInfo: ScheduledCloseInfo? = (raw[closeDateField] ?: raw[openPeriodField])
?.jsonPrimitive ?.jsonPrimitive
@ -123,7 +123,7 @@ data class RegularPoll(
override val isAnonymous: Boolean = false, override val isAnonymous: Boolean = false,
val allowMultipleAnswers: Boolean = false, val allowMultipleAnswers: Boolean = false,
override val scheduledCloseInfo: ScheduledCloseInfo? = null override val scheduledCloseInfo: ScheduledCloseInfo? = null
) : MultipleAnswersPoll() ) : MultipleAnswersPoll
@Serializable(PollSerializer::class) @Serializable(PollSerializer::class)
data class QuizPoll( data class QuizPoll(
@ -140,7 +140,7 @@ data class QuizPoll(
override val isClosed: Boolean = false, override val isClosed: Boolean = false,
override val isAnonymous: Boolean = false, override val isAnonymous: Boolean = false,
override val scheduledCloseInfo: ScheduledCloseInfo? = null override val scheduledCloseInfo: ScheduledCloseInfo? = null
) : Poll(), ExplainedInput ) : Poll, TextedInput
@Serializer(Poll::class) @Serializer(Poll::class)
internal object PollSerializer : KSerializer<Poll> { internal object PollSerializer : KSerializer<Poll> {

View File

@ -1,17 +1,16 @@
package dev.inmo.tgbotapi.utils.internal package dev.inmo.tgbotapi.utils.internal
import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.link import dev.inmo.tgbotapi.types.link
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Link import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Link
import dev.inmo.tgbotapi.utils.extensions.toHtml import dev.inmo.tgbotapi.utils.extensions.toHtml
private fun List<TextSource>.joinSubSourcesMarkdownV2() = joinToString("") { private fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.joinSubSourcesMarkdownV2() = joinToString("") {
it.markdownV2 it.markdownV2
} }
private fun List<TextSource>.joinSubSourcesHtml() = joinToString("") { private fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.joinSubSourcesHtml() = joinToString("") {
it.html it.html
} }

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -40,7 +39,7 @@ internal val testTextEntities = listOf(
) )
) )
fun List<TextSource>.testTextSources() { fun List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>.testTextSources() {
assertTrue (first() is RegularTextSource) assertTrue (first() is RegularTextSource)
assertTrue (get(1) is BoldTextSource) assertTrue (get(1) is BoldTextSource)
assertTrue (get(2) is RegularTextSource) assertTrue (get(2) is RegularTextSource)

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.MessageEntity package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.plus import dev.inmo.tgbotapi.CommonAbstracts.plus
import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.extensions.utils.formatting.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
@ -40,7 +39,7 @@ class StringFormattingTests {
@Test @Test
fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() { fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() {
val sources: List<TextSource> = regular("It ") + val sources: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource> = regular("It ") +
bold(italic("is") + bold(italic("is") +
" " + " " +
strikethrough(underline("simple"))) + strikethrough(underline("simple"))) +

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types package dev.inmo.tgbotapi.types
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.makeString import dev.inmo.tgbotapi.CommonAbstracts.makeString
import dev.inmo.tgbotapi.TestsJsonFormat import dev.inmo.tgbotapi.TestsJsonFormat
import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.extensions.utils.formatting.*
@ -34,4 +33,4 @@ class TextSourcesTests {
assertEquals(testList, deserialized) assertEquals(testList, deserialized)
assertEquals(testList.makeString(), deserialized.makeString()) assertEquals(testList.makeString(), deserialized.makeString())
} }
} }

View File

@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -41,7 +42,7 @@ suspend fun <T> TelegramBot.editMessageCaption(
suspend fun TelegramBot.editMessageCaption( suspend fun TelegramBot.editMessageCaption(
chatId: ChatIdentifier, chatId: ChatIdentifier,
messageId: MessageIdentifier, messageId: MessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = execute( ) = execute(
EditChatMessageCaption(chatId, messageId, entities, replyMarkup) EditChatMessageCaption(chatId, messageId, entities, replyMarkup)
@ -50,7 +51,7 @@ suspend fun TelegramBot.editMessageCaption(
suspend fun TelegramBot.editMessageCaption( suspend fun TelegramBot.editMessageCaption(
chat: Chat, chat: Chat,
messageId: MessageIdentifier, messageId: MessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = editMessageCaption(chat.id, messageId, entities, replyMarkup) ) = editMessageCaption(chat.id, messageId, entities, replyMarkup)

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.extensions.api.edit.caption package dev.inmo.tgbotapi.extensions.api.edit.caption
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.edit.caption.EditInlineMessageCaption import dev.inmo.tgbotapi.requests.edit.caption.EditInlineMessageCaption
import dev.inmo.tgbotapi.types.InlineMessageIdentifier import dev.inmo.tgbotapi.types.InlineMessageIdentifier
@ -16,6 +15,6 @@ suspend fun TelegramBot.editMessageCaption(
suspend fun TelegramBot.editMessageCaption( suspend fun TelegramBot.editMessageCaption(
inlineMessageId: InlineMessageIdentifier, inlineMessageId: InlineMessageIdentifier,
entities: List<TextSource>, entities: List<dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource>,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
) = execute(EditInlineMessageCaption(inlineMessageId, entities, replyMarkup)) ) = execute(EditInlineMessageCaption(inlineMessageId, entities, replyMarkup))

Some files were not shown because too many files have changed in this diff Show More