1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-27 12:38:45 +00:00

Merge branch 'master' into klassindex

This commit is contained in:
InsanusMokrassar 2021-06-23 22:17:55 +06:00
commit ccf89830bd
205 changed files with 2771 additions and 1372 deletions

12
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,12 @@
name: Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build
run: ./gradlew build

View File

@ -14,10 +14,8 @@ jobs:
cat gradle.properties | sed -e "s/^library_version=\([0-9\.]*\)/library_version=\1-branch_$branch-build${{ github.run_number }}/" > gradle.properties.tmp
rm gradle.properties
mv gradle.properties.tmp gradle.properties
- name: Build
run: ./gradlew build
- name: Publish
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication -x signMetadataPublication
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication
env:
GITHUBPACKAGES_USER: ${{ github.actor }}
GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1 +0,0 @@
spellchecker: true

View File

@ -1,5 +1,71 @@
# TelegramBotAPI changelog
## 0.35.0
**ALL PREVIOUS DEPRECATIONS HAVE BEEN REMOVED**
**JS PART NOW USE IR COMPILER ONLY**
* `Common`:
* `Version`:
* `Kotlin`: `1.4.72` -> `1.5.10`
* `MicroUtils`: `0.4.36` -> `0.5.6`
* `Coroutines`: `1.4.3` -> `1.5.0`
* `Serialization`: `1.1.0` -> `1.2.1`
* `Klock`: `2.0.7` -> `2.1.2`
* `UUID`: `0.2.3` -> `0.3.0`
* `Ktor`: `1.5.4` -> `1.6.0`
* `Core`:
* `ForceReply` has been renamed to `ReplyForce`
* `Captioned` and `Explained` interfaces have been removed
* `RecordAudioAction` and `UploadAudioAction` (and all related to these actions functionality) have been removed
* `TextSource` interface and all related things have been replaced
* `CallbackQuery` interface and all its extenders/implementers become `sealed`
* `InputMedia` interface and all its extenders/implementers become `sealed`
* `ParseMode` interface and all its extenders/implementers become `sealed`
* `ChatMember` becomes `sealed`
* `KeyboardMarkup` becomes `sealed`
* `LeftChatMember` and `MemberChatMember` become interfaces. All their code were replaced to the `*Impl` classes
* Most of `sealed` classes have been modified to be interfaces
* Most serializers becomes public, but they are still `RistFeature`
* For `EntitiesBuilder` multilevel text sources builders with callback have been added
## 0.34.1
* `Common`:
* `Version`:
* `ktor`: `1.5.3` -> `1.5.4`
* `MicroUtils`: `0.4.35` -> `0.4.36`
* `Core`
* Fix in creating of text sources list
## 0.34.0
_**It is recommended to use [0.34.1](https://github.com/InsanusMokrassar/TelegramBotAPI/releases/tag/0.34.1) version due to the bug in 0.34.0 related to rewriting of `TextSource`s creating mechanism.**_
**UPDATE UP TO Telegram Bot API 5.2**
_**ALL OLD DEPRECATIONS WERE REMOVED**_
* `Core`:
* Type `ChatType` has been added
* New `ExtendedChat` for unknown messages `UnknownExtendedChat` has been added
* `SendInvoice#startParameter` becomes optional and replaced in `SendInvoice` constructor
* New interface `CommonSendInvoiceData` has been added
* Fields `CommonSendInvoiceData#maxTipAmount` and `CommonSendInvoiceData#suggestedTipAmounts` have been added
* New type `InputInvoiceMessageContent` has been added
* New interface `TextedWithTextSources` on top of `Texted` interface
* Interface `TextedInput` now extends `TextedWithTextSources` with overriding of `textSources` field as not
nullable
* `textSources` become main field in `TextedInput`
* **MIGRATION** Remove all `import dev.inmo.tgbotapi.CommonAbstracts.textSources` in your project
* `textEntities` become are calculable property in `TextedInput`
* Interface `Captioned` and `CaptionedInput` now is deprecated
* Most of captions usages were replaced with texts
* Interface `Explained` and `ExplainedInput` now is deprecated
* Most of captions usages were replaced with texts
* Interface `VoiceChatEvent` now is `CommonEvent`
* Mechanism of `RawMessageEntity` converting were fully rewritten
## 0.33.4
* `Common`:

View File

@ -6,7 +6,7 @@ Hello! This is a set of libraries for working with Telegram Bot API.
| Common info | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Useful links | [![Chat in Telegram](badges/chat.svg)](https://t.me/InMoTelegramBotAPI) [![Create bot](badges/template.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![KDocs](badges/kdocs.svg)](https://tgbotapi.inmo.dev/docs/index.html) [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/), [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
| Useful links | [![Chat in Telegram](badges/chat.svg)](https://t.me/InMoTelegramBotAPI) [![Create bot](badges/template.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![KDocs](badges/kdocs.svg)](https://tgbotapi.inmo.dev/index.html) [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/), [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
| TelegramBotAPI Core status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) |
| TelegramBotAPI API Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api) |
| TelegramBotAPI Util Extensions status | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils) |

View File

@ -21,6 +21,13 @@ plugins {
allprojects {
repositories {
maven { url 'https://jitpack.io' }
if (it != rootProject.findProject("docs")) {
tasks.whenTaskAdded { task ->
if (task.name == "jsLegacyBrowserTest" || task.name == "jsLegacyNodeTest") {
task.enabled = false
}
}
}
}
}

View File

@ -26,7 +26,7 @@ repositories {
kotlin {
jvm()
js(BOTH) {
js(IR) {
browser()
nodejs()
}

View File

@ -1,3 +1,3 @@
dokka_version=1.4.30
dokka_version=1.4.32
org.gradle.jvmargs=-Xmx1024m

View File

@ -5,18 +5,18 @@ kotlin.js.generate.externals=true
kotlin.incremental=true
kotlin.incremental.js=true
kotlin_version=1.4.32
kotlin_coroutines_version=1.4.3
kotlin_serialisation_runtime_version=1.1.0
klock_version=2.0.7
uuid_version=0.2.4
ktor_version=1.5.3
kotlin_version=1.5.10
kotlin_coroutines_version=1.5.0
kotlin_serialisation_runtime_version=1.2.1
klock_version=2.1.2
uuid_version=0.3.0
ktor_version=1.6.0
micro_utils_version=0.4.35
micro_utils_version=0.5.6
javax_activation_version=1.1.1
library_group=dev.inmo
library_version=0.33.4
library_version=0.35.0
github_release_plugin_version=2.2.12

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip

View File

@ -1,6 +1,5 @@
# TelegramBotAPI Core
[![Download](https://api.bintray.com/packages/insanusmokrassar/TelegramBotAPI/tgbotapi.core/images/download.svg) ](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core/_latestVersion)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core)
## What is it?
@ -10,7 +9,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
## Compatibility
This version compatible with [9th of March 2021 update of TelegramBotAPI (version 5.1)](https://core.telegram.org/bots/api-changelog#march-9-2021).
This version compatible with [26th of April 2021 update of TelegramBotAPI (version 5.2)](https://core.telegram.org/bots/api-changelog#april-26-2021).
## How to implement library?

View File

@ -31,10 +31,8 @@ repositories {
}
kotlin {
jvm {
compilations.main.kotlinOptions.useIR = true
}
js(BOTH) {
jvm()
js(IR) {
browser()
nodejs()
}

View File

@ -1,26 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
interface Captioned {
val caption: String?
}
@Deprecated("This interface is not used in library and will be removed soon")
interface CaptionedOutput : Captioned {
val parseMode: ParseMode?
}
interface CaptionedInput : Captioned {
/**
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
val captionEntities: List<TextPart>
}
/**
* @see CaptionedInput.captionEntities
* @see justTextSources
*/
val CaptionedInput.textSources
get() = captionEntities.justTextSources()

View File

@ -0,0 +1,36 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.payments.abstracts.Currencied
import dev.inmo.tgbotapi.types.payments.abstracts.Priced
interface CommonSendInvoiceData : Titled, Currencied, Priced {
val description: String
val payload: String
val providerToken: String
val maxTipAmount: Int?
val suggestedTipAmounts: List<Int>?
val providerData: String?
val requireName: Boolean
val requirePhoneNumber: Boolean
val requireEmail: Boolean
val requireShippingAddress: Boolean
val shouldSendPhoneNumberToProvider: Boolean
val shouldSendEmailToProvider: Boolean
val priceDependOnShipAddress: Boolean
val photoUrl: String?
val photoSize: Long?
val photoWidth: Int?
val photoHeight: Int?
fun setPhoto(
photoUrl: String,
photoSize: Long? = null,
photoWidth: Int? = null,
photoHeight: Int? = null
)
fun unsetPhoto()
}

View File

@ -1,31 +0,0 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
interface Explained {
val explanation: String?
}
interface ParsableExplainedOutput : Explained {
val parseMode: ParseMode?
}
interface EntitiesExplainedOutput : Explained {
val entities: List<TextSource>?
}
interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput
interface ExplainedInput : Explained {
/**
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
val explanationEntities: List<TextPart>
}
/**
* @see ExplainedInput.explanationEntities
* @see justTextSources
*/
val ExplainedInput.textSources
get() = explanationEntities.justTextSources()

View File

@ -1,98 +1,79 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourceSerializer
import dev.inmo.tgbotapi.types.MessageEntity.textsources.regular
import dev.inmo.tgbotapi.types.MessageEntity.toTextParts
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
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.MessageEntity.textsources.makeString
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.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"
const val DirectInvocationOfTextSourceConstructor =
"It is strongly not recommended to use constructors directly instead of factory methods"
typealias TextSourcesList = List<TextSource>
@Deprecated(
"Replaced",
ReplaceWith("TextSourcesList", "dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList")
)
typealias TextSourcesList = TextSourcesList
@Serializable(TextSourceSerializer::class)
interface TextSource {
val markdown: String
val markdownV2: String
val html: String
val source: String
val asText: String
get() = source
companion object {
fun serializer() = TextSourceSerializer
}
}
@Deprecated("Replaced", ReplaceWith("TextSource", "dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource"))
typealias TextSource = TextSource
@Suppress("NOTHING_TO_INLINE")
inline operator fun TextSource.plus(other: TextSource) = listOf(this, other)
@Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
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
@Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
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))
@Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
inline operator fun TextSource.plus(text: String) =
listOf(this, regular(text))
@Suppress("NOTHING_TO_INLINE")
@Deprecated("Replaced", ReplaceWith("plus", "dev.inmo.tgbotapi.types.MessageEntity.textsources.plus"))
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
}
}
data class TextPart(
val range: IntRange,
val source: TextSource
@Deprecated(
"Replaced",
ReplaceWith("MultilevelTextSource", "dev.inmo.tgbotapi.types.MessageEntity.textsources.MultilevelTextSource")
)
typealias MultilevelTextSource = MultilevelTextSource
fun List<TextPart>.justTextSources() = map { it.source }
fun List<TextSource>.makeString() = joinToString("") { it.source }
internal fun MultilevelTextSource.textParts(offset: Int): List<TextPart> = subsources.toTextParts(offset)
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
if (isEmpty()) {
return emptyList()
}
@Deprecated("Replaced", ReplaceWith("makeString()", "dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString"))
fun List<TextSource>.makeString() = makeString()
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
}
@Deprecated(
"Replaced",
ReplaceWith("separateForMessage", "dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForMessage")
)
fun List<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
* [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)
}
@Deprecated(
"Replaced",
ReplaceWith("separateForCaption", "dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForCaption")
)
fun List<TextSource>.separateForCaption() = separateForCaption()
/**
* 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)
@Deprecated(
"Replaced",
ReplaceWith("separateForText", "dev.inmo.tgbotapi.types.MessageEntity.textsources.separateForText")
)
inline fun List<TextSource>.separateForText() = separateForText()

View File

@ -1,35 +1,29 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
interface Texted {
val text: String?
}
interface TextedWithTextSources : Texted {
/**
* Full list of [TextSource]s
*/
val textSources: List<TextSource>?
}
interface ParsableOutput : Texted {
val parseMode: ParseMode?
}
interface EntitiesOutput : Texted {
interface EntitiesOutput : TextedWithTextSources {
val entities: List<TextSource>?
get() = textSources
}
interface TextedOutput : ParsableOutput, EntitiesOutput
interface TextedInput : Texted {
/**
* Here must be full list of entities. This list must contains [TextPart]s with
* [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] in case if source text contains parts of
* regular text
*/
val textEntities: List<TextPart>
interface TextedInput : TextedWithTextSources {
override val textSources: List<TextSource>
}
/**
* Full list of [TextSource] built from source[TextedInput.textEntities]
*
* @see TextedInput.textEntities
* @see justTextSources
*/
val TextedInput.textSources
get() = textEntities.justTextSources()

View File

@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.polls.Poll
import dev.inmo.tgbotapi.types.polls.PollSerializer
import kotlinx.serialization.*
@Serializable
@ -19,7 +20,7 @@ data class StopPoll(
) : MessageAction, SimpleRequest<Poll>, ReplyMarkup {
override fun method(): String = "stopPoll"
override val resultDeserializer: DeserializationStrategy<Poll>
get() = Poll.serializer()
get() = PollSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.StorageFile
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
@ -30,8 +31,8 @@ data class FileId(
fun String.toInputFile() = FileId(this)
@Serializer(InputFile::class)
internal object InputFileSerializer : KSerializer<InputFile> {
@RiskFeature
object InputFileSerializer : KSerializer<InputFile> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(FileId::class.toString(), PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: InputFile) = encoder.encodeString(value.fileId)
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())

View File

@ -4,7 +4,8 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.serializers.InlineQueryResultSerializer
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
@ -26,7 +27,7 @@ data class AnswerInlineQuery(
val switchPmText: String? = null,
@SerialName(switchPmParameterField)
val switchPmParameter: String? = null
): SimpleRequest<Boolean> {
) : SimpleRequest<Boolean> {
override fun method(): String = "answerInlineQuery"
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
@ -51,6 +52,7 @@ fun InlineQuery.createAnswer(
switchPmParameter
)
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ListSerializer(
@RiskFeature
object InlineQueryAnswersResultsSerializer : KSerializer<List<InlineQueryResult>> by ListSerializer(
InlineQueryResultSerializer
)

View File

@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.requests.answers.payments.abstracts.AnswerShippingQuery
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.payments.ShippingOption
import dev.inmo.tgbotapi.types.payments.ShippingQuery
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.builtins.ListSerializer
@ -21,7 +22,8 @@ data class AnswerShippingQueryOk(
get() = serializer()
}
internal object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ListSerializer(
@RiskFeature
object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ListSerializer(
ShippingOption.serializer()
)

View File

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

View File

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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.requests.games.abstracts
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.games.GameHighScore
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
@ -15,4 +16,5 @@ interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
get() = GameHighScoresSerializer
}
internal object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ListSerializer(GameHighScore.serializer())
@RiskFeature
object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ListSerializer(GameHighScore.serializer())

View File

@ -1,11 +1,13 @@
package dev.inmo.tgbotapi.requests.send
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.CommonAbstracts.types.MessageAction
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -32,7 +34,18 @@ fun CopyMessage(
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = CopyMessage(fromChatId, toChatId, messageId, entities.makeString(), null, entities.toRawMessageEntities(), disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
) = CopyMessage(
fromChatId,
toChatId,
messageId,
entities.makeString(),
null,
entities.toRawMessageEntities(),
disableNotification,
replyToMessageId,
allowSendingWithoutReply,
replyMarkup
)
@Serializable
data class CopyMessage internal constructor(
@ -62,8 +75,8 @@ data class CopyMessage internal constructor(
TextedOutput {
override val chatId: ChatIdentifier
get() = fromChatId
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: List<TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
override fun method(): String = "copyMessage"

View File

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

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -20,7 +21,7 @@ fun SendAnimation(
chatId: ChatIdentifier,
animation: InputFile,
thumb: InputFile? = null,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
duration: Long? = null,
width: Int? = null,
@ -39,7 +40,7 @@ fun SendAnimation(
chatId,
animationAsFileId,
thumbAsFileId,
caption,
text,
parseMode,
null,
duration,
@ -65,7 +66,7 @@ fun SendAnimation(
chatId: ChatIdentifier,
animation: InputFile,
thumb: InputFile? = null,
entities: List<TextSource>,
entities: TextSourcesList,
duration: Long? = null,
width: Int? = null,
height: Int? = null,
@ -144,8 +145,8 @@ data class SendAnimationData internal constructor(
DuratedSendMessageRequest<ContentMessage<AnimationContent>>,
SizedSendMessageRequest<ContentMessage<AnimationContent>>
{
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -1,11 +1,13 @@
package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.Performerable
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -20,7 +22,7 @@ fun SendAudio(
chatId: ChatIdentifier,
audio: InputFile,
thumb: InputFile? = null,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
duration: Long? = null,
performer: String? = null,
@ -39,7 +41,7 @@ fun SendAudio(
chatId,
audioAsFileId,
thumbAsFileId,
caption,
text,
parseMode,
null,
duration,
@ -145,8 +147,8 @@ data class SendAudioData internal constructor(
DuratedSendMessageRequest<ContentMessage<AudioContent>>,
Performerable
{
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: List<TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -29,7 +30,7 @@ fun SendDocument(
chatId: ChatIdentifier,
document: InputFile,
thumb: InputFile? = null,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
@ -46,7 +47,7 @@ fun SendDocument(
chatId,
documentAsFileId,
thumbAsFileId,
caption,
text,
parseMode,
null,
disableNotification,
@ -79,7 +80,7 @@ fun SendDocument(
chatId: ChatIdentifier,
document: InputFile,
thumb: InputFile? = null,
entities: List<TextSource>,
entities: TextSourcesList,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
@ -157,8 +158,8 @@ data class SendDocumentData internal constructor(
TextableSendMessageRequest<ContentMessage<DocumentContent>>,
ThumbedSendMessageRequest<ContentMessage<DocumentContent>>
{
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -18,7 +19,7 @@ import kotlinx.serialization.*
fun SendPhoto(
chatId: ChatIdentifier,
photo: InputFile,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
@ -28,7 +29,7 @@ fun SendPhoto(
val data = SendPhotoData(
chatId,
(photo as? FileId) ?.fileId,
caption,
text,
parseMode,
null,
disableNotification,
@ -47,7 +48,7 @@ fun SendPhoto(
fun SendPhoto(
chatId: ChatIdentifier,
photo: InputFile,
entities: List<TextSource>,
entities: TextSourcesList,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
@ -55,7 +56,7 @@ fun SendPhoto(
): Request<ContentMessage<PhotoContent>> {
val data = SendPhotoData(
chatId,
(photo as? FileId) ?.fileId,
(photo as? FileId)?.fileId,
entities.makeString(),
null,
entities.toRawMessageEntities(),
@ -100,8 +101,8 @@ data class SendPhotoData internal constructor(
ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>,
TextableSendMessageRequest<ContentMessage<PhotoContent>>
{
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -20,7 +21,7 @@ fun SendVideo(
chatId: ChatIdentifier,
video: InputFile,
thumb: InputFile? = null,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
duration: Long? = null,
width: Int? = null,
@ -40,7 +41,7 @@ fun SendVideo(
chatId,
videoAsFileId,
thumbAsFileId,
caption,
text,
parseMode,
null,
duration,
@ -67,7 +68,7 @@ fun SendVideo(
chatId: ChatIdentifier,
video: InputFile,
thumb: InputFile? = null,
entities: List<TextSource>,
entities: TextSourcesList,
duration: Long? = null,
width: Int? = null,
height: Int? = null,
@ -150,8 +151,8 @@ data class SendVideoData internal constructor(
DuratedSendMessageRequest<ContentMessage<VideoContent>>,
SizedSendMessageRequest<ContentMessage<VideoContent>>
{
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.requests.send.media
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
@ -19,7 +20,7 @@ import kotlinx.serialization.*
fun SendVoice(
chatId: ChatIdentifier,
voice: InputFile,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
duration: Long? = null,
disableNotification: Boolean = false,
@ -33,7 +34,7 @@ fun SendVoice(
val data = SendVoiceData(
chatId,
voiceAsFileId,
caption,
text,
parseMode,
null,
duration,
@ -56,7 +57,7 @@ fun SendVoice(
fun SendVoice(
chatId: ChatIdentifier,
voice: InputFile,
entities: List<TextSource>,
entities: TextSourcesList,
duration: Long? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
@ -120,8 +121,8 @@ data class SendVoiceData internal constructor(
TextableSendMessageRequest<ContentMessage<VoiceContent>>,
DuratedSendMessageRequest<ContentMessage<VoiceContent>>
{
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.requests.send.payments
import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData
import dev.inmo.tgbotapi.CommonAbstracts.types.*
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
import dev.inmo.tgbotapi.types.*
@ -9,7 +10,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializ
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
import dev.inmo.tgbotapi.types.payments.abstracts.*
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
import kotlinx.serialization.*
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
@ -23,36 +24,40 @@ data class SendInvoice(
@SerialName(chatIdField)
override val chatId: ChatId,
@SerialName(titleField)
val title: String,
override val title: String,
@SerialName(descriptionField)
val description: String,
override val description: String,
@SerialName(payloadField)
val payload: String,
override val payload: String,
@SerialName(providerTokenField)
val providerToken: String,
@SerialName(startParameterField)
val startParameter: StartParameter,
override val providerToken: String,
@SerialName(currencyField)
override val currency: Currency,
@Serializable(LabeledPricesSerializer::class)
@SerialName(pricesField)
override val prices: List<LabeledPrice>,
@SerialName(maxTipAmountField)
override val maxTipAmount: Int? = null,
@SerialName(suggestedTipAmountsField)
override val suggestedTipAmounts: List<Int>? = null,
@SerialName(startParameterField)
val startParameter: StartParameter? = null,
@SerialName(providerDataField)
val providerData: String? = null,
override val providerData: String? = null,
@SerialName(requireNameField)
val requireName: Boolean = false,
override val requireName: Boolean = false,
@SerialName(requirePhoneNumberField)
val requirePhoneNumber: Boolean = false,
override val requirePhoneNumber: Boolean = false,
@SerialName(requireEmailField)
val requireEmail: Boolean = false,
override val requireEmail: Boolean = false,
@SerialName(requireShippingAddressField)
val requireShippingAddress: Boolean = false,
override val requireShippingAddress: Boolean = false,
@SerialName(shouldSendPhoneNumberToProviderField)
val shouldSendPhoneNumberToProvider: Boolean = false,
override val shouldSendPhoneNumberToProvider: Boolean = false,
@SerialName(shouldSendEmailToProviderField)
val shouldSendEmailToProvider: Boolean = false,
override val shouldSendEmailToProvider: Boolean = false,
@SerialName(priceDependOnShipAddressField)
val priceDependOnShipAddress: Boolean = false,
override val priceDependOnShipAddress: Boolean = false,
@SerialName(disableNotificationField)
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
@ -61,8 +66,7 @@ data class SendInvoice(
override val allowSendingWithoutReply: Boolean? = null,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null
) : Currencied,
Priced,
) : CommonSendInvoiceData,
ChatRequest,
DisableNotification,
ReplyMessageId,
@ -75,24 +79,35 @@ data class SendInvoice(
get() = serializer()
@SerialName(photoUrlField)
var photoUrl: String? = null
override var photoUrl: String? = null
private set
@SerialName(photoSizeField)
var photoSize: Long? = null
override var photoSize: Long? = null
private set
@SerialName(photoWidthField)
var photoWidth: Int? = null
override var photoWidth: Int? = null
private set
@SerialName(photoHeightField)
var photoHeight: Int? = null
override var photoHeight: Int? = null
private set
fun setPhoto(
init {
suggestedTipAmounts ?.let { _ ->
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
maxTipAmount ?.let { _ ->
require(
suggestedTipAmounts.none { it > maxTipAmount }
)
}
}
}
override fun setPhoto(
photoUrl: String,
photoSize: Long? = null,
photoWidth: Int? = null,
photoHeight: Int? = null
photoSize: Long?,
photoWidth: Int?,
photoHeight: Int?
) {
this.photoUrl = photoUrl
this.photoSize = photoSize
@ -100,7 +115,7 @@ data class SendInvoice(
this.photoHeight = photoHeight
}
fun unsetPhoto() {
override fun unsetPhoto() {
photoUrl = null
photoSize = null
photoWidth = null

View File

@ -1,11 +1,13 @@
package dev.inmo.tgbotapi.requests.send.polls
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
@ -338,7 +340,7 @@ data class SendQuizPoll internal constructor(
@SerialName(isClosedField)
override val isClosed: Boolean = false,
@SerialName(explanationField)
override val explanation: String? = null,
override val text: String? = null,
@SerialName(explanationParseModeField)
override val parseMode: ParseMode? = null,
@SerialName(explanationEntitiesField)
@ -355,12 +357,12 @@ data class SendQuizPoll internal constructor(
override val allowSendingWithoutReply: Boolean? = null,
@SerialName(replyMarkupField)
override val replyMarkup: KeyboardMarkup? = null
) : SendPoll(), ExplainedOutput {
) : SendPoll(), TextedOutput {
override val type: String = quizPollType
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources()
override val textSources: List<TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {
@ -371,9 +373,9 @@ data class SendQuizPoll internal constructor(
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +
"value is $correctOptionId")
}
if (explanation != null && explanation.length !in explanationLimit) {
if (text != null && text.length !in explanationLimit) {
error("Quiz poll explanation size must be in range $explanationLimit," +
"but actual explanation contains ${explanation.length} symbols")
"but actual explanation contains ${text.length} symbols")
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,9 @@
package dev.inmo.tgbotapi.types
import dev.inmo.micro_utils.common.Warning
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.JsonPrimitive
@ -52,10 +54,12 @@ data class Username(
fun String.toUsername(): Username = Username(this)
@Serializer(ChatIdentifier::class)
internal object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
@RiskFeature
object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
private val internalSerializer = JsonPrimitive.serializer()
override val descriptor: SerialDescriptor = internalSerializer.descriptor
override fun deserialize(decoder: Decoder): ChatIdentifier {
val id = JsonPrimitive.serializer().deserialize(decoder)
val id = internalSerializer.deserialize(decoder)
return id.longOrNull ?.let {
ChatId(it)
} ?: id.content.let {

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
@ -79,7 +80,7 @@ data class CommonInviteLink(
get() = expireDate ?.asDate
}
@Serializer(ChatInviteLink::class)
@RiskFeature
object ChatInviteLinkSerializer : KSerializer<ChatInviteLink> {
override val descriptor: SerialDescriptor
get() = RawChatInviteLink.serializer().descriptor

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,15 @@
package dev.inmo.tgbotapi.types.ChatMember
import dev.inmo.tgbotapi.types.*
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,15 @@
package dev.inmo.tgbotapi.types.ChatMember
import dev.inmo.tgbotapi.types.*
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

@ -20,7 +20,6 @@ interface AdministratorChatMember : SpecialRightsChatMember {
val customTitle: String?
}
@Serializer(AdministratorChatMember::class)
@RiskFeature
object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
override val descriptor: SerialDescriptor = ChatMemberSerializer.descriptor

View File

@ -13,11 +13,10 @@ import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive
@Serializable(ChatMemberSerializer::class)
interface ChatMember {
sealed interface ChatMember {
val user: User
}
@Serializer(ChatMember::class)
@RiskFeature
object ChatMemberSerializer : KSerializer<ChatMember> {
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
@ -27,9 +26,9 @@ object ChatMemberSerializer : KSerializer<ChatMember> {
return when (json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")) {
"creator" -> nonstrictJsonFormat.decodeFromJsonElement(CreatorChatMember.serializer(), json)
"administrator" -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json)
"member" -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMember.serializer(), json)
"member" -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMemberImpl.serializer(), json)
"restricted" -> nonstrictJsonFormat.decodeFromJsonElement(RestrictedChatMember.serializer(), json)
"left" -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMember.serializer(), json)
"left" -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMemberImpl.serializer(), json)
"kicked" -> nonstrictJsonFormat.decodeFromJsonElement(KickedChatMember.serializer(), json)
else -> error("Unknown type of chat member in json: $json")
}
@ -39,9 +38,9 @@ object ChatMemberSerializer : KSerializer<ChatMember> {
when (value) {
is CreatorChatMember -> CreatorChatMember.serializer()
is AdministratorChatMemberImpl -> AdministratorChatMemberImpl.serializer()
is MemberChatMember -> MemberChatMember.serializer()
is MemberChatMember -> MemberChatMemberImpl.serializer()
is RestrictedChatMember -> RestrictedChatMember.serializer()
is LeftChatMember -> LeftChatMember.serializer()
is LeftChatMember -> LeftChatMemberImpl.serializer()
is KickedChatMember -> KickedChatMember.serializer()
}
}

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

@ -80,6 +80,8 @@ val openPeriodPollSecondsLimit = 5 .. 600
val membersLimit = 1 .. 99999
val suggestedTipAmountsLimit = 1 .. 4
const val botActionActualityTime: Seconds = 5
// Made as lazy for correct work in K/JS
@ -315,6 +317,10 @@ const val xShiftField = "x_shift"
const val yShiftField = "y_shift"
const val scaleField = "scale"
const val maxTipAmountField = "max_tip_amount"
const val suggestedTipAmountsField = "suggested_tip_amounts"
const val chatTypeField = "chat_type"
const val explanationEntitiesField = "explanation_entities"
const val explanationParseModeField = "explanation_parse_mode"
const val openPeriodField = "open_period"
@ -349,6 +355,7 @@ const val providerPaymentChargeIdField = "provider_payment_charge_id"
const val providerTokenField = "provider_token"
const val providerDataField = "provider_data"
const val usersField = "users"
const val startDateField = "start_date"
const val requireNameField = "need_name"
const val requirePhoneNumberField = "need_phone_number"

View File

@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -1,12 +1,13 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudioCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -25,10 +26,18 @@ fun InlineQueryResultAudioCachedImpl(
fun InlineQueryResultAudioCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultAudioCachedImpl(id, fileId, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
) = InlineQueryResultAudioCachedImpl(
id,
fileId,
entities.makeString(),
null,
entities.toRawMessageEntities(),
replyMarkup,
inputMessageContent
)
@Serializable
data class InlineQueryResultAudioCachedImpl internal constructor(
@ -48,7 +57,7 @@ data class InlineQueryResultAudioCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultAudioCached {
override val type: String = inlineQueryResultAudioType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
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.inlineQueryResultAudioType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -30,10 +31,21 @@ fun InlineQueryResultAudioImpl(
title: String,
performer: String? = null,
duration: Int? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultAudioImpl internal constructor(
@ -59,7 +71,7 @@ data class InlineQueryResultAudioImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultAudio {
override val type: String = inlineQueryResultAudioType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.CommonContactData
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -1,12 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocumentCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -29,10 +29,20 @@ fun InlineQueryResultDocumentCachedImpl(
fileId: FileId,
title: String,
description: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultDocumentCachedImpl internal constructor(
@ -56,7 +66,7 @@ data class InlineQueryResultDocumentCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultDocumentCached {
override val type: String = inlineQueryResultDocumentType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
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.inlineQueryResultDocumentType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -38,10 +39,24 @@ fun InlineQueryResultDocumentImpl(
thumbWidth: Int? = null,
thumbHeight: Int? = null,
description: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultDocumentImpl internal constructor(
@ -73,7 +88,7 @@ data class InlineQueryResultDocumentImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultDocument {
override val type: String = inlineQueryResultDocumentType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,12 +1,13 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGifCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -27,10 +28,19 @@ fun InlineQueryResultGifCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
title: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultGifCachedImpl internal constructor(
@ -52,7 +62,7 @@ data class InlineQueryResultGifCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultGifCached {
override val type: String = inlineQueryResultGifType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
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.inlineQueryResultGifType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -37,10 +38,24 @@ fun InlineQueryResultGifImpl(
height: Int? = null,
duration: Int? = null,
title: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultGifImpl internal constructor(
@ -72,8 +87,8 @@ data class InlineQueryResultGifImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultGif {
override val type: String = inlineQueryResultGifType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -1,12 +1,13 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4GifCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -27,10 +28,19 @@ fun InlineQueryResultMpeg4GifCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
title: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultMpeg4GifCachedImpl internal constructor(
@ -52,7 +62,7 @@ data class InlineQueryResultMpeg4GifCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultMpeg4GifCached {
override val type: String = inlineQueryResultMpeg4GifType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
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.inlineQueryResultMpeg4GifType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -37,10 +38,24 @@ fun InlineQueryResultMpeg4GifImpl(
height: Int? = null,
duration: Int? = null,
title: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultMpeg4GifImpl internal constructor(
@ -72,8 +87,8 @@ data class InlineQueryResultMpeg4GifImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultMpeg4Gif {
override val type: String = inlineQueryResultMpeg4GifType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
init {

View File

@ -1,12 +1,13 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhotoCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -29,10 +30,20 @@ fun InlineQueryResultPhotoCachedImpl(
fileId: FileId,
title: String? = null,
description: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultPhotoCachedImpl internal constructor(
@ -56,7 +67,7 @@ data class InlineQueryResultPhotoCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultPhotoCached {
override val type: String = inlineQueryResultPhotoType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
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.inlineQueryResultPhotoType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -34,10 +35,23 @@ fun InlineQueryResultPhotoImpl(
height: Int? = null,
title: String? = null,
description: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultPhotoImpl internal constructor(
@ -67,7 +81,7 @@ data class InlineQueryResultPhotoImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultPhoto {
override val type: String = inlineQueryResultPhotoType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -4,7 +4,7 @@ import dev.inmo.tgbotapi.CommonAbstracts.CommonVenueData
import dev.inmo.tgbotapi.CommonAbstracts.Locationed
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -1,12 +1,13 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideoCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -29,10 +30,20 @@ fun InlineQueryResultVideoCachedImpl(
fileId: FileId,
title: String,
description: String? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultVideoCachedImpl internal constructor(
@ -56,7 +67,7 @@ data class InlineQueryResultVideoCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVideoCached {
override val type: String = inlineQueryResultVideoType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
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.inlineQueryResultVideoType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -43,7 +44,22 @@ fun InlineQueryResultVideoImpl(
entities: List<TextSource>,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultVideoImpl internal constructor(
@ -77,7 +93,7 @@ data class InlineQueryResultVideoImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVideo {
override val type: String = inlineQueryResultVideoType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: List<TextSource>? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,12 +1,12 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoiceCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -27,10 +27,19 @@ fun InlineQueryResultVoiceCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
title: String,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultVoiceCachedImpl internal constructor(
@ -52,7 +61,7 @@ data class InlineQueryResultVoiceCachedImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVoiceCached {
override val type: String = inlineQueryResultVoiceType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,11 +1,11 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
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.inlineQueryResultVoiceType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -38,10 +38,20 @@ fun InlineQueryResultVoiceImpl(
url: String,
title: String,
duration: Int? = null,
entities: List<TextSource>,
entities: TextSourcesList,
replyMarkup: InlineKeyboardMarkup? = 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
)
@Serializable
data class InlineQueryResultVoiceImpl internal constructor(
@ -65,7 +75,7 @@ data class InlineQueryResultVoiceImpl internal constructor(
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVoice {
override val type: String = inlineQueryResultVoiceType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
}

View File

@ -1,6 +1,6 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputMessageContent
interface WithInputMessageContentInlineQueryResult : InlineQueryResult {
val inputMessageContent: InputMessageContent?

View File

@ -2,13 +2,14 @@ package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.serializers
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializer(InlineQueryResult::class)
internal object InlineQueryResultSerializer : KSerializer<InlineQueryResult> {
@RiskFeature
object InlineQueryResultSerializer : KSerializer<InlineQueryResult> {
@InternalSerializationApi
override val descriptor: SerialDescriptor = buildSerialDescriptor(InlineQueryResult::class.toString(), PolymorphicKind.OPEN)
override fun serialize(encoder: Encoder, value: InlineQueryResult) {

View File

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

View File

@ -0,0 +1,79 @@
package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
class InputInvoiceMessageContent(
@SerialName(titleField)
override val title: String,
@SerialName(descriptionField)
override val description: String,
@SerialName(payloadField)
override val payload: String,
@SerialName(providerTokenField)
override val providerToken: String,
@SerialName(currencyField)
override val currency: Currency,
@Serializable(LabeledPricesSerializer::class)
@SerialName(pricesField)
override val prices: List<LabeledPrice>,
@SerialName(maxTipAmountField)
override val maxTipAmount: Int? = null,
@SerialName(suggestedTipAmountsField)
override val suggestedTipAmounts: List<Int>? = null,
@SerialName(providerDataField)
override val providerData: String? = null,
@SerialName(requireNameField)
override val requireName: Boolean = false,
@SerialName(requirePhoneNumberField)
override val requirePhoneNumber: Boolean = false,
@SerialName(requireEmailField)
override val requireEmail: Boolean = false,
@SerialName(requireShippingAddressField)
override val requireShippingAddress: Boolean = false,
@SerialName(shouldSendPhoneNumberToProviderField)
override val shouldSendPhoneNumberToProvider: Boolean = false,
@SerialName(shouldSendEmailToProviderField)
override val shouldSendEmailToProvider: Boolean = false,
@SerialName(priceDependOnShipAddressField)
override val priceDependOnShipAddress: Boolean = false
) : InputMessageContent, CommonSendInvoiceData {
@SerialName(photoUrlField)
override var photoUrl: String? = null
private set
@SerialName(photoSizeField)
override var photoSize: Long? = null
private set
@SerialName(photoWidthField)
override var photoWidth: Int? = null
private set
@SerialName(photoHeightField)
override var photoHeight: Int? = null
private set
override fun setPhoto(
photoUrl: String,
photoSize: Long?,
photoWidth: Int?,
photoHeight: Int?
) {
this.photoUrl = photoUrl
this.photoSize = photoSize
this.photoWidth = photoWidth
this.photoHeight = photoHeight
}
override fun unsetPhoto() {
photoUrl = null
photoSize = null
photoWidth = null
photoHeight = null
}
}

View File

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

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

@ -1,10 +1,11 @@
package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview
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.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import kotlinx.serialization.SerialName
@ -23,7 +24,7 @@ fun InputTextMessageContent(
* Represents the [InputMessageContent] of a text message to be sent as the result of an inline query.
*/
fun InputTextMessageContent(
entities: List<TextSource>,
entities: TextSourcesList,
disableWebPagePreview: Boolean? = null
) = InputTextMessageContent(entities.makeString(), null, entities.toRawMessageEntities(), disableWebPagePreview)
@ -38,7 +39,7 @@ data class InputTextMessageContent internal constructor(
@SerialName(disableWebPagePreviewField)
override val disableWebPagePreview: Boolean? = null
) : TextedOutput, DisableWebPagePreview, InputMessageContent {
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
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.Locationed
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -1,14 +1,14 @@
package dev.inmo.tgbotapi.types.InlineQueries
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.*
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializer(InputMessageContent::class)
internal object InputMessageContentSerializer : KSerializer<InputMessageContent> {
@RiskFeature
object InputMessageContentSerializer : KSerializer<InputMessageContent> {
@InternalSerializationApi
override val descriptor: SerialDescriptor = buildSerialDescriptor(InputMessageContent::class.toString(), PolymorphicKind.OPEN)
override fun serialize(encoder: Encoder, value: InputMessageContent) {
@ -17,6 +17,7 @@ internal object InputMessageContentSerializer : KSerializer<InputMessageContent>
is InputLocationMessageContent -> InputLocationMessageContent.serializer().serialize(encoder, value)
is InputTextMessageContent -> InputTextMessageContent.serializer().serialize(encoder, value)
is InputVenueMessageContent -> InputVenueMessageContent.serializer().serialize(encoder, value)
is InputInvoiceMessageContent -> InputInvoiceMessageContent.serializer().serialize(encoder, value)
else -> throw IllegalArgumentException("Unknown for serializing InputContactMessageContent")
}
}

View File

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

View File

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

View File

@ -1,12 +1,13 @@
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.User
import dev.inmo.tgbotapi.types.chat.ChatType
data class BaseInlineQuery(
override val id: InlineQueryIdentifier,
override val from: User,
override val query: String,
override val offset: String
override val offset: String,
override val chatType: ChatType?
) : InlineQuery

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,8 +1,8 @@
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.User
import dev.inmo.tgbotapi.types.chat.ChatType
import dev.inmo.tgbotapi.types.location.Location
data class LocationInlineQuery(
@ -10,5 +10,6 @@ data class LocationInlineQuery(
override val from: User,
override val query: String,
override val offset: String,
override val chatType: ChatType?,
val location: Location
) : InlineQuery

View File

@ -1,6 +1,8 @@
package dev.inmo.tgbotapi.types.InlineQueries.query
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.ChatType
import dev.inmo.tgbotapi.types.chat.ChatTypeSerializer
import dev.inmo.tgbotapi.types.location.Location
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -15,12 +17,15 @@ internal data class RawInlineQuery(
val query: String,
@SerialName(offsetField)
val offset: String,
@SerialName(chatTypeField)
@Serializable(ChatTypeSerializer::class)
val chatType: ChatType? = null,
@SerialName(locationField)
val location: Location? = null
) {
val asInlineQuery by lazy {
location ?.let {
LocationInlineQuery(id, from, query, offset, location)
} ?: BaseInlineQuery(id, from, query, offset)
LocationInlineQuery(id, from, query, offset, chatType, location)
} ?: BaseInlineQuery(id, from, query, offset, chatType)
}
}

View File

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

View File

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

View File

@ -1,10 +1,11 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import kotlinx.serialization.SerialName
@ -22,12 +23,21 @@ fun InputMediaAnimation(
fun InputMediaAnimation(
file: InputFile,
entities: List<TextSource>,
entities: TextSourcesList,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
thumb: InputFile? = null
) = InputMediaAnimation(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb)
) = InputMediaAnimation(
file,
entities.makeString(),
null,
entities.toRawMessageEntities(),
width,
height,
duration,
thumb
)
@Serializable
data class InputMediaAnimation internal constructor(
@ -44,8 +54,8 @@ data class InputMediaAnimation internal constructor(
override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput {
override val type: String = "animation"
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
@SerialName(mediaField)

View File

@ -5,6 +5,8 @@ import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageEntity.textsources.makeString
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.files.AudioFile
@ -14,7 +16,7 @@ internal const val audioInputMediaType = "audio"
fun InputMediaAudio(
file: InputFile,
entities: List<TextSource>,
entities: TextSourcesList,
duration: Long? = null,
performer: String? = null,
title: String? = null,
@ -50,8 +52,8 @@ data class InputMediaAudio internal constructor(
override val thumb: InputFile? = null
) : InputMedia, AudioMediaGroupMemberInputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, Performerable {
override val type: String = audioInputMediaType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
@ -62,12 +64,12 @@ data class InputMediaAudio internal constructor(
}
fun AudioFile.toInputMediaAudio(
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
title: String? = this.title
): InputMediaAudio = InputMediaAudio(
fileId,
caption,
text,
parseMode,
duration,
performer,

View File

@ -1,9 +1,9 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.files.DocumentFile
@ -13,18 +13,25 @@ internal const val documentInputMediaType = "document"
fun InputMediaDocument(
file: InputFile,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
thumb: InputFile? = null,
disableContentTypeDetection: Boolean? = null
) = InputMediaDocument(file, caption, parseMode, null, thumb, disableContentTypeDetection)
) = InputMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection)
fun InputMediaDocument(
file: InputFile,
entities: List<TextSource>,
entities: TextSourcesList,
thumb: InputFile? = null,
disableContentTypeDetection: Boolean? = null
) = InputMediaDocument(file, entities.makeString(), null, entities.toRawMessageEntities(), thumb, disableContentTypeDetection)
) = InputMediaDocument(
file,
entities.makeString(),
null,
entities.toRawMessageEntities(),
thumb,
disableContentTypeDetection
)
/**
* Represents a general file to be sent. See https://core.telegram.org/bots/api#inputmediadocument
@ -50,8 +57,8 @@ data class InputMediaDocument internal constructor(
val disableContentTypeDetection: Boolean? = null
) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia {
override val type: String = documentInputMediaType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
@ -62,11 +69,11 @@ data class InputMediaDocument internal constructor(
}
fun DocumentFile.toInputMediaDocument(
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null
) = InputMediaDocument(
fileId,
caption,
text,
parseMode,
thumb ?.fileId
)

View File

@ -1,10 +1,10 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.files.PhotoSize
@ -20,7 +20,7 @@ fun InputMediaPhoto(
fun InputMediaPhoto(
file: InputFile,
entities: List<TextSource>
entities: TextSourcesList
) = InputMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities())
@Serializable
@ -34,8 +34,8 @@ data class InputMediaPhoto internal constructor(
private val rawEntities: List<RawMessageEntity>? = null
) : InputMedia, VisualMediaGroupMemberInputMedia {
override val type: String = photoInputMediaType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
@ -46,11 +46,11 @@ data class InputMediaPhoto internal constructor(
}
fun PhotoSize.toInputMediaPhoto(
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null
): InputMediaPhoto = InputMediaPhoto(
fileId,
caption,
text,
parseMode
)

View File

@ -1,12 +1,13 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializer(InputMedia::class)
internal object InputMediaSerializer : KSerializer<InputMedia> {
@RiskFeature
object InputMediaSerializer : KSerializer<InputMedia> {
@InternalSerializationApi
override val descriptor: SerialDescriptor = buildSerialDescriptor(InputMedia::class.toString(), PolymorphicKind.OPEN)
override fun serialize(encoder: Encoder, value: InputMedia) {

View File

@ -1,10 +1,10 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import kotlinx.serialization.*
@ -23,7 +23,7 @@ fun InputMediaVideo(
fun InputMediaVideo(
file: InputFile,
entities: List<TextSource>,
entities: TextSourcesList,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
@ -45,8 +45,8 @@ data class InputMediaVideo internal constructor (
override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, VisualMediaGroupMemberInputMedia {
override val type: String = videoInputMediaType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)
}
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)

View File

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

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.types.typeField
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
@ -8,8 +9,8 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
@Serializer(MediaGroupMemberInputMedia::class)
internal object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
@RiskFeature
object MediaGroupMemberInputMediaSerializer : KSerializer<MediaGroupMemberInputMedia> {
@InternalSerializationApi
override val descriptor: SerialDescriptor = buildSerialDescriptor(MediaGroupMemberInputMedia::class.toString(), PolymorphicKind.OPEN)
override fun serialize(encoder: Encoder, value: MediaGroupMemberInputMedia) {

View File

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

View File

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

View File

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

View File

@ -1,10 +1,7 @@
package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
import dev.inmo.tgbotapi.utils.internal.shiftSourcesToTheLeft
import kotlinx.serialization.Serializable
@Serializable
@ -15,70 +12,125 @@ internal data class RawMessageEntity(
val url: String? = null,
val user: User? = null,
val language: String? = null
)
internal fun RawMessageEntity.asTextParts(
source: String,
subParts: List<TextPart>
): List<TextPart> {
val sourceSubstring: String = source.substring(offset, offset + length)
val range = offset until (offset + length)
val shiftedSubSources = sourceSubstring.fullListOfSubSource(subParts.shiftSourcesToTheLeft(offset)).justTextSources()
return when (type) {
"mention" -> MentionTextSource(sourceSubstring, shiftedSubSources)
"hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubSources)
"cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubSources)
"bot_command" -> BotCommandTextSource(sourceSubstring)
"url" -> URLTextSource(sourceSubstring)
"email" -> EMailTextSource(sourceSubstring, shiftedSubSources)
"phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubSources)
"bold" -> BoldTextSource(sourceSubstring, shiftedSubSources)
"italic" -> ItalicTextSource(sourceSubstring, shiftedSubSources)
"code" -> CodeTextSource(sourceSubstring)
"pre" -> PreTextSource(sourceSubstring, language)
"text_link" -> TextLinkTextSource(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"), shiftedSubSources)
"underline" -> UnderlineTextSource(sourceSubstring, shiftedSubSources)
"strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubSources)
else -> RegularTextSource(sourceSubstring)
}.let {
val part = TextPart(range, it)
if (it !is MultilevelTextSource && subParts.isNotEmpty()) {
(subParts + part).sortedBy { currentPart -> currentPart.range.first }
} else {
listOf(part)
}
) {
internal val range by lazy {
offset until (offset + length)
}
}
internal fun createTextPart(originalFullString: String, entities: RawMessageEntities): List<TextPart> {
val mutableEntities = entities.toMutableList()
mutableEntities.sortBy { it.offset }
val resultList = mutableListOf<TextPart>()
internal fun RawMessageEntity.asTextSource(
source: String,
subParts: TextSourcesList
): TextSource {
val sourceSubstring: String = source.substring(range)
val subPartsWithRegulars by lazy {
subParts.fillWithRegulars(sourceSubstring)
}
return when (type) {
"mention" -> MentionTextSource(sourceSubstring, subPartsWithRegulars)
"hashtag" -> HashTagTextSource(sourceSubstring, subPartsWithRegulars)
"cashtag" -> CashTagTextSource(sourceSubstring, subPartsWithRegulars)
"bot_command" -> BotCommandTextSource(sourceSubstring)
"url" -> URLTextSource(sourceSubstring)
"email" -> EMailTextSource(sourceSubstring, subPartsWithRegulars)
"phone_number" -> PhoneNumberTextSource(sourceSubstring, subPartsWithRegulars)
"bold" -> BoldTextSource(sourceSubstring, subPartsWithRegulars)
"italic" -> ItalicTextSource(sourceSubstring, subPartsWithRegulars)
"code" -> CodeTextSource(sourceSubstring)
"pre" -> PreTextSource(sourceSubstring, language)
"text_link" -> TextLinkTextSource(
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)
"strikethrough" -> StrikethroughTextSource(sourceSubstring, subPartsWithRegulars)
else -> RegularTextSource(sourceSubstring)
}
}
while (mutableEntities.isNotEmpty()) {
val currentFirst = mutableEntities.removeAt(0)
val subEntities = if (mutableEntities.isNotEmpty()) {
val lastIndex = currentFirst.offset + currentFirst.length
val subEntities = mutableListOf<RawMessageEntity>()
while (mutableEntities.isNotEmpty()) {
val currentPossibleSubEntity = mutableEntities.first()
if (currentPossibleSubEntity.offset < lastIndex) {
subEntities.add(currentPossibleSubEntity)
mutableEntities.removeAt(0)
} else {
break
private inline operator fun <T : Comparable<T>> ClosedRange<T>.contains(other: ClosedRange<T>): Boolean {
return start <= other.start && endInclusive >= other.endInclusive
}
internal fun TextSourcesList.fillWithRegulars(source: String): TextSourcesList {
var index = 0
val result = mutableListOf<TextSource>()
for (i in 0 until size) {
val textSource = get(i)
val thisSourceInStart = source.startsWith(textSource.source, index)
if (!thisSourceInStart) {
val regularEndIndex = source.indexOf(textSource.source, index)
result.add(regular(source.substring(index, regularEndIndex)))
index = regularEndIndex
}
}
subEntities
} else {
emptyList<RawMessageEntity>()
result.add(textSource)
index += textSource.source.length
}
resultList.addAll(
currentFirst.asTextParts(
if (index != source.length) {
result.add(regular(source.substring(index, source.length)))
}
return result
}
private fun createTextSources(
originalFullString: String,
entities: RawMessageEntities
): TextSourcesList {
val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } }
val resultList = mutableListOf<TextSource>()
while (mutableEntities.isNotEmpty()) {
var parent = mutableEntities.removeFirst()
val subentities = mutableListOf<RawMessageEntity>()
val toAddCutted = mutableListOf<RawMessageEntity>()
while (mutableEntities.isNotEmpty()) {
val potentialParent = mutableEntities.first()
when {
potentialParent.range.first > parent.range.last -> break
potentialParent.range in parent.range -> {
subentities.add(potentialParent)
}
potentialParent.offset == parent.offset && potentialParent.length > parent.length -> {
subentities.add(parent)
parent = potentialParent
}
else -> { // need to cut
toAddCutted.add(potentialParent)
}
}
mutableEntities.remove(potentialParent)
}
val subtextSources = if (subentities.isNotEmpty()) {
mutableEntities.removeAll(subentities)
if (toAddCutted.isNotEmpty()) {
val borderIndex = parent.range.last + 1
mutableEntities.addAll(
0,
toAddCutted.map {
val firstLength = borderIndex - it.offset
subentities.add(it.copy(length = firstLength))
it.copy(
offset = borderIndex,
length = it.length - firstLength
)
}
)
}
createTextSources(originalFullString, subentities)
} else {
emptyList()
}
resultList.add(
parent.asTextSource(
originalFullString,
createTextPart(originalFullString, subEntities)
subtextSources
)
)
}
@ -86,60 +138,54 @@ internal fun createTextPart(originalFullString: String, entities: RawMessageEnti
return resultList
}
internal fun TextPart.asRawMessageEntities(): List<RawMessageEntity> {
internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEntity> {
val source = source
val length = range.last - range.first + 1
val length = source.length
return listOfNotNull(
when (source) {
is MentionTextSource -> RawMessageEntity("mention", range.first, length)
is HashTagTextSource -> RawMessageEntity("hashtag", range.first, length)
is CashTagTextSource -> RawMessageEntity("cashtag", range.first, length)
is BotCommandTextSource -> RawMessageEntity("bot_command", range.first, length)
is URLTextSource -> RawMessageEntity("url", range.first, length)
is EMailTextSource -> RawMessageEntity("email", range.first, length)
is PhoneNumberTextSource -> RawMessageEntity("phone_number", range.first, length)
is BoldTextSource -> RawMessageEntity("bold", range.first, length)
is ItalicTextSource -> RawMessageEntity("italic", range.first, length)
is CodeTextSource -> RawMessageEntity("code", range.first, length)
is PreTextSource -> RawMessageEntity("pre", range.first, length, language = source.language)
is TextLinkTextSource -> RawMessageEntity("text_link", range.first, length, source.url)
is TextMentionTextSource -> RawMessageEntity("text_mention", range.first, length, user = source.user)
is UnderlineTextSource -> RawMessageEntity("underline", range.first, length)
is StrikethroughTextSource -> RawMessageEntity("strikethrough", range.first, length)
when (this) {
is MentionTextSource -> RawMessageEntity("mention", offset, length)
is HashTagTextSource -> RawMessageEntity("hashtag", offset, length)
is CashTagTextSource -> RawMessageEntity("cashtag", offset, length)
is BotCommandTextSource -> RawMessageEntity("bot_command", offset, length)
is URLTextSource -> RawMessageEntity("url", offset, length)
is EMailTextSource -> RawMessageEntity("email", offset, length)
is PhoneNumberTextSource -> RawMessageEntity("phone_number", offset, length)
is BoldTextSource -> RawMessageEntity("bold", offset, length)
is ItalicTextSource -> RawMessageEntity("italic", offset, length)
is CodeTextSource -> RawMessageEntity("code", offset, length)
is PreTextSource -> RawMessageEntity("pre", offset, length, language = language)
is TextLinkTextSource -> RawMessageEntity("text_link", offset, length, url)
is TextMentionTextSource -> RawMessageEntity("text_mention", offset, length, user = user)
is UnderlineTextSource -> RawMessageEntity("underline", offset, length)
is StrikethroughTextSource -> RawMessageEntity("strikethrough", offset, length)
else -> null
}
) + if (source is MultilevelTextSource) {
source.textParts(range.first).asRawMessageEntities()
) + if (this is MultilevelTextSource) {
subsources.toRawMessageEntities(offset)
} else {
emptyList()
}
}
internal fun List<TextPart>.asRawMessageEntities(): List<RawMessageEntity> = flatMap { it.asRawMessageEntities() }
internal fun List<TextSource>.toTextParts(preOffset: Int = 0): List<TextPart> {
internal fun TextSourcesList.toRawMessageEntities(preOffset: Int = 0): List<RawMessageEntity> {
var i = preOffset
return map {
TextPart(
i until (i + it.source.length),
it
).also {
i = it.range.last + 1
return flatMap { textSource ->
textSource.toRawMessageEntities(i).also {
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)
} else {
this
}
internal fun List<TextSource>.toRawMessageEntities(): List<RawMessageEntity> = toTextParts().asRawMessageEntities()
internal fun TextSourcesList.toRawMessageEntities(): List<RawMessageEntity> = toRawMessageEntities(0)
internal fun RawMessageEntities.asTextParts(sourceString: String): List<TextPart> = sourceString.fullListOfSubSource(
createTextPart(sourceString, this)
)
internal fun RawMessageEntities.asTextSources(sourceString: String): TextSourcesList =
createTextSources(sourceString, this).fillWithRegulars(sourceString)
internal typealias RawMessageEntities = List<RawMessageEntity>

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