mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-27 17:55:52 +00:00
add micro_utils and deprecate old coroutine methods
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
|
||||
|
||||
interface Captioned {
|
||||
val caption: String?
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
|
||||
|
||||
interface Explained {
|
||||
val explanation: String?
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
|
||||
|
||||
interface Texted {
|
||||
val text: String?
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.bot.Ktor
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
|
||||
import dev.inmo.tgbotapi.bot.Ktor.base.*
|
||||
import dev.inmo.tgbotapi.bot.exceptions.newRequestException
|
||||
@@ -36,7 +37,7 @@ class KtorRequestsExecutor(
|
||||
}
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
return handleSafely(
|
||||
return safely(
|
||||
{ e ->
|
||||
throw if (e is ClientRequestException) {
|
||||
val content = e.response ?.readText() ?: throw e
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package dev.inmo.tgbotapi.bot.Ktor.base
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
|
||||
import dev.inmo.tgbotapi.requests.DownloadFile
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||
import dev.inmo.tgbotapi.utils.handleSafely
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.get
|
||||
import kotlinx.serialization.json.Json
|
||||
@@ -18,7 +18,7 @@ object DownloadFileRequestCallFactory : KtorCallFactory {
|
||||
): T? = (request as? DownloadFile) ?.let {
|
||||
val fullUrl = "${urlsKeeper.fileBaseUrl}/${it.filePath}"
|
||||
|
||||
return handleSafely {
|
||||
return safely {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
client.get<ByteArray>(fullUrl) as T // always ByteArray
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ 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.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.shiftSourcesToTheLeft
|
||||
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.internal.shiftSourcesToTheLeft
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.toTextParts
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.boldMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2
|
||||
|
||||
/**
|
||||
* @see bold
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.removeLeading
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
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]*")
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.cashTagMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2
|
||||
|
||||
/**
|
||||
* @see cashTag
|
||||
|
||||
@@ -3,6 +3,9 @@ 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.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.codeMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.codeMarkdownV2
|
||||
|
||||
/**
|
||||
* @see code
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.emailMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2
|
||||
|
||||
/**
|
||||
* @see email
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.hashTagMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2
|
||||
|
||||
/**
|
||||
* @see hashtag
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.italicMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2
|
||||
|
||||
/**
|
||||
* @see italic
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.removeLeading
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
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("@")) {
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.phoneMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2
|
||||
|
||||
/**
|
||||
* @see phone
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.preMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.preMarkdownV2
|
||||
|
||||
/**
|
||||
* @see pre
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.regularMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.regularMarkdownV2
|
||||
|
||||
/**
|
||||
* @see regular
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2
|
||||
|
||||
/**
|
||||
* @see strikethrough
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.linkMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2
|
||||
|
||||
/**
|
||||
* @see link
|
||||
|
||||
@@ -3,6 +3,9 @@ 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.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.textMentionMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2
|
||||
|
||||
/**
|
||||
* @see mention
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.linkMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2
|
||||
|
||||
/**
|
||||
* @see link
|
||||
|
||||
@@ -2,6 +2,9 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.underlineMarkdown
|
||||
import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2
|
||||
|
||||
/**
|
||||
* @see underline
|
||||
|
||||
@@ -22,7 +22,6 @@ import dev.inmo.tgbotapi.types.payments.Invoice
|
||||
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||
import dev.inmo.tgbotapi.types.polls.Poll
|
||||
import dev.inmo.tgbotapi.types.venue.Venue
|
||||
import dev.inmo.tgbotapi.utils.fullListOfSubSource
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@@ -10,7 +10,9 @@ import dev.inmo.tgbotapi.types.ParseMode.*
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.internal.toMarkdownTexts
|
||||
|
||||
data class TextContent(
|
||||
val text: String,
|
||||
|
||||
@@ -14,8 +14,8 @@ import dev.inmo.tgbotapi.types.files.AnimationFile
|
||||
import dev.inmo.tgbotapi.types.files.DocumentFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||
import dev.inmo.tgbotapi.utils.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.toMarkdownV2Captions
|
||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions
|
||||
|
||||
data class AnimationContent(
|
||||
override val media: AnimationFile,
|
||||
|
||||
@@ -12,7 +12,7 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.files.AudioFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent
|
||||
import dev.inmo.tgbotapi.utils.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
||||
|
||||
data class AudioContent(
|
||||
override val media: AudioFile,
|
||||
|
||||
@@ -15,7 +15,7 @@ import dev.inmo.tgbotapi.types.files.asDocumentFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||
import dev.inmo.tgbotapi.utils.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
||||
|
||||
data class DocumentContent(
|
||||
override val media: DocumentFile,
|
||||
|
||||
@@ -13,7 +13,7 @@ import dev.inmo.tgbotapi.types.files.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
|
||||
import dev.inmo.tgbotapi.utils.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
||||
|
||||
data class PhotoContent(
|
||||
override val mediaCollection: Photo,
|
||||
|
||||
@@ -12,7 +12,7 @@ import dev.inmo.tgbotapi.types.files.VideoFile
|
||||
import dev.inmo.tgbotapi.types.files.toInputMediaVideo
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
|
||||
import dev.inmo.tgbotapi.utils.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
||||
|
||||
data class VideoContent(
|
||||
override val media: VideoFile,
|
||||
|
||||
@@ -13,8 +13,8 @@ import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.files.VoiceFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||
import dev.inmo.tgbotapi.utils.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.toMarkdownV2Captions
|
||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
||||
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions
|
||||
|
||||
data class VoiceContent(
|
||||
override val media: VoiceFile,
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
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
|
||||
|
||||
|
||||
typealias ExceptionHandler<T> = suspend (Throwable) -> T
|
||||
@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 {
|
||||
return try {
|
||||
supervisorScope(block)
|
||||
} catch (e: Throwable) {
|
||||
onException(e)
|
||||
}
|
||||
}
|
||||
): T = safely(onException, block)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
package dev.inmo.tgbotapi.utils.internal
|
||||
|
||||
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
package dev.inmo.tgbotapi.utils.internal
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
package dev.inmo.tgbotapi.utils.internal
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
package dev.inmo.tgbotapi.utils.internal
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.*
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
@@ -3,7 +3,7 @@ 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.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.MessageEntity
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.justTextSources
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import dev.inmo.tgbotapi.utils.internal.toHtmlTexts
|
||||
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Texts
|
||||
import kotlin.test.*
|
||||
|
||||
class TextPartsCreatingTests {
|
||||
|
||||
Reference in New Issue
Block a user