mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 03:28:44 +00:00
deprecations removing and several warnings fixes
This commit is contained in:
parent
6013c3ba86
commit
1f5c719294
@ -15,6 +15,7 @@
|
||||
* `UUID`: `0.1.1` -> `0.2.0`
|
||||
* `Ktor`: `1.3.2` -> `1.3.2-1.4.0-rc`
|
||||
* `buildMimeType` function now is cache-oriented getter which will save already got mime types into internal map
|
||||
* All deprecations from previous versions were removed
|
||||
|
||||
## 0.27.0
|
||||
|
||||
|
@ -13,9 +13,7 @@ import io.ktor.client.engine.*
|
||||
*/
|
||||
data class BotBuilder internal constructor(
|
||||
var proxy: ProxyConfig? = null,
|
||||
@Deprecated("ktorClientEngineFactory parameter will be used preferable. In future this parameter will be removed")
|
||||
var ktorClientEngine: HttpClientEngine? = null,
|
||||
var ktorClientEngineFactory: HttpClientEngineFactory<out HttpClientEngineConfig>? = null,
|
||||
var ktorClientEngineFactory: HttpClientEngineFactory<HttpClientEngineConfig>? = null,
|
||||
var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null
|
||||
) {
|
||||
internal fun createHttpClient(): HttpClient = ktorClientEngineFactory ?.let {
|
||||
@ -26,13 +24,6 @@ data class BotBuilder internal constructor(
|
||||
) {
|
||||
ktorClientConfig ?.let { it() }
|
||||
}
|
||||
} ?: ktorClientEngine ?.let { engine ->
|
||||
HttpClient(engine) {
|
||||
ktorClientConfig ?.let { it() }
|
||||
engine {
|
||||
this@engine.proxy = this@BotBuilder.proxy ?: this@engine.proxy
|
||||
}
|
||||
}
|
||||
} ?: HttpClient {
|
||||
ktorClientConfig ?.let { it() }
|
||||
engine {
|
||||
|
@ -1,10 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.getMe
|
||||
|
||||
@Deprecated(
|
||||
"Replaced",
|
||||
ReplaceWith("getMe", "com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe")
|
||||
)
|
||||
suspend fun RequestsExecutor.getMe() = getMe()
|
@ -16,7 +16,7 @@ internal fun Update.lastUpdateIdentifier(): UpdateIdentifier {
|
||||
}
|
||||
|
||||
internal fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
|
||||
return maxBy { it.updateId } ?.lastUpdateIdentifier()
|
||||
return maxByOrNull { it.updateId } ?.lastUpdateIdentifier()
|
||||
}
|
||||
|
||||
internal fun List<Update>.convertWithMediaGroupUpdates(): List<Update> {
|
||||
|
@ -1,182 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.updates
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||
fun RequestsExecutor.startGettingOfUpdates(
|
||||
timeoutSeconds: Seconds = 30,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
|
||||
allowedUpdates: List<String>? = null,
|
||||
updatesReceiver: UpdateReceiver<Update>
|
||||
): Job = scope.launch {
|
||||
var lastUpdateIdentifier: UpdateIdentifier? = null
|
||||
|
||||
while (isActive) {
|
||||
handleSafely(
|
||||
{ e ->
|
||||
exceptionsHandler ?.invoke(e)
|
||||
if (e is RequestException) {
|
||||
delay(1000L)
|
||||
}
|
||||
}
|
||||
) {
|
||||
val updates = getUpdates(
|
||||
offset = lastUpdateIdentifier?.plus(1),
|
||||
timeout = timeoutSeconds,
|
||||
allowed_updates = allowedUpdates
|
||||
).let { originalUpdates ->
|
||||
val converted = originalUpdates.convertWithMediaGroupUpdates()
|
||||
/**
|
||||
* Dirty hack for cases when the media group was retrieved not fully:
|
||||
*
|
||||
* We are throw out the last media group and will reretrieve it again in the next get updates
|
||||
* and it will guarantee that it is full
|
||||
*/
|
||||
if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) {
|
||||
converted - converted.last()
|
||||
} else {
|
||||
converted
|
||||
}
|
||||
}
|
||||
|
||||
handleSafely {
|
||||
for (update in updates) {
|
||||
updatesReceiver(update)
|
||||
|
||||
lastUpdateIdentifier = update.lastUpdateIdentifier()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows. To avoid it, you can pass
|
||||
* [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting
|
||||
*/
|
||||
@FlowPreview
|
||||
@PreviewFeature
|
||||
@Suppress("unused")
|
||||
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||
fun RequestsExecutor.startGettingFlowsUpdates(
|
||||
timeoutSeconds: Seconds = 30,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||
flowsUpdatesFilterUpdatesKeeperCount: Int = 100,
|
||||
flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {}
|
||||
): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply {
|
||||
flowUpdatesPreset()
|
||||
startGettingOfUpdates(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver)
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||
fun RequestsExecutor.startGettingOfUpdates(
|
||||
updatesFilter: UpdatesFilter,
|
||||
timeoutSeconds: Seconds = 30,
|
||||
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
): Job = startGettingOfUpdates(
|
||||
timeoutSeconds,
|
||||
scope,
|
||||
exceptionsHandler,
|
||||
updatesFilter.allowedUpdates,
|
||||
updatesFilter.asUpdateReceiver
|
||||
)
|
||||
|
||||
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||
fun RequestsExecutor.startGettingOfUpdates(
|
||||
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||
messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null,
|
||||
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||
editedMessageMediaGroupCallback: UpdateReceiver<EditMessageMediaGroupUpdate>? = null,
|
||||
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
||||
channelPostMediaGroupCallback: UpdateReceiver<ChannelPostMediaGroupUpdate>? = null,
|
||||
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
||||
editedChannelPostMediaGroupCallback: UpdateReceiver<EditChannelPostMediaGroupUpdate>? = null,
|
||||
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
||||
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||
timeoutSeconds: Seconds = 30,
|
||||
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||
scope: CoroutineScope = GlobalScope
|
||||
): Job {
|
||||
return startGettingOfUpdates(
|
||||
SimpleUpdatesFilter(
|
||||
messageCallback,
|
||||
messageMediaGroupCallback,
|
||||
editedMessageCallback,
|
||||
editedMessageMediaGroupCallback,
|
||||
channelPostCallback,
|
||||
channelPostMediaGroupCallback,
|
||||
editedChannelPostCallback,
|
||||
editedChannelPostMediaGroupCallback,
|
||||
chosenInlineResultCallback,
|
||||
inlineQueryCallback,
|
||||
callbackQueryCallback,
|
||||
shippingQueryCallback,
|
||||
preCheckoutQueryCallback,
|
||||
pollCallback,
|
||||
pollAnswerCallback
|
||||
),
|
||||
timeoutSeconds,
|
||||
exceptionsHandler,
|
||||
scope
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@Deprecated("Replaced and renamed in TelegramBotAPI-extensions-utils")
|
||||
fun RequestsExecutor.startGettingOfUpdates(
|
||||
messageCallback: UpdateReceiver<MessageUpdate>? = null,
|
||||
mediaGroupCallback: UpdateReceiver<MediaGroupUpdate>? = null,
|
||||
editedMessageCallback: UpdateReceiver<EditMessageUpdate>? = null,
|
||||
channelPostCallback: UpdateReceiver<ChannelPostUpdate>? = null,
|
||||
editedChannelPostCallback: UpdateReceiver<EditChannelPostUpdate>? = null,
|
||||
chosenInlineResultCallback: UpdateReceiver<ChosenInlineResultUpdate>? = null,
|
||||
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||
timeoutSeconds: Seconds = 30,
|
||||
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
): Job = startGettingOfUpdates(
|
||||
messageCallback = messageCallback,
|
||||
messageMediaGroupCallback = mediaGroupCallback,
|
||||
editedMessageCallback = editedMessageCallback,
|
||||
editedMessageMediaGroupCallback = mediaGroupCallback,
|
||||
channelPostCallback = channelPostCallback,
|
||||
channelPostMediaGroupCallback = mediaGroupCallback,
|
||||
editedChannelPostCallback = editedChannelPostCallback,
|
||||
editedChannelPostMediaGroupCallback = mediaGroupCallback,
|
||||
chosenInlineResultCallback = chosenInlineResultCallback,
|
||||
inlineQueryCallback = inlineQueryCallback,
|
||||
callbackQueryCallback = callbackQueryCallback,
|
||||
shippingQueryCallback = shippingQueryCallback,
|
||||
preCheckoutQueryCallback = preCheckoutQueryCallback,
|
||||
pollCallback = pollCallback,
|
||||
pollAnswerCallback = pollAnswerCallback,
|
||||
timeoutSeconds = timeoutSeconds,
|
||||
exceptionsHandler = exceptionsHandler,
|
||||
scope = scope
|
||||
)
|
@ -5,7 +5,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.link
|
||||
|
||||
private const val internalLinkBeginning = "https://t.me"
|
||||
|
||||
|
@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.*
|
||||
|
||||
inline fun <reified T : MessageContent> filterForContentMessage(): suspend (ContentMessage<*>) -> ContentMessage<T>? = {
|
||||
if (it.content is T) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
it as ContentMessage<T>
|
||||
} else {
|
||||
null
|
||||
@ -32,6 +33,7 @@ inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.filterMedi
|
||||
): Flow<List<CommonMessage<T>>> = map {
|
||||
it.data.mapNotNull { message ->
|
||||
if (message.content is T) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
message as CommonMessage<T>
|
||||
} else {
|
||||
null
|
||||
@ -83,7 +85,10 @@ fun FlowsUpdatesFilter.sentMessagesWithMediaGroups(
|
||||
): Flow<ContentMessage<MessageContent>> = merge(
|
||||
sentMessages(scopeToIncludeChannels),
|
||||
mediaGroupMessages(scopeToIncludeChannels).flatMap {
|
||||
it.mapNotNull { it as? ContentMessage<MessageContent> }
|
||||
it.mapNotNull {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
it as? ContentMessage<MessageContent>
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -15,16 +15,6 @@ fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdatesByChatId(chatId: Cha
|
||||
* [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
||||
*/
|
||||
fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdatesByChat(chat: Chat): Flow<T> = filterBaseMessageUpdatesByChatId(chat.id)
|
||||
/**
|
||||
* [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId]
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("filterBaseMessageUpdatesByChatId"))
|
||||
fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdates(chatId: ChatId): Flow<T> = filterBaseMessageUpdatesByChatId(chatId)
|
||||
/**
|
||||
* [Flow.filter] incoming [BaseMessageUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("filterBaseMessageUpdatesByChat"))
|
||||
fun <T : BaseMessageUpdate> Flow<T>.filterBaseMessageUpdates(chat: Chat): Flow<T> = filterBaseMessageUpdatesByChatId(chat.id)
|
||||
|
||||
|
||||
/**
|
||||
@ -35,13 +25,3 @@ fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdatesByChatId(chatI
|
||||
* [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
||||
*/
|
||||
fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdatesByChat(chat: Chat): Flow<T> = filterSentMediaGroupUpdatesByChatId(chat.id)
|
||||
/**
|
||||
* [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId]
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("filterSentMediaGroupUpdatesByChatId"))
|
||||
fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdates(chatId: ChatId): Flow<T> = filterSentMediaGroupUpdatesByChatId(chatId)
|
||||
/**
|
||||
* [Flow.filter] incoming [SentMediaGroupUpdate]s by their [ChatId] using [Chat.id] of [chat]
|
||||
*/
|
||||
@Deprecated("Renamed", ReplaceWith("filterSentMediaGroupUpdatesByChat"))
|
||||
fun <T : SentMediaGroupUpdate> Flow<T>.filterSentMediaGroupUpdates(chat: Chat): Flow<T> = filterSentMediaGroupUpdatesByChatId(chat.id)
|
||||
|
@ -24,7 +24,7 @@ fun Update.lastUpdateIdentifier(): UpdateIdentifier {
|
||||
* @see [Update.lastUpdateIdentifier]
|
||||
*/
|
||||
fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
|
||||
return maxBy { it.updateId } ?.lastUpdateIdentifier()
|
||||
return maxByOrNull { it.updateId } ?.lastUpdateIdentifier()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,11 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe
|
||||
|
||||
@Deprecated(
|
||||
"Replaced",
|
||||
ReplaceWith(
|
||||
"GetMe", "com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe"
|
||||
)
|
||||
)
|
||||
typealias GetMe = GetMe
|
@ -13,11 +13,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
import kotlinx.serialization.json.buildJsonArray
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
|
||||
@Deprecated("Replaced and renamed", ReplaceWith("mediaCountInMediaGroup", "com.github.insanusmokrassar.TelegramBotAPI.types.mediaCountInMediaGroup"))
|
||||
val membersCountInMediaGroup
|
||||
get() = mediaCountInMediaGroup
|
||||
|
||||
fun SendMediaGroup(
|
||||
chatId: ChatIdentifier,
|
||||
|
@ -212,15 +212,11 @@ data class SendQuizPoll(
|
||||
override val replyToMessageId: MessageIdentifier? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendPoll(), CaptionedOutput, ExplainedOutput {
|
||||
) : SendPoll(), ExplainedOutput {
|
||||
override val type: String = quizPollType
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
@Deprecated("Will be removed in near updates", ReplaceWith("explanation"))
|
||||
override val caption: String?
|
||||
get() = explanation
|
||||
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?
|
||||
= (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000)
|
||||
|
@ -24,24 +24,6 @@ fun AddStaticStickerToSet(
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Renamed",
|
||||
ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet")
|
||||
)
|
||||
fun AddStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSetName: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
||||
|
||||
@Deprecated(
|
||||
"Renamed",
|
||||
ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet")
|
||||
)
|
||||
typealias AddStickerToSet = AddStaticStickerToSet
|
||||
|
||||
@Serializable
|
||||
data class AddStaticStickerToSet internal constructor(
|
||||
@SerialName(userIdField)
|
||||
|
@ -34,12 +34,6 @@ fun CreateNewStickerSet(
|
||||
maskPosition: MaskPosition? = null
|
||||
): Request<Boolean> = CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition)
|
||||
|
||||
@Deprecated(
|
||||
"Renamed",
|
||||
ReplaceWith("CreateNewStaticStickerSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStaticStickerSet")
|
||||
)
|
||||
typealias CreateNewStickerSet = CreateNewStaticStickerSet
|
||||
|
||||
@Serializable
|
||||
data class CreateNewStaticStickerSet internal constructor(
|
||||
@SerialName(userIdField)
|
||||
|
@ -62,8 +62,6 @@ val botCommandsLimit = 0 .. 100
|
||||
val mediaCountInMediaGroup: IntRange = 2 .. 10
|
||||
|
||||
val explanationLimit = 0 .. 200
|
||||
@Deprecated("Will be removed in near updates", ReplaceWith("explanationLimit"))
|
||||
val quizPollExplanationLimit = explanationLimit
|
||||
|
||||
val openPeriodPollSecondsLimit = 5 .. 600
|
||||
|
||||
|
@ -1,9 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.dice.Dice
|
||||
|
||||
@Deprecated(
|
||||
"Replaced",
|
||||
ReplaceWith("Dice", "com.github.insanusmokrassar.TelegramBotAPI.types.dice.Dice")
|
||||
)
|
||||
typealias Dice = Dice
|
@ -1,6 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Locationed
|
||||
|
||||
@Deprecated("Will be removed due to useless")
|
||||
interface PositionedInlineQueryResult : InlineQueryResult, Locationed
|
@ -1,6 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue
|
||||
|
||||
@Deprecated("Replaced", ReplaceWith("Venue", "com.github.insanusmokrassar.TelegramBotAPI.types.venue.Venue"))
|
||||
typealias Venue = Venue
|
@ -25,8 +25,6 @@ object BasketballDiceAnimationType : DiceAnimationType() {
|
||||
data class CustomDiceAnimationType(
|
||||
override val emoji: String
|
||||
) : DiceAnimationType()
|
||||
@Deprecated("Renamed", ReplaceWith("CustomDiceAnimationType"))
|
||||
typealias UnknownDiceAnimationType = CustomDiceAnimationType
|
||||
|
||||
@Serializer(DiceAnimationType::class)
|
||||
internal object DiceAnimationTypeSerializer : KSerializer<DiceAnimationType> {
|
||||
|
@ -9,7 +9,7 @@ import kotlinx.serialization.builtins.ListSerializer
|
||||
|
||||
typealias Photo = List<PhotoSize>
|
||||
|
||||
fun Photo.biggest(): PhotoSize? = maxBy {
|
||||
fun Photo.biggest(): PhotoSize? = maxByOrNull {
|
||||
it.resolution
|
||||
}
|
||||
|
||||
|
@ -136,14 +136,7 @@ data class QuizPoll(
|
||||
override val isClosed: Boolean = false,
|
||||
override val isAnonymous: Boolean = false,
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = null
|
||||
) : Poll(), CaptionedInput, ExplainedInput {
|
||||
@Deprecated("Will be removed in near updates", ReplaceWith("explanation"))
|
||||
override val caption: String?
|
||||
get() = explanation
|
||||
@Deprecated("Will be removed in near updates", ReplaceWith("explanationEntities"))
|
||||
override val captionEntities: List<TextPart>
|
||||
get() = explanationEntities
|
||||
}
|
||||
) : Poll(), ExplainedInput
|
||||
|
||||
@Serializer(Poll::class)
|
||||
internal object PollSerializer : KSerializer<Poll> {
|
||||
|
@ -19,8 +19,6 @@ data class UnknownUpdate(
|
||||
override val data: String,
|
||||
val rawJson: JsonElement
|
||||
) : Update
|
||||
@Deprecated("Renamed", ReplaceWith("UnknownUpdate"))
|
||||
typealias UnknownUpdateType = UnknownUpdate
|
||||
|
||||
internal object UpdateSerializerWithoutSerialization : KSerializer<Update> {
|
||||
override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor
|
||||
|
@ -6,8 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createFormattedText(
|
||||
internal fun createFormattedText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last,
|
||||
mode: ParseMode = MarkdownParseMode
|
||||
@ -48,96 +47,63 @@ fun createFormattedText(
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createMarkdownText(
|
||||
internal fun createMarkdownText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownCaptions(): List<String> = createMarkdownText(
|
||||
this,
|
||||
captionLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun CaptionedInput.toMarkdownCaptions(): List<String> = fullEntitiesList().toMarkdownCaptions()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownTexts(): List<String> = createMarkdownText(
|
||||
internal fun FullTextSourcesList.toMarkdownTexts(): List<String> = createMarkdownText(
|
||||
this,
|
||||
textLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
internal fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
|
||||
internal fun FullTextSourcesList.toMarkdownExplanations(): List<String> = createMarkdownText(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
internal fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
|
||||
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createMarkdownV2Text(
|
||||
internal fun createMarkdownV2Text(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, MarkdownV2ParseMode)
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
|
||||
internal fun FullTextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
captionLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toMarkdownV2Captions()
|
||||
internal fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toMarkdownV2Captions()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
|
||||
internal fun FullTextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
textLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
internal fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
|
||||
internal fun FullTextSourcesList.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
internal fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
|
||||
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun createHtmlText(
|
||||
internal fun createHtmlText(
|
||||
entities: FullTextSourcesList,
|
||||
partLength: Int = textLength.last
|
||||
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
|
||||
internal fun FullTextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
|
||||
this,
|
||||
captionLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCaptions()
|
||||
internal fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCaptions()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
|
||||
internal fun FullTextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
|
||||
this,
|
||||
textLength.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun FullTextSourcesList.toHtmlExplanations(): List<String> = createHtmlText(
|
||||
this,
|
||||
explanationLimit.last
|
||||
)
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils")
|
||||
fun ExplainedInput.toHtmlExplanations(): List<String> = fullEntitiesList().toHtmlTexts()
|
||||
internal fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
|
||||
|
||||
|
||||
|
@ -1,36 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat
|
||||
|
||||
private const val internalLinkBeginning = "https://t.me"
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils project")
|
||||
fun makeLinkToMessage(
|
||||
username: String,
|
||||
messageId: MessageIdentifier
|
||||
): String = "$internalLinkBeginning/$username/$messageId"
|
||||
|
||||
private val linkIdRedundantPartRegex = Regex("^-100")
|
||||
private val usernameBeginSymbolRegex = Regex("^@")
|
||||
|
||||
@Deprecated("Replaced into TelegramBotAPI-extensions-utils project")
|
||||
fun makeLinkToMessage(
|
||||
chat: ExtendedChat,
|
||||
messageId: MessageIdentifier
|
||||
): String? {
|
||||
return when {
|
||||
chat is UsernameChat && chat.username != null -> {
|
||||
"$internalLinkBeginning/${chat.username ?.username ?.replace(usernameBeginSymbolRegex, "")}/$messageId"
|
||||
}
|
||||
chat !is PrivateChat -> chat.id.chatId.toString().replace(
|
||||
linkIdRedundantPartRegex,
|
||||
""
|
||||
).let { bareId ->
|
||||
"$internalLinkBeginning/c/$bareId/$messageId"
|
||||
}
|
||||
else -> return null
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardInfo
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.forwarded: ForwardInfo?
|
||||
get() = first().let {
|
||||
(it as? PossiblyForwardedMessage) ?.forwardInfo
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.replyTo: Message?
|
||||
get() = first().let {
|
||||
(it as? PossiblyReplyMessage) ?.replyTo
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.chat: Chat?
|
||||
get() = first().data.chat
|
||||
|
||||
@Deprecated("Replaced and updated inside of TelegramBotAPI-extensions-utils")
|
||||
val List<BaseMessageUpdate>.mediaGroupId: MediaGroupIdentifier?
|
||||
get() = (first().data as? MediaGroupMessage) ?.mediaGroupId
|
@ -36,72 +36,45 @@ private fun String.htmlDefault(
|
||||
closeControlSymbol: String = openControlSymbol
|
||||
) = "<$openControlSymbol>${toHtml()}</$closeControlSymbol>"
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})"
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.linkMarkdownV2(link: String): String = "[${escapeMarkdownV2Common()}](${link.escapeMarkdownV2Link()})"
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.linkHTML(link: String): String = "<a href=\"$link\">${toHtml()}</a>"
|
||||
|
||||
internal fun String.linkMarkdown(link: String): String = "[${toMarkdown()}](${link.toMarkdown()})"
|
||||
internal fun String.linkMarkdownV2(link: String): String = "[${escapeMarkdownV2Common()}](${link.escapeMarkdownV2Link()})"
|
||||
internal fun String.linkHTML(link: String): String = "<a href=\"$link\">${toHtml()}</a>"
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.boldMarkdownV2(): String = markdownV2Default(markdownBoldControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.boldHTML(): String = htmlDefault(htmlBoldControl)
|
||||
internal fun String.boldMarkdown(): String = markdownDefault(markdownBoldControl)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl, markdownV2ItalicEndControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.italicHTML(): String = htmlDefault(htmlItalicControl)
|
||||
internal fun String.italicMarkdown(): String = markdownDefault(markdownItalicControl)
|
||||
|
||||
/**
|
||||
* Crutch for support of strikethrough in default markdown. Simply add modifier, but it will not look like correct
|
||||
*/
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.strikethroughMarkdown(): String = map { it + "\u0336" }.joinToString("")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.strikethroughHTML(): String = htmlDefault(htmlStrikethroughControl)
|
||||
|
||||
internal fun String.strikethroughMarkdown(): String = map { it + "\u0336" }.joinToString("")
|
||||
internal fun String.strikethroughMarkdownV2(): String = markdownV2Default(markdownV2StrikethroughControl)
|
||||
|
||||
|
||||
/**
|
||||
* Crutch for support of underline in default markdown. Simply add modifier, but it will not look like correct
|
||||
*/
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.underlineMarkdown(): String = map { it + "\u0347" }.joinToString("")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
||||
|
||||
internal fun String.underlineMarkdown(): String = map { it + "\u0347" }.joinToString("")
|
||||
internal fun String.underlineMarkdownV2(): String = markdownV2Default(markdownV2UnderlineControl, markdownV2UnderlineEndControl)
|
||||
internal fun String.underlineHTML(): String = htmlDefault(htmlUnderlineControl)
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
||||
internal fun String.codeMarkdown(): String = markdownDefault(markdownCodeControl)
|
||||
internal fun String.codeMarkdownV2(): String = markdownV2Default(markdownCodeControl, escapeFun = String::escapeMarkdownV2PreAndCode)
|
||||
internal fun String.codeHTML(): String = htmlDefault(htmlCodeControl)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.preMarkdown(language: String? = null): String = markdownDefault(
|
||||
internal fun String.preMarkdown(language: String? = null): String = markdownDefault(
|
||||
"$markdownPreControl${language ?: ""}\n",
|
||||
"\n$markdownPreControl"
|
||||
)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.preMarkdownV2(language: String? = null): String = markdownV2Default(
|
||||
internal fun String.preMarkdownV2(language: String? = null): String = markdownV2Default(
|
||||
"$markdownPreControl${language ?: ""}\n",
|
||||
"\n$markdownPreControl",
|
||||
String::escapeMarkdownV2PreAndCode
|
||||
)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.preHTML(language: String? = null): String = htmlDefault(
|
||||
internal fun String.preHTML(language: String? = null): String = htmlDefault(
|
||||
language ?.let {
|
||||
"$htmlPreControl><$htmlCodeControl class=\"language-$language\""
|
||||
} ?: htmlPreControl,
|
||||
@ -110,198 +83,68 @@ fun String.preHTML(language: String? = null): String = htmlDefault(
|
||||
} ?: htmlPreControl
|
||||
)
|
||||
|
||||
internal fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}")
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.emailMarkdown(): String = linkMarkdown("mailto://$${toMarkdown()}")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.emailMarkdownV2(): String = linkMarkdownV2("mailto://$${toMarkdown()}")
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.emailHTML(): String = linkHTML("mailto://$${toHtml()}")
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
private inline fun String.mention(adapt: String.() -> String): String = if (startsWith("@")) {
|
||||
adapt()
|
||||
} else {
|
||||
"@${adapt()}"
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
private inline fun String.hashTag(adapt: String.() -> String): String = if (startsWith("#")) {
|
||||
adapt()
|
||||
} else {
|
||||
"#${adapt()}"
|
||||
}
|
||||
|
||||
internal fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
||||
internal fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.textMentionMarkdown(userId: UserId): String = linkMarkdown(userId.link)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.textMentionHTML(userId: UserId): String = linkHTML(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)
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.mentionMarkdown(): String = mention(String::toMarkdown)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.mentionMarkdownV2(): String = mention(String::escapeMarkdownV2Common)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.mentionHTML(): String = mention(String::toHtml)
|
||||
internal fun String.phoneMarkdown(): String = toMarkdown()
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.phoneMarkdown(): String = toMarkdown()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.phoneMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.phoneHTML(): String = toHtml()
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.command(adapt: String.() -> String): String = if (startsWith("/")) {
|
||||
internal fun String.command(adapt: String.() -> String): String = if (startsWith("/")) {
|
||||
adapt()
|
||||
} else {
|
||||
"/${adapt()}"
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.commandMarkdown(): String = command(String::toMarkdown)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common)
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.commandHTML(): String = command(String::toHtml)
|
||||
internal fun String.commandMarkdown(): String = command(String::toMarkdown)
|
||||
internal fun String.commandMarkdownV2(): String = command(String::escapeMarkdownV2Common)
|
||||
internal fun String.commandHTML(): String = command(String::toHtml)
|
||||
|
||||
internal fun String.regularMarkdown(): String = toMarkdown()
|
||||
internal fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
internal fun String.regularHtml(): String = toHtml()
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.regularMarkdown(): String = toMarkdown()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.regularHtml(): String = toHtml()
|
||||
internal fun String.cashTagMarkdown(): String = toMarkdown()
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.cashTagMarkdown(): String = toMarkdown()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.cashTagMarkdownV2(): String = escapeMarkdownV2Common()
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.cashTagHtml(): String = toHtml()
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.bold(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> boldHTML()
|
||||
is Markdown -> boldMarkdown()
|
||||
is MarkdownV2 -> boldMarkdownV2()
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.italic(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> italicHTML()
|
||||
is Markdown -> italicMarkdown()
|
||||
is MarkdownV2 -> italicMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.hashTag(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> hashTagHTML()
|
||||
is Markdown -> hashTagMarkdown()
|
||||
is MarkdownV2 -> hashTagMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.code(parseMode: ParseMode): String = when (parseMode) {
|
||||
internal infix fun String.code(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> codeHTML()
|
||||
is Markdown -> codeMarkdown()
|
||||
is MarkdownV2 -> codeMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
fun String.pre(parseMode: ParseMode, language: String? = null): String = when (parseMode) {
|
||||
is HTML -> preHTML(language)
|
||||
is Markdown -> preMarkdown(language)
|
||||
is MarkdownV2 -> preMarkdownV2(language)
|
||||
}
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.pre(parseMode: ParseMode): String = pre(parseMode, null)
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.email(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> emailHTML()
|
||||
is Markdown -> emailMarkdown()
|
||||
is MarkdownV2 -> emailMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun Pair<String, String>.link(parseMode: ParseMode): String = when (parseMode) {
|
||||
internal infix fun Pair<String, String>.link(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> first.linkHTML(second)
|
||||
is Markdown -> first.linkMarkdown(second)
|
||||
is MarkdownV2 -> first.linkMarkdownV2(second)
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> mentionHTML()
|
||||
is Markdown -> mentionMarkdown()
|
||||
is MarkdownV2 -> mentionMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun Pair<String, ChatId>.mention(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> first.textMentionHTML(second)
|
||||
is Markdown -> first.textMentionMarkdown(second)
|
||||
is MarkdownV2 -> first.textMentionMarkdownV2(second)
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.phone(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> phoneHTML()
|
||||
is Markdown -> phoneMarkdown()
|
||||
is MarkdownV2 -> phoneMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
||||
internal infix fun String.command(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> commandHTML()
|
||||
is Markdown -> commandMarkdown()
|
||||
is MarkdownV2 -> commandMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
|
||||
|
||||
internal infix fun String.underline(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> underlineHTML()
|
||||
is Markdown -> underlineMarkdown()
|
||||
is MarkdownV2 -> underlineMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.strikethrough(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> strikethroughHTML()
|
||||
is Markdown -> strikethroughMarkdown()
|
||||
is MarkdownV2 -> strikethroughMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.regular(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> regularHtml()
|
||||
is Markdown -> regularMarkdown()
|
||||
is MarkdownV2 -> regularMarkdownV2()
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
infix fun String.cashtag(parseMode: ParseMode): String = when (parseMode) {
|
||||
is HTML -> cashTagHtml()
|
||||
is Markdown -> cashTagMarkdown()
|
||||
is MarkdownV2 -> cashTagMarkdownV2()
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
@Deprecated("Will be removed in next major update")
|
||||
fun <T: Any> RequestsExecutor.executeAsync(
|
||||
request: Request<T>,
|
||||
onFail: (suspend (Response) -> Unit)? = null,
|
||||
scope: CoroutineScope = GlobalScope,
|
||||
onSuccess: (suspend (T) -> Unit)? = null
|
||||
): Job {
|
||||
return scope.launch {
|
||||
try {
|
||||
val result = execute(request)
|
||||
onSuccess ?.invoke(result)
|
||||
} catch (e: RequestException) {
|
||||
onFail ?.invoke(e.response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and modified inside of TelegramBotAPI-extensions-utils")
|
||||
fun <T: Any> RequestsExecutor.executeAsync(
|
||||
request: Request<T>,
|
||||
scope: CoroutineScope = GlobalScope
|
||||
): Deferred<T> {
|
||||
return scope.async { execute(request) }
|
||||
}
|
||||
|
||||
@Deprecated("Replaced and modified inside of TelegramBotAPI-extensions-utils")
|
||||
suspend fun <T: Any> RequestsExecutor.executeUnsafe(
|
||||
request: Request<T>,
|
||||
retries: Int = 0,
|
||||
retriesDelay: Long = 1000L,
|
||||
onAllFailed: (suspend (exceptions: Array<Exception>) -> Unit)? = null
|
||||
): T? {
|
||||
var leftRetries = retries
|
||||
val exceptions = onAllFailed ?.let { mutableListOf<Exception>() }
|
||||
do {
|
||||
handleSafely(
|
||||
{
|
||||
leftRetries--
|
||||
delay(retriesDelay)
|
||||
exceptions ?.add(it)
|
||||
null
|
||||
}
|
||||
) {
|
||||
execute(request)
|
||||
} ?.let { return it }
|
||||
} while(leftRetries >= 0)
|
||||
onAllFailed ?.invoke(exceptions ?.toTypedArray() ?: emptyArray())
|
||||
return null
|
||||
}
|
@ -1,218 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdateReceiver
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.webhook.WebhookPrivateKeyConfig
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.request.receiveText
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.post
|
||||
import io.ktor.routing.routing
|
||||
import io.ktor.server.engine.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Reverse proxy webhook.
|
||||
*
|
||||
* @param url URL of webhook WITHOUT including of [port]
|
||||
* @param port port which will be listen by bot
|
||||
* @param listenRoute address to listen by bot
|
||||
* @param certificate [com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile] or [com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId]
|
||||
* which will be used by telegram to send encrypted messages
|
||||
* @param scope Scope which will be used for
|
||||
*/
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
suspend fun RequestsExecutor.setWebhook(
|
||||
url: String,
|
||||
port: Int,
|
||||
engineFactory: ApplicationEngineFactory<*, *>,
|
||||
listenHost: String = "0.0.0.0",
|
||||
listenRoute: String = "/",
|
||||
certificate: InputFile? = null,
|
||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||
allowedUpdates: List<String>? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
|
||||
block: UpdateReceiver<Update>
|
||||
): Job {
|
||||
val executeDeferred = certificate ?.let {
|
||||
executeAsync(
|
||||
SetWebhook(
|
||||
url,
|
||||
certificate,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
)
|
||||
)
|
||||
} ?: executeAsync(
|
||||
SetWebhook(
|
||||
url,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
)
|
||||
)
|
||||
val updatesChannel = Channel<Update>(Channel.UNLIMITED)
|
||||
val mediaGroupChannel = Channel<Pair<String, BaseMessageUpdate>>(Channel.UNLIMITED)
|
||||
val mediaGroupAccumulatedChannel = mediaGroupChannel.accumulateByKey(
|
||||
1000L,
|
||||
scope = scope
|
||||
)
|
||||
val env = applicationEngineEnvironment {
|
||||
|
||||
module {
|
||||
routing {
|
||||
post(listenRoute) {
|
||||
handleSafely(
|
||||
{
|
||||
exceptionsHandler ?.invoke(it)
|
||||
}
|
||||
) {
|
||||
val asJson = nonstrictJsonFormat.parseToJsonElement(call.receiveText())
|
||||
val update = nonstrictJsonFormat.decodeFromJsonElement(
|
||||
UpdateDeserializationStrategy,
|
||||
asJson
|
||||
)
|
||||
updatesChannel.send(update)
|
||||
}
|
||||
call.respond("Ok")
|
||||
}
|
||||
}
|
||||
}
|
||||
privateKeyConfig ?.let {
|
||||
sslConnector(
|
||||
privateKeyConfig.keyStore,
|
||||
privateKeyConfig.aliasName,
|
||||
privateKeyConfig::keyStorePassword,
|
||||
privateKeyConfig::aliasPassword
|
||||
) {
|
||||
host = listenHost
|
||||
this.port = port
|
||||
}
|
||||
} ?: connector {
|
||||
host = listenHost
|
||||
this.port = port
|
||||
}
|
||||
|
||||
}
|
||||
val engine = embeddedServer(engineFactory, env)
|
||||
|
||||
try {
|
||||
executeDeferred.await()
|
||||
} catch (e: Exception) {
|
||||
env.stop()
|
||||
throw e
|
||||
}
|
||||
|
||||
return scope.launch {
|
||||
launch {
|
||||
for (update in updatesChannel) {
|
||||
val data = update.data
|
||||
when (data) {
|
||||
is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
|
||||
else -> block(update)
|
||||
}
|
||||
}
|
||||
}
|
||||
launch {
|
||||
for ((_, mediaGroup) in mediaGroupAccumulatedChannel) {
|
||||
mediaGroup.convertWithMediaGroupUpdates().forEach {
|
||||
block(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
engine.start(false)
|
||||
}.also {
|
||||
it.invokeOnCompletion {
|
||||
engine.stop(1000L, 0L, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
suspend fun RequestsExecutor.setWebhook(
|
||||
url: String,
|
||||
port: Int,
|
||||
engineFactory: ApplicationEngineFactory<*, *>,
|
||||
listenHost: String = "0.0.0.0",
|
||||
listenRoute: String = "/",
|
||||
certificate: InputFile? = null,
|
||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||
allowedUpdates: List<String>? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
block: UpdateReceiver<Update>
|
||||
) = setWebhook(
|
||||
url,
|
||||
port,
|
||||
engineFactory,
|
||||
listenHost,
|
||||
listenRoute,
|
||||
certificate,
|
||||
privateKeyConfig,
|
||||
scope,
|
||||
allowedUpdates,
|
||||
maxAllowedConnections,
|
||||
null,
|
||||
block
|
||||
)
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
suspend fun RequestsExecutor.setWebhook(
|
||||
url: String,
|
||||
port: Int,
|
||||
engineFactory: ApplicationEngineFactory<*, *>,
|
||||
certificate: InputFile? = null,
|
||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||
allowedUpdates: List<String>? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
block: UpdateReceiver<Update>
|
||||
) = setWebhook(
|
||||
url,
|
||||
port,
|
||||
engineFactory,
|
||||
certificate ?.let { "0.0.0.0" } ?: "localhost",
|
||||
"/",
|
||||
certificate,
|
||||
privateKeyConfig,
|
||||
scope,
|
||||
allowedUpdates,
|
||||
maxAllowedConnections,
|
||||
block
|
||||
)
|
||||
|
||||
@Deprecated("Replaced into project TelegramBotAPI-extensions-utils")
|
||||
suspend fun RequestsExecutor.setWebhook(
|
||||
url: String,
|
||||
port: Int,
|
||||
filter: UpdatesFilter,
|
||||
engineFactory: ApplicationEngineFactory<*, *>,
|
||||
certificate: InputFile? = null,
|
||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||
maxAllowedConnections: Int? = null,
|
||||
listenHost: String = certificate ?.let { "0.0.0.0" } ?: "localhost",
|
||||
listenRoute: String = "/"
|
||||
): Job = setWebhook(
|
||||
url,
|
||||
port,
|
||||
engineFactory,
|
||||
listenHost,
|
||||
listenRoute,
|
||||
certificate,
|
||||
privateKeyConfig,
|
||||
scope,
|
||||
filter.allowedUpdates,
|
||||
maxAllowedConnections,
|
||||
filter.asUpdateReceiver
|
||||
)
|
@ -1,5 +1,7 @@
|
||||
kotlin.code.style=official
|
||||
org.gradle.parallel=true
|
||||
kotlin.js.generate.externals=true
|
||||
|
||||
kotlin_version=1.4.0
|
||||
kotlin_coroutines_version=1.3.9
|
||||
kotlin_serialisation_runtime_version=1.0.0-RC
|
||||
|
Loading…
Reference in New Issue
Block a user