1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-10-18 22:00:23 +00:00

Merge remote-tracking branch 'upstream/0.28.0' into feature/download-pathed-file-extension

This commit is contained in:
2020-08-23 18:57:03 +06:00
520 changed files with 1130 additions and 1826 deletions

View File

@@ -1,5 +1,6 @@
# TelegramBotAPI Util Extensions
- [TelegramBotAPI Util Extensions](#telegrambotapi-util-extensions)
* [What is it?](#what-is-it)
* [How to implement library?](#how-to-implement-library)
@@ -23,7 +24,7 @@
## What is it?
It is wrapper library for [TelegramBotAPI](../TelegramBotAPI/README.md). Currently, this library contains some usefull filters for commands, updates types and different others.
It is wrapper library for [TelegramBotAPI-core](../TelegramBotAPI-core/README.md). Currently, this library contains some usefull filters for commands, updates types and different others.
## How to implement library?
@@ -93,7 +94,7 @@ updates retrieving:
* Webhooks
* Long Polling
Both of them you could use in your project using [TelegramBotAPI](../TelegramBotAPI/README.md), but here there are
Both of them you could use in your project using [TelegramBotAPI-core](../TelegramBotAPI-core/README.md), but here there are
several useful extensions for both of them.
Anyway, in both of ways it will be useful to know that it is possible to create `UpdateReceiver` object using function

View File

@@ -13,8 +13,8 @@ buildscript {
}
plugins {
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
}
project.version = "$library_version"
@@ -31,16 +31,19 @@ repositories {
kotlin {
jvm()
js()
js(BOTH) {
browser()
nodejs()
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib')
if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") {
api "${project.group}:TelegramBotAPI:$library_version"
api "${project.group}:TelegramBotAPI-core:$library_version"
} else {
api project(":TelegramBotAPI")
api project(":TelegramBotAPI-core")
}
}
}

View File

@@ -6,6 +6,6 @@ import kotlinx.serialization.json.Json
internal val nonstrictJsonFormat = Json {
isLenient = true
ignoreUnknownKeys = true
serializeSpecialFloatingPointValues = true
allowSpecialFloatingPointValues = true
useArrayPolymorphism = true
}

View File

@@ -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"

View File

@@ -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>
}
}
)

View File

@@ -8,11 +8,11 @@ import kotlinx.serialization.json.JsonElement
/**
* @return Deserialize [source] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
*/
fun Json.toTelegramUpdate(source: String) = parse(UpdateDeserializationStrategy, source)
fun Json.toTelegramUpdate(source: String) = decodeFromString(UpdateDeserializationStrategy, source)
/**
* @return Deserialize [source] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]
*/
fun Json.toTelegramUpdate(source: JsonElement) = fromJson(UpdateDeserializationStrategy, source)
fun Json.toTelegramUpdate(source: JsonElement) = decodeFromJsonElement(UpdateDeserializationStrategy, source)
/**
* @return Deserialize [this] as [com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update]. In fact,

View File

@@ -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)

View File

@@ -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()
}
/**

View File

@@ -45,8 +45,8 @@ fun Route.includeWebhookHandlingInRoute(
exceptionsHandler ?: {}
) {
val asJson =
nonstrictJsonFormat.parseJson(call.receiveText())
val update = nonstrictJsonFormat.fromJson(
nonstrictJsonFormat.parseToJsonElement(call.receiveText())
val update = nonstrictJsonFormat.decodeFromJsonElement(
UpdateDeserializationStrategy,
asJson
)