1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

Merge pull request #257 from InsanusMokrassar/0.31.0

0.31.0
This commit is contained in:
InsanusMokrassar 2021-01-10 13:08:00 +06:00 committed by GitHub
commit d1993842c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
87 changed files with 208 additions and 579 deletions

View File

@ -1,5 +1,19 @@
# TelegramBotAPI changelog
## 0.31.0
**THIS UPDATE CONTAINS BREAKING CHANGES**
* `Common`:
* **ALL DEPRECATIONS CREATED SINCE 0.30.0 WERE REMOVED**
* `Behaviour Builder`:
* Extension `TelegramBot#buildBehaviour` have changed its return value: now it is `Job` instead of
`FlowsUpdatesFilter`
* `Utils`
* New extensions `TelegramBot#longPolling` were added as new recommended way to start getting updates via long
polling
* Old extensions `RequestsExecutor#startGettingFlowsUpdatesByLongPolling` has been deprecated
## 0.30.13
* `Common`:

View File

@ -17,6 +17,6 @@ micro_utils_version=0.4.16
javax_activation_version=1.1.1
library_group=dev.inmo
library_version=0.30.13
library_version=0.31.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.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
interface Captioned {
val caption: String?
@ -13,8 +12,7 @@ interface CaptionedOutput : Captioned {
interface CaptionedInput : Captioned {
/**
* Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
* @see [CaptionedInput.fullEntitiesList]
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
val captionEntities: List<TextPart>
}
@ -25,10 +23,3 @@ interface CaptionedInput : Captioned {
*/
val CaptionedInput.textSources
get() = captionEntities.justTextSources()
/**
* Convert its [CaptionedInput.captionEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Currently list of entities already full. This method is redundant")
fun CaptionedInput.fullEntitiesList(): TextSourcesList = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
interface Explained {
val explanation: String?
@ -19,8 +18,7 @@ interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput
interface ExplainedInput : Explained {
/**
* Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
* @see [ExplainedInput.fullEntitiesList]
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
val explanationEntities: List<TextPart>
}
@ -31,10 +29,3 @@ interface ExplainedInput : Explained {
*/
val ExplainedInput.textSources
get() = explanationEntities.justTextSources()
/**
* Convert its [ExplainedInput.explanationEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Currently list of entities already full. This method is redundant")
fun ExplainedInput.fullEntitiesList(): TextSourcesList = explanation ?.fullListOfSubSource(explanationEntities) ?.map { it.source } ?: emptyList()

View File

@ -8,10 +8,6 @@ import dev.inmo.tgbotapi.types.textLength
const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods"
typealias TextSourcesList = List<TextSource>
@Deprecated("All lists of TextSource in public API now are full. So, this typealias is redundant")
typealias FullTextSourcesList = List<TextSource>
@Deprecated("All lists of TextPart in public API now are full. So, this typealias is redundant")
typealias FullTextPartsList = List<TextPart>
interface TextSource {
val markdown: String
@ -21,16 +17,6 @@ interface TextSource {
val asText: String
get() = source
@Deprecated("Rename", ReplaceWith("markdown"))
val asMarkdownSource: String
get() = markdown
@Deprecated("Rename", ReplaceWith("markdownV2"))
val asMarkdownV2Source: String
get() = markdownV2
@Deprecated("Rename", ReplaceWith("html"))
val asHtmlSource: String
get() = html
}
@Suppress("NOTHING_TO_INLINE")
@ -43,13 +29,7 @@ inline operator fun TextSource.plus(text: String) = listOf(this, regular(text))
inline operator fun List<TextSource>.plus(text: String) = this + regular(text)
interface MultilevelTextSource : TextSource {
@Deprecated("Will be removed in near major release")
val textParts: List<TextPart>
get() = textParts(0)
val subsources: List<TextSource>
@Deprecated("Will be removed in near major release", ReplaceWith("subsources"))
val textSources: List<TextSource>
get() = subsources
}
data class TextPart(

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
interface Texted {
val text: String?
@ -22,7 +21,6 @@ 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
* @see [CaptionedInput.fullEntitiesList]
*/
val textEntities: List<TextPart>
}
@ -35,10 +33,3 @@ interface TextedInput : Texted {
*/
val TextedInput.textSources
get() = textEntities.justTextSources()
/**
* Convert its [TextedInput.textEntities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Currently list of entities already full. This method is redundant")
fun TextedInput.fullEntitiesList(): TextSourcesList = text ?.fullListOfSubSource(textEntities) ?.map { it.source } ?: emptyList()

View File

@ -5,7 +5,8 @@ import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
import dev.inmo.tgbotapi.bot.Ktor.base.*
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
import dev.inmo.tgbotapi.bot.settings.limiters.*
import dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter
import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.Response
import dev.inmo.tgbotapi.utils.*
@ -67,7 +68,7 @@ class KtorRequestsExecutor(
return safely(
{ e ->
throw if (e is ClientRequestException) {
val content = e.response ?.readText() ?: throw e
val content = e.response.readText()
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
newRequestException(
responseObject,

View File

@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.bot.exceptions.newRequestException
import dev.inmo.tgbotapi.requests.GetUpdates
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.Response
import dev.inmo.tgbotapi.types.RetryAfterError
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient
import io.ktor.client.call.receive
@ -14,7 +13,6 @@ import io.ktor.client.features.timeout
import io.ktor.client.request.*
import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import kotlinx.coroutines.delay
import kotlinx.serialization.json.Json
import kotlin.collections.set

View File

@ -25,10 +25,9 @@ object MultipartRequestCallFactory : AbstractRequestCallFactory() {
Headers.build {
append(HttpHeaders.ContentType, value.mimeType)
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
}
) {
value.file.asInput()
}
},
block = value.file::input
)
is FileId -> append(key, value.fileId)
else -> append(key, value.toString())
}

View File

@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.bot.exceptions
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.Response
import dev.inmo.tgbotapi.types.RetryAfterError
import io.ktor.utils.io.errors.IOException
fun newRequestException(

View File

@ -1,15 +1,11 @@
package dev.inmo.tgbotapi.bot.settings.limiters
import com.soywiz.klock.DateTime
import dev.inmo.micro_utils.coroutines.*
import dev.inmo.tgbotapi.types.MilliSeconds
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.sync.Semaphore
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlin.coroutines.Continuation
import kotlin.math.roundToLong
private fun now(): Long = DateTime.nowUnixLong()

View File

@ -2,11 +2,13 @@ package dev.inmo.tgbotapi.bot.settings.limiters
import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.tgbotapi.bot.exceptions.TooMuchRequestsException
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MilliSeconds
import dev.inmo.tgbotapi.types.RetryAfterError
import io.ktor.client.features.ClientRequestException
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
/**
* This limiter will limit requests only after getting a [RetryAfterError] or [ClientRequestException] with
@ -60,6 +62,3 @@ class ExceptionsOnlyLimiter(
}
}
}
@Deprecated("Renamed", ReplaceWith("ExceptionsOnlyLimiter", "dev.inmo.tgbotapi.bot.settings.limiters.ExceptionsOnlyLimiter"))
typealias EmptyLimiter = ExceptionsOnlyLimiter

View File

@ -1,9 +1,9 @@
package dev.inmo.tgbotapi.bot.settings.limiters
import dev.inmo.micro_utils.coroutines.*
import dev.inmo.micro_utils.coroutines.actor
import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.tgbotapi.types.MilliSeconds
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlin.coroutines.*

View File

@ -2,10 +2,7 @@ package dev.inmo.tgbotapi.requests.chat.modify
import dev.inmo.tgbotapi.CommonAbstracts.types.ChatRequest
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chatIdField
import dev.inmo.tgbotapi.types.messageIdField
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer

View File

@ -9,8 +9,6 @@ import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import kotlinx.serialization.*
fun CopyMessage(

View File

@ -87,7 +87,7 @@ fun Poll.createRequest(
correctOptionId,
isAnonymous,
isClosed,
fullEntitiesList(),
textSources,
scheduledCloseInfo,
disableNotification,
replyToMessageId,

View File

@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.requests.webhook
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.*
import dev.inmo.tgbotapi.requests.send.media.base.DataRequest
import dev.inmo.tgbotapi.requests.send.media.base.MultipartRequestImpl
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer

View File

@ -62,12 +62,6 @@ val inlineQueryAnswerResultsLimit = 0 .. 50
val customTitleLength = 0 .. 16
val dartsCubeAndBowlingDiceResultLimit = 1 .. 6
@Deprecated("Renamed", ReplaceWith("dartsCubeAndBowlingDiceResultLimit", "dev.inmo.tgbotapi.types.dartsCubeAndBowlingDiceResultLimit"))
val dartsAndCubeDiceResultLimit
get() = dartsCubeAndBowlingDiceResultLimit
@Deprecated("Renamed", ReplaceWith("dartsCubeAndBowlingDiceResultLimit", "dev.inmo.tgbotapi.types.dartsCubeAndBowlingDiceResultLimit"))
val diceResultLimit
get() = dartsCubeAndBowlingDiceResultLimit
val basketballAndFootballDiceResultLimit = 1 .. 5
val slotMachineDiceResultLimit = 1 .. 64

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.WithInputMessageContentInlineQueryResult
@ -8,10 +7,5 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.WithInp
const val inlineQueryResultAudioType = "audio"
interface InlineQueryResultAudioCommon : InlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@ -9,10 +8,5 @@ const val inlineQueryResultDocumentType = "document"
interface InlineQueryResultDocumentCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@ -8,10 +7,5 @@ const val inlineQueryResultGifType = "gif"
interface InlineQueryResultGifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@ -8,10 +7,5 @@ const val inlineQueryResultMpeg4GifType = "mpeg4_gif"
interface InlineQueryResultMpeg4GifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@ -9,10 +8,5 @@ const val inlineQueryResultPhotoType = "photo"
interface InlineQueryResultPhotoCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
@ -9,10 +8,5 @@ const val inlineQueryResultVideoType = "video"
interface InlineQueryResultVideoCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
WithInputMessageContentInlineQueryResult

View File

@ -1,17 +1,11 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultVoiceType = "voice"
interface InlineQueryResultVoiceCommon : InlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult,
TitledInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}
TitledInlineQueryResult

View File

@ -37,10 +37,7 @@ data class InputTextMessageContent internal constructor(
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(disableWebPagePreviewField)
override val disableWebPagePreview: Boolean? = null
) : CaptionedOutput, TextedOutput, DisableWebPagePreview, InputMessageContent {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
) : TextedOutput, DisableWebPagePreview, InputMessageContent {
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text) ?.justTextSources()
}

View File

@ -3,9 +3,6 @@ package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import kotlinx.serialization.Serializable
@Deprecated("Will be removed due to redundancy for end-side users")
fun String.toInputMediaFileAttachmentName() = "attach://$this"
@Serializable(InputMediaSerializer::class)
interface InputMedia {
val type: String

View File

@ -42,16 +42,12 @@ data class InputMediaAnimation internal constructor(
override val height: Int? = null,
override val duration: Long? = null,
override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput, CaptionedOutput {
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput {
override val type: String = "animation"
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
}
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
@SerialName(mediaField)
override val media: String
init { media = file.fileIdToSend } // crutch until js compiling will be fixed

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.InputMedia
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import kotlinx.serialization.*
import kotlinx.serialization.json.Json
@ -16,10 +15,7 @@ internal fun <T> T.buildArguments(withSerializer: SerializationStrategy<T>) = ar
)
@Serializable(MediaGroupMemberInputMediaSerializer::class)
interface MediaGroupMemberInputMedia : InputMedia, CaptionedOutput, TextedOutput {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
interface MediaGroupMemberInputMedia : InputMedia, TextedOutput {
fun serialize(format: StringFormat): String
}

View File

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

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.boldMarkdown
import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2
/**
* @see bold

View File

@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.commandMarkdown
import dev.inmo.tgbotapi.utils.internal.commandMarkdownV2
private val commandRegex = Regex("[/!][^@\\s]*")

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.cashTagMarkdown
import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2
/**
* @see cashTag

View File

@ -2,10 +2,8 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.codeMarkdown
import dev.inmo.tgbotapi.utils.internal.codeMarkdownV2
/**
* @see code

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.emailMarkdown
import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2
/**
* @see email

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.hashTagMarkdown
import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2
/**
* @see hashtag

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.italicMarkdown
import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2
/**
* @see italic

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.mentionMarkdown
import dev.inmo.tgbotapi.utils.internal.mentionMarkdownV2
private val String.withoutCommercialAt
get() = if (startsWith("@")) {

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.phoneMarkdown
import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2
/**
* @see phone

View File

@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.preMarkdown
import dev.inmo.tgbotapi.utils.internal.preMarkdownV2
/**
* @see pre

View File

@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.regularMarkdown
import dev.inmo.tgbotapi.utils.internal.regularMarkdownV2
/**
* @see regular

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdown
import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2
/**
* @see strikethrough

View File

@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.linkMarkdown
import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2
/**
* @see link

View File

@ -2,10 +2,8 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.textMentionMarkdown
import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2
/**
* @see mention

View File

@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.linkMarkdown
import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2
/**
* @see link

View File

@ -1,10 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.utils.*
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.underlineMarkdown
import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2
/**
* @see underline

View File

@ -1,6 +1,5 @@
package dev.inmo.tgbotapi.types.chat.abstracts
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer
import kotlinx.serialization.Serializable

View File

@ -4,7 +4,6 @@ import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
data class ChannelEventMessage<T : ChannelEvent>(

View File

@ -20,6 +20,3 @@ data class ChannelMessageImpl<T: MessageContent>(
override val senderBot: CommonBot?,
override val authorSignature: AuthorSignature?
) : ChannelMessage<T>
@Deprecated("Renamed", ReplaceWith("ChannelMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelMessageImpl"))
typealias ChannelMessage<T> = ChannelMessageImpl<T>

View File

@ -7,9 +7,6 @@ import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage
@Deprecated("Renamed", ReplaceWith("CommonGroupEventMessage"))
typealias GroupEventMessage = CommonGroupEventMessage<*>
data class CommonGroupEventMessage<T : GroupEvent>(
override val messageId: MessageIdentifier,
override val user: User,

View File

@ -4,13 +4,9 @@ import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent
import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage
@Deprecated("Renamed", ReplaceWith("CommonSupergroupEventMessage"))
typealias SupergroupEventMessage = CommonSupergroupEventMessage<*>
data class CommonSupergroupEventMessage<T : SupergroupEvent>(
override val messageId: MessageIdentifier,
override val user: User,

View File

@ -22,6 +22,3 @@ data class PrivateMessageImpl<T: MessageContent>(
override val senderBot: CommonBot?,
val paymentInfo: SuccessfulPaymentInfo?
) : PrivateMessage<T>
@Deprecated("Renamed", ReplaceWith("PrivateMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateMessageImpl"))
typealias CommonMessageImpl<T> = PrivateMessageImpl<T>

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
import dev.inmo.tgbotapi.CommonAbstracts.TextedInput
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.SendTextMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
@ -10,17 +11,11 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.utils.internal.*
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
import dev.inmo.tgbotapi.utils.internal.toMarkdownTexts
data class TextContent(
override val text: String,
override val textEntities: List<TextPart> = emptyList()
) : MessageContent, TextedInput {
@Deprecated("Has been renamed", ReplaceWith("textEntities"))
val entities: List<TextPart>
get() = textEntities
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
@ -77,10 +72,3 @@ data class TextContent(
)
}
}
/**
* Convert its [TextContent.entities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource]
* with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/
@Deprecated("Useless due to the fact that currently every message contains full list of sources")
fun TextContent.fullEntitiesList(): TextSourcesList = text.fullListOfSubSource(entities).map { it.source }

View File

@ -18,6 +18,7 @@ package dev.inmo.tgbotapi.utils
)
annotation class PreviewFeature
const val lowLevelRiskFeatureMessage = "This method is low-level and not recommended to direct use"
@RequiresOptIn(
"This feature can work unstable and may have some restrictions in Telegram System",
RequiresOptIn.Level.WARNING

View File

@ -1,21 +0,0 @@
package dev.inmo.tgbotapi.utils
import dev.inmo.micro_utils.coroutines.ExceptionHandler
import dev.inmo.micro_utils.coroutines.safely
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.supervisorScope
@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("ExceptionHandler", "dev.inmo.micro_utils.coroutines.ExceptionHandler"))
typealias ExceptionHandler<T> = ExceptionHandler<T>
/**
* It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions
*
* @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this
* exception will be available for catching
*/
@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely"))
suspend inline fun <T> handleSafely(
noinline onException: ExceptionHandler<T> = { throw it },
noinline block: suspend CoroutineScope.() -> T
): T = safely(onException, block)

View File

@ -5,19 +5,40 @@ import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.Input
import kotlinx.serialization.Serializable
/**
* Information about file for [StorageFile]
*
* @param contentType Raw type like "application/json"
* @param fileName This filename will be used in telegram system as name of file
*/
@Serializable
data class StorageFileInfo(
val contentType: String,
val fileName: String
) {
/**
* This methods is required for random generation of name for keeping warranties about unique file name
*/
fun generateCustomName() = "${uuid4()}.${fileName.fileExtension}"
}
/**
* Contains info about file, which potentially can be sent to telegram system.
*
* @param storageFileInfo Information about this file
* @param inputSource Lambda which able to allocate [Input] for uploading/manipulating data
*
* @see StorageFileInfo
* @see asStorageFile
*/
data class StorageFile(
val storageFileInfo: StorageFileInfo,
private val inputSource: () -> Input
) {
fun asInput() = inputSource()
val input: Input
get() = inputSource()
@Deprecated("This method will be fully replaced with input property", ReplaceWith("input"))
fun asInput() = input
}
@Suppress("NOTHING_TO_INLINE")
@ -31,5 +52,8 @@ inline fun StorageFile(
ByteReadPacket(bytes)
}
@Suppress("NOTHING_TO_INLINE")
/**
*
*/
@Suppress("NOTHING_TO_INLINE", "unused")
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)

View File

@ -1,55 +0,0 @@
package dev.inmo.tgbotapi.utils.internal
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.update.*
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
private inline val Pair<MediaGroupMessage, *>.message
get() = first
internal fun List<BaseMessageUpdate>.convertWithMediaGroupUpdates(): List<Update> {
val resultUpdates = mutableListOf<Update>()
val mediaGroups = mutableMapOf<MediaGroupIdentifier, MutableList<BaseMessageUpdate>>()
for (update in this) {
val asEditMediaGroupMessage = update.toEditMediaGroupUpdate()
if (asEditMediaGroupMessage != null) {
resultUpdates.add(asEditMediaGroupMessage)
} else {
val data = update.data
if (data is MediaGroupMessage) {
(mediaGroups[data.mediaGroupId] ?: mutableListOf<BaseMessageUpdate>().also { mediaGroups[data.mediaGroupId] = it }).add(update)
} else {
resultUpdates.add(update)
}
}
}
mediaGroups.values.map {
it.toSentMediaGroupUpdate() ?.let { mediaGroupUpdate ->
resultUpdates.add(mediaGroupUpdate)
}
}
return resultUpdates.sortedBy { it.updateId }
}
internal fun List<BaseMessageUpdate>.toSentMediaGroupUpdate(): SentMediaGroupUpdate? = (this as? SentMediaGroupUpdate) ?: let {
if (isEmpty()) {
return@let null
}
val resultList = sortedBy { it.updateId }
when (first()) {
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
else -> null
}
}
internal fun BaseMessageUpdate.toEditMediaGroupUpdate(): EditMediaGroupUpdate? = (this as? EditMediaGroupUpdate) ?: let {
when (this) {
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
else -> null
}
}

View File

@ -4,7 +4,6 @@ import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ParseMode.*
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.fullEntitiesList
internal fun createFormattedText(
entities: TextSourcesList,
@ -56,13 +55,7 @@ internal fun TextSourcesList.toMarkdownTexts(): List<String> = createMarkdownTex
this,
textLength.last
)
internal fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
internal fun TextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
this,
explanationLimit.last
)
internal fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
internal fun TextContent.toMarkdownTexts(): List<String> = textSources.toMarkdownTexts()
internal fun createMarkdownV2Text(
@ -74,19 +67,13 @@ internal fun TextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdo
this,
captionLength.last
)
internal fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toMarkdownV2Captions()
internal fun CaptionedInput.toMarkdownV2Captions(): List<String> = textSources.toMarkdownV2Captions()
internal fun TextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
this,
textLength.last
)
internal fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
internal fun TextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
this,
explanationLimit.last
)
internal fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
internal fun TextContent.toMarkdownV2Texts(): List<String> = textSources.toMarkdownV2Texts()
internal fun createHtmlText(
@ -98,12 +85,12 @@ internal fun TextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
this,
captionLength.last
)
internal fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCaptions()
internal fun CaptionedInput.toHtmlCaptions(): List<String> = textSources.toHtmlCaptions()
internal fun TextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
this,
textLength.last
)
internal fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
internal fun TextContent.toHtmlTexts(): List<String> = textSources.toHtmlTexts()

View File

@ -148,8 +148,3 @@ internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") +
internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml()
internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + subsources.joinSubSourcesHtml()

View File

@ -99,12 +99,10 @@ private inline fun String.hashTag(adapt: String.() -> String): String = if (star
}
internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
internal fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
internal fun String.mentionMarkdown(): String = mention(String::toMarkdown)
internal fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
internal fun String.hashTagHTML(): String = hashTag(String::toHtml)
internal fun String.phoneMarkdown(): String = toMarkdown()
@ -136,14 +134,6 @@ internal infix fun Pair<String, String>.link(parseMode: ParseMode): String = whe
is MarkdownV2 -> first.linkMarkdownV2(second)
}
internal infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
is HTML -> commandHTML()
is Markdown -> commandMarkdown()
is MarkdownV2 -> commandMarkdownV2()
}
internal infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
is HTML -> underlineHTML()
is Markdown -> underlineMarkdown()

View File

@ -1,8 +1,8 @@
package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.CommonAbstracts.plus
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.utils.internal.*
import kotlin.test.Test
import kotlin.test.assertEquals

View File

@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.CommonAbstracts.justTextSources
import dev.inmo.tgbotapi.utils.internal.toHtmlTexts
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Texts
import kotlin.test.*
import kotlin.test.Test
import kotlin.test.assertEquals
class TextPartsCreatingTests {
@Test

View File

@ -1,9 +1,7 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.tgbotapi.utils.MimeType
import dev.inmo.tgbotapi.utils.StorageFile
import java.io.File
import java.io.InputStream
fun File.toInputFile() = if (exists()) {
MultipartFile(

View File

@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.utils
import io.ktor.utils.io.streams.asInput
import java.io.File
import java.io.InputStream
import java.nio.file.Files
fun StorageFile(

View File

@ -45,17 +45,3 @@ fun buildBot(
TelegramAPIUrlsKeeper(token, apiUrl),
BotBuilder().apply(block).createHttpClient()
)
/**
* @return Created by [telegramBotWithCustomClientConfig] function [TelegramBot]. This executor will be preconfigured using [token] and
* [block]
*/
@Deprecated("Renamed", ReplaceWith("buildBot", "dev.inmo.tgbotapi.extensions.api.buildBot"))
fun telegramBot(
token: String,
block: BotBuilder.() -> Unit
): TelegramBot = buildBot(
token,
telegramBotAPIDefaultUrl,
block
)

View File

@ -1,6 +1,6 @@
package dev.inmo.tgbotapi.extensions.api
import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
@ -8,23 +8,13 @@ import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.*
/**
* Allows to create bot using bot [urlsKeeper]
*/
@Deprecated("Replaced in core", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.bot.Ktor.telegramBot"))
fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper
): TelegramBot = dev.inmo.tgbotapi.bot.Ktor.telegramBot(
urlsKeeper
)
/**
* Allows to create bot using bot [urlsKeeper] and already prepared [client]
*/
fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper,
client: HttpClient
): TelegramBot = dev.inmo.tgbotapi.bot.Ktor.telegramBot(urlsKeeper) {
): TelegramBot = telegramBot(urlsKeeper) {
this.client = client
}
@ -69,16 +59,6 @@ inline fun telegramBot(
HttpClient(clientConfig)
)
/**
* Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client]
*/
@Deprecated("Replaced in core", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.bot.Ktor.telegramBot"))
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
token: String,
apiUrl: String = telegramBotAPIDefaultUrl
): TelegramBot = dev.inmo.tgbotapi.bot.Ktor.telegramBot(token, apiUrl)
/**
* Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client]
*/
@ -130,37 +110,3 @@ inline fun telegramBot(
TelegramAPIUrlsKeeper(token, apiUrl),
clientConfig
)
/**
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
* configure [HttpClient] using [clientConfig]
*/
@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
fun telegramBotWithCustomClientConfig(
urlsKeeper: TelegramAPIUrlsKeeper,
clientEngine: HttpClientEngine,
clientConfig: HttpClientConfig<*>.() -> Unit
): TelegramBot = telegramBot(
urlsKeeper,
HttpClient(clientEngine, clientConfig)
)
/**
* Allows to create bot using bot [urlsKeeper] and optionally configure [HttpClient] using [clientConfig]
*/
@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
fun telegramBotWithCustomClientConfig(
urlsKeeper: TelegramAPIUrlsKeeper,
clientConfig: HttpClientConfig<*>.() -> Unit
): TelegramBot = telegramBot(
urlsKeeper,
HttpClient(clientConfig)
)
@Suppress("NOTHING_TO_INLINE")
@Deprecated("Renamed", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
inline fun telegramBotWithCustomClientConfig(
token: String,
apiUrl: String = telegramBotAPIDefaultUrl,
noinline clientConfig: HttpClientConfig<*>.() -> Unit
) = telegramBot(token, apiUrl = apiUrl, clientConfig = clientConfig)

View File

@ -5,7 +5,6 @@ import dev.inmo.tgbotapi.requests.chat.modify.UnpinChatMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.message.abstracts.Message
suspend fun TelegramBot.unpinChatMessage(

View File

@ -2,12 +2,7 @@ package dev.inmo.tgbotapi.extensions.api.send
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.send.SendVenue
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.FoursquareId
import dev.inmo.tgbotapi.types.FoursquareType
import dev.inmo.tgbotapi.types.GooglePlaceId
import dev.inmo.tgbotapi.types.GooglePlaceType
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.location.StaticLocation

View File

@ -1,10 +1,22 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.PreviewFeature
import kotlinx.coroutines.CoroutineScope
/**
* Use this method in case you wish to make some additional actions with [flowUpdatesFilter].
*
* **WARNING** This method WILL NOT launch any listening of updates. Use something like
* [startGettingOfUpdatesByLongPolling] or tools for work with webhooks
*
* @see [BehaviourContext]
* @see startGettingOfUpdatesByLongPolling
*/
@PreviewFeature
suspend fun TelegramBot.buildBehaviour(
scope: CoroutineScope,
flowUpdatesFilter: FlowsUpdatesFilter,
@ -17,17 +29,26 @@ suspend fun TelegramBot.buildBehaviour(
).block()
}
/**
* Use this method to build bot behaviour and run it via long polling. In case you wish to get [FlowsUpdatesFilter] for
* additional manipulations, you must provide external [FlowsUpdatesFilter] in other [buildBehaviour] function.
*
* @see buildBehaviour
* @see BehaviourContext
* @see startGettingOfUpdatesByLongPolling
*/
@PreviewFeature
suspend fun TelegramBot.buildBehaviour(
scope: CoroutineScope,
block: BehaviourContextReceiver<Unit>
) = FlowsUpdatesFilter().also {
) = FlowsUpdatesFilter().let {
buildBehaviour(
scope,
it,
block
)
startGettingOfUpdatesByLongPolling(
updatesFilter = it,
longPolling(
it,
scope = scope
)
}

View File

@ -8,6 +8,13 @@ import kotlinx.coroutines.CoroutineScope
typealias BehaviourContextReceiver<T> = suspend BehaviourContext.() -> T
typealias BehaviourContextAndTypeReceiver<T, I> = suspend BehaviourContext.(I) -> T
/**
* This class contains all necessary tools for work with bots and especially for [buildBehaviour]
*
* @param scope This param will be used for creating of some subscriptions inside of methods, updates listening and
* different other things in context of working with [CoroutineScope] and coroutines.
* @param flowsUpdatesFilter This parameter will be used to subscribe on different types of update
*/
data class BehaviourContext(
val bot: TelegramBot,
val scope: CoroutineScope,

View File

@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.*
@ -26,7 +27,7 @@ typealias NullableRequestBuilder<T> = suspend (Update) -> Request<T>?
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
* will be called too), [errorFactory] and then will be returned null
*/
@RiskFeature("This method is not very comfortable to use and too low-level. It is recommended to use methods which already included into library")
@RiskFeature(lowLevelRiskFeatureMessage)
suspend fun <T> FlowsUpdatesFilter.expectFlow(
bot: TelegramBot,
initRequest: Request<*>? = null,
@ -92,7 +93,7 @@ suspend fun <T> BehaviourContext.expectFlow(
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
* will be called too), [errorFactory] and then will be returned null
*/
@RiskFeature("This method is not very comfortable to use and too low-level. It is recommended to use methods which already included into library")
@RiskFeature(lowLevelRiskFeatureMessage)
suspend fun <T> FlowsUpdatesFilter.expectOne(
bot: TelegramBot,
initRequest: Request<*>? = null,

View File

@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.content.abstracts.*
import dev.inmo.tgbotapi.types.message.content.media.*

View File

@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.*

View File

@ -10,9 +10,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.content.ContactContent
import dev.inmo.tgbotapi.types.message.content.abstracts.*
import dev.inmo.tgbotapi.types.message.content.media.PhotoContent
import dev.inmo.tgbotapi.types.message.content.media.VideoContent

View File

@ -1,6 +1,8 @@
@file:Suppress("NOTHING_TO_INLINE", "unused", "UNCHECKED_CAST")
package dev.inmo.tgbotapi.extensions.utils
import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.CallbackQuery.*
import dev.inmo.tgbotapi.types.ChatMember.*
@ -20,6 +22,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery
import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery
import dev.inmo.tgbotapi.types.InputMedia.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import dev.inmo.tgbotapi.types.actions.*
import dev.inmo.tgbotapi.types.buttons.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
@ -30,58 +33,15 @@ import dev.inmo.tgbotapi.types.files.abstracts.*
import dev.inmo.tgbotapi.types.message.*
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage
import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage
import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.content.abstracts.*
import dev.inmo.tgbotapi.types.message.content.media.*
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.types.polls.*
import dev.inmo.tgbotapi.types.update.*
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
import dev.inmo.tgbotapi.types.update.abstracts.*
import dev.inmo.tgbotapi.utils.PreviewFeature
import dev.inmo.tgbotapi.types.message.content.abstracts.ResendableContent
import dev.inmo.tgbotapi.types.message.content.ContactContent
import dev.inmo.tgbotapi.types.message.content.DiceContent
import dev.inmo.tgbotapi.types.message.content.GameContent
import dev.inmo.tgbotapi.types.message.content.LocationContent
import dev.inmo.tgbotapi.types.message.content.PollContent
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.VenueContent
import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.media.AnimationContent
import dev.inmo.tgbotapi.types.message.content.media.AudioContent
import dev.inmo.tgbotapi.types.message.content.media.DocumentContent
import dev.inmo.tgbotapi.types.message.content.media.PhotoContent
import dev.inmo.tgbotapi.types.message.content.media.StickerContent
import dev.inmo.tgbotapi.types.message.content.media.VideoContent
import dev.inmo.tgbotapi.types.message.content.media.VideoNoteContent
import dev.inmo.tgbotapi.types.message.content.media.VoiceContent
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.BoldTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.CashTagTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.CodeTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.EMailTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.HashTagTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.ItalicTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.MentionTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.PhoneNumberTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.PreTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.StrikethroughTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextLinkTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextMentionTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.URLTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.UnderlineTextSource
@PreviewFeature
inline fun Chat.asBot(): Bot? = this as? Bot

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.extensions.utils
import dev.inmo.micro_utils.coroutines.safely
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.flow.*

View File

@ -1,17 +0,0 @@
package dev.inmo.tgbotapi.extensions.utils
import dev.inmo.micro_utils.coroutines.ExceptionHandler
import dev.inmo.tgbotapi.utils.*
import kotlinx.coroutines.CoroutineScope
/**
* Shortcut for [dev.inmo.micro_utils.coroutines.safely]. It was created for more comfortable way of handling different things
*/
@Deprecated("In future will be used typealias from micro_utils", ReplaceWith("safely", "dev.inmo.micro_utils.coroutines.safely"))
suspend inline fun <T> safely(
noinline onException: ExceptionHandler<T> = { throw it },
noinline block: suspend CoroutineScope.() -> T
): T = dev.inmo.micro_utils.coroutines.safely(
onException,
block
)

View File

@ -1,24 +0,0 @@
package dev.inmo.tgbotapi.extensions.utils.chat_events
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
import kotlin.reflect.KClass
@Deprecated("Refactored, replaced and renamed", ReplaceWith("filterByChatEvent", "dev.inmo.tgbotapi.extensions.utils.shortcuts.filterByChatEvent"))
fun <T : ChatEventMessage<*>> Flow<ChatEventMessage<*>>.divideBySource(contentType: KClass<T>) = mapNotNull {
if (contentType.isInstance(it)) {
@Suppress("UNCHECKED_CAST")
it as T
} else {
null
}
}
@Deprecated("Replaced and renamed", ReplaceWith("channelEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.channelEvents"))
fun Flow<ChatEventMessage<*>>.onlyChannelEvents() = channelEvents()
@Deprecated("Replaced and renamed", ReplaceWith("groupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.groupEvents"))
fun Flow<ChatEventMessage<*>>.onlyGroupEvents() = groupEvents()
@Deprecated("Replaced and renamed", ReplaceWith("supergroupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.supergroupEvents"))
fun Flow<ChatEventMessage<*>>.onlySupergroupEvents() = supergroupEvents()

View File

@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.extensions.utils.formatting
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.link
import dev.inmo.tgbotapi.types.ParseMode.*
import dev.inmo.tgbotapi.types.chat.abstracts.*
import dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedPublicChat
import dev.inmo.tgbotapi.types.message.abstracts.Message
@ -84,38 +83,3 @@ private const val stickerSetAddingLinkPrefix = "$internalLinkBeginning/addsticke
val StickerSetName.stickerSetLink
get() = link(this, "$stickerSetAddingLinkPrefix/$this")
/**
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [MarkdownV2]
*/
@Deprecated("Use extension `stickerSetLink` + getting of `asMarkdownV2Source` property")
fun makeLinkToAddStickerSetInMarkdownV2(
stickerSetName: StickerSetName
) = stickerSetName.stickerSetLink.markdownV2
/**
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [Markdown]
*/
@Deprecated("Use extension `stickerSetLink` + getting of `asMarkdownSource` property")
fun makeLinkToAddStickerSetInMarkdown(stickerSetName: StickerSetName) = stickerSetName.stickerSetLink.markdown
/**
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [HTML]
*/
@Deprecated("Use extension `stickerSetLink` + getting of `asHtmlSource` property")
fun makeLinkToAddStickerSetInHtml(stickerSetName: StickerSetName) = stickerSetName.stickerSetLink.html
/**
* Create a link for adding of sticker set with name [stickerSetName]. Was added thanks to user Djaler and based on
* https://github.com/Djaler/evil-bot/blob/master/src/main/kotlin/com/github/djaler/evilbot/utils/StickerUtils.kt#L6-L8
*
* @see [makeLinkToAddStickerSetInMarkdownV2]
* @see [makeLinkToAddStickerSetInMarkdown]
* @see [makeLinkToAddStickerSetInHtml]
*/
@Deprecated("Use extension `stickerSetLink` + getting of required property")
fun makeLinkToAddStickerSet(
stickerSetName: StickerSetName,
parseMode: ParseMode
) = when (parseMode) {
MarkdownParseMode -> makeLinkToAddStickerSetInMarkdown(stickerSetName)
MarkdownV2ParseMode -> makeLinkToAddStickerSetInMarkdownV2(stickerSetName)
HTMLParseMode -> makeLinkToAddStickerSetInHtml(stickerSetName)
}

View File

@ -4,7 +4,6 @@ import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.ParseMode.*
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.fullEntitiesList
fun createFormattedText(
entities: TextSourcesList,
@ -56,19 +55,19 @@ fun TextSourcesList.toMarkdownCaptions(): List<String> = createMarkdownText(
this,
captionLength.last
)
fun CaptionedInput.toMarkdownCaptions(): List<String> = fullEntitiesList().toMarkdownCaptions()
fun CaptionedInput.toMarkdownCaptions(): List<String> = textSources.toMarkdownCaptions()
fun TextSourcesList.toMarkdownTexts(): List<String> = createMarkdownText(
this,
textLength.last
)
fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
fun TextContent.toMarkdownTexts(): List<String> = textSources.toMarkdownTexts()
fun TextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
this,
explanationLimit.last
)
fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
fun ExplainedInput.toMarkdownExplanations(): List<String> = textSources.toMarkdownTexts()
fun createMarkdownV2Text(
@ -80,19 +79,19 @@ fun TextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
this,
captionLength.last
)
fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toMarkdownV2Captions()
fun CaptionedInput.toMarkdownV2Captions(): List<String> = textSources.toMarkdownV2Captions()
fun TextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
this,
textLength.last
)
fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
fun TextContent.toMarkdownV2Texts(): List<String> = textSources.toMarkdownV2Texts()
fun TextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
this,
explanationLimit.last
)
fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
fun ExplainedInput.toMarkdownV2Explanations(): List<String> = textSources.toMarkdownV2Texts()
fun createHtmlText(
@ -104,18 +103,18 @@ fun TextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
this,
captionLength.last
)
fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCaptions()
fun CaptionedInput.toHtmlCaptions(): List<String> = textSources.toHtmlCaptions()
fun TextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
this,
textLength.last
)
fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
fun TextContent.toHtmlTexts(): List<String> = textSources.toHtmlTexts()
fun TextSourcesList.toHtmlExplanations(): List<String> = createHtmlText(
this,
explanationLimit.last
)
fun ExplainedInput.toHtmlExplanations(): List<String> = fullEntitiesList().toHtmlTexts()
fun ExplainedInput.toHtmlExplanations(): List<String> = textSources.toHtmlTexts()

View File

@ -8,7 +8,6 @@ import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.fullEntitiesList
import kotlinx.coroutines.flow.*
/**

View File

@ -9,7 +9,8 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
@RiskFeature("Use with caution")
inline fun FlowsUpdatesFilter.events(): Flow<ChatEventMessage<*>> {

View File

@ -12,9 +12,12 @@ import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.*
@RiskFeature(lowLevelRiskFeatureMessage)
inline fun <reified T : MessageContent> filterForContentMessage(): suspend (ContentMessage<*>) -> ContentMessage<T>? = {
if (it.content is T) {
@Suppress("UNCHECKED_CAST")
@ -25,9 +28,11 @@ inline fun <reified T : MessageContent> filterForContentMessage(): suspend (Cont
}
@Suppress("UNCHECKED_CAST")
@RiskFeature(lowLevelRiskFeatureMessage)
inline fun <reified T: MessageContent> Flow<BaseSentMessageUpdate>.filterContentMessages(
): Flow<ContentMessage<T>> = asContentMessagesFlow().mapNotNull(filterForContentMessage())
@RiskFeature("This method is low-level")
inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.filterMediaGroupMessages(
): Flow<List<CommonMessage<T>>> = map {
it.data.mapNotNull { message ->
@ -46,6 +51,7 @@ inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.filterMedi
* [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping
*/
@Suppress("UNCHECKED_CAST")
@RiskFeature(lowLevelRiskFeatureMessage)
inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
scopeToIncludeChannels: CoroutineScope? = null
): Flow<ContentMessage<T>> {
@ -64,6 +70,7 @@ inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
* [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping
*/
@Suppress("UNCHECKED_CAST")
@RiskFeature(lowLevelRiskFeatureMessage)
inline fun <reified T: MediaGroupContent> FlowsUpdatesFilter.filterMediaGroupMessages(
scopeToIncludeChannels: CoroutineScope? = null
): Flow<List<CommonMessage<T>>> {

View File

@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.fullEntitiesList
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
import kotlinx.coroutines.flow.Flow

View File

@ -1,3 +1,5 @@
@file:Suppress("unused")
package dev.inmo.tgbotapi.extensions.utils.updates
import dev.inmo.tgbotapi.types.message.abstracts.*
@ -23,11 +25,6 @@ fun <T : BaseSentMessageUpdate> Flow<T>.asCommonMessagesFlow() = mapNotNull {
inline fun <T : BaseSentMessageUpdate> Flow<T>.chatEvents() = mapNotNull {
it.data as? ChatEventMessage<*>
}
/**
* Will map incoming [BaseSentMessageUpdate]s to [ChatEventMessage] from [BaseSentMessageUpdate.data]
*/
@Deprecated("Renamed", ReplaceWith("chatEvents", "dev.inmo.tgbotapi.extensions.utils.updates.chatEvents"))
fun <T : BaseSentMessageUpdate> Flow<T>.asChatEventsFlow() = chatEvents()
/**
* Will map incoming [BaseSentMessageUpdate]s to [UnknownMessageType] from [BaseSentMessageUpdate.data]

View File

@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving
import dev.inmo.micro_utils.coroutines.ExceptionHandler
import dev.inmo.micro_utils.coroutines.safely
import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.exceptions.RequestException
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier
@ -15,7 +16,7 @@ import dev.inmo.tgbotapi.updateshandlers.*
import dev.inmo.tgbotapi.utils.*
import kotlinx.coroutines.*
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
fun TelegramBot.startGettingOfUpdatesByLongPolling(
timeoutSeconds: Seconds = 30,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
@ -65,6 +66,33 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
}
}
/**
* Will [startGettingOfUpdatesByLongPolling] using incoming [flowsUpdatesFilter]. It is assumed that you ALREADY CONFIGURE
* all updates receivers, because this method will trigger getting of updates and.
*/
fun TelegramBot.longPolling(
flowsUpdatesFilter: FlowsUpdatesFilter,
timeoutSeconds: Seconds = 30,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
exceptionsHandler: ExceptionHandler<Unit>? = null
): Job = flowsUpdatesFilter.run {
startGettingOfUpdatesByLongPolling(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver)
}
/**
* Will enable [longPolling] by creating [FlowsUpdatesFilter] with [flowsUpdatesFilterUpdatesKeeperCount] as an argument
* and applied [flowUpdatesPreset]. It is assumed that you WILL CONFIGURE all updates receivers in [flowUpdatesPreset],
* because of after [flowUpdatesPreset] method calling will be triggered getting of updates.
*/
@Suppress("unused")
fun TelegramBot.longPolling(
timeoutSeconds: Seconds = 30,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
exceptionsHandler: ExceptionHandler<Unit>? = null,
flowsUpdatesFilterUpdatesKeeperCount: Int = 100,
flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit
): Job = longPolling(FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply(flowUpdatesPreset), timeoutSeconds, scope, exceptionsHandler)
/**
* This method will create a new one [FlowsUpdatesFilter]. This method could be unsafe due to the fact that it will start
* getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call
@ -72,6 +100,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
* [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting
*/
@FlowPreview
@Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling"))
@Suppress("unused")
fun RequestsExecutor.startGettingFlowsUpdatesByLongPolling(
timeoutSeconds: Seconds = 30,
@ -97,6 +126,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
updatesFilter.asUpdateReceiver
)
@Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling"))
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
messageCallback: UpdateReceiver<MessageUpdate>? = null,
messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
@ -141,6 +171,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
)
}
@Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling"))
@Suppress("unused")
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
messageCallback: UpdateReceiver<MessageUpdate>? = null,