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

Merge pull request #136 from InsanusMokrassar/0.28.3

0.28.3
This commit is contained in:
InsanusMokrassar 2020-09-22 18:32:06 +06:00 committed by GitHub
commit 2d743e4c19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 206 additions and 26 deletions

3
.gitignore vendored
View File

@ -8,3 +8,6 @@ settings.xml
.gradle/
build/
out/
local.properties
secret.gradle

View File

@ -42,6 +42,28 @@
* `HttpClient#loadFile`
* `PathedFile#download`
### 0.28.3
* Common:
* Version updates:
* `Klock`: `0.12.0` -> `0.12.1`
* `Kotlin serialization`: `1.0.0-RC` -> `1.0.0-RC2` (dependency `kotlinx-serialization-core` was replaced with
`kotlinx-serialization-json` due to [kotlinx.serialization library update](https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md#100-rc2--2020-09-21))
* `TelegramBotAPI-core`:
* All `InlineQueryResult` has changed their type of id for more obvious relation between `InlineQueryResult#id` and
`ChosenInlineResult#resultId`: `String` -> `InlineQueryIdentifier`
* `TelegramBotAPI-extensions-utils`:
* Several extensions for updates flows based on `InlineQueryUpdate` has been added:
* `Flow<InlineQueryUpdate>#onlyBaseInlineQueriesWithUpdates`
* `Flow<InlineQueryUpdate>#onlyBaseInlineQueries`
* `Flow<InlineQueryUpdate>#onlyLocationInlineQueriesWithUpdates`
* `Flow<InlineQueryUpdate>#onlyLocationInlineQueries`
* Several extensions for updates flows based on `ChosenInlineResultUpdate` has been added:
* `Flow<ChosenInlineResultUpdate>.onlyBaseChosenInlineResultsWithUpdates`
* `Flow<ChosenInlineResultUpdate>.onlyBaseChosenInlineResults`
* `Flow<ChosenInlineResultUpdate>.onlyLocationChosenInlineResultsWithUpdates`
* `Flow<ChosenInlineResultUpdate>.onlyLocationChosenInlineResults`
### 0.28.2
* `TelegramBotAPI-extensions-utils`:

View File

@ -41,7 +41,7 @@ kotlin {
dependencies {
implementation kotlin('stdlib')
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlin_serialisation_runtime_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_serialisation_runtime_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-properties:$kotlin_serialisation_runtime_version"
api "com.soywiz.korlibs.klock:klock:$klock_version"

View File

@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
@Serializable
class InlineQueryResultArticle(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(titleField)
override val title: String,
@SerialName(inputMessageContentField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultAudioCachedImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(audioFileIdField)
override val fileId: FileId,
@SerialName(captionField)

View File

@ -13,7 +13,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultAudioImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(audioUrlField)
override val url: String,
@SerialName(titleField)

View File

@ -11,7 +11,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultContact(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(phoneNumberField)
override val phoneNumber: String,
@SerialName(firstNameField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultDocumentCachedImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(documentFileIdField)
override val fileId: FileId,
@SerialName(titleField)

View File

@ -15,7 +15,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultDocumentImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(documentUrlField)
override val url: String,
@SerialName(titleField)

View File

@ -1,6 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueryIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.gameShortNameField
import kotlinx.serialization.SerialName
@ -8,7 +9,7 @@ import kotlinx.serialization.Serializable
@Serializable
class InlineQueryResultGame(
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(gameShortNameField)
val gameShortName: String,
override val replyMarkup: InlineKeyboardMarkup? = null

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultGifCachedImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(gifFileIdField)
override val fileId: FileId,
@SerialName(titleField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultGifImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(gifUrlField)
override val url: String,
@SerialName(thumbUrlField)

View File

@ -12,7 +12,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultLocation(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(latitudeField)
override val latitude: Double,
@SerialName(longitudeField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultMpeg4GifCachedImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(mpeg4GifFileIdField)
override val fileId: FileId,
@SerialName(titleField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultMpeg4GifImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(mpeg4GifUrlField)
override val url: String,
@SerialName(thumbUrlField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultPhotoCachedImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(photoFileIdField)
override val fileId: FileId,
@SerialName(titleField)

View File

@ -13,7 +13,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultPhotoImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(photoUrlField)
override val url: String,
@SerialName(thumbUrlField)

View File

@ -11,7 +11,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultStickerCached(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(stickerFileIdField)
override val fileId: FileId,
@SerialName(replyMarkupField)

View File

@ -12,7 +12,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultVenue(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(latitudeField)
override val latitude: Double,
@SerialName(longitudeField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultVideoCachedImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(videoFileIdField)
override val fileId: FileId,
@SerialName(titleField)

View File

@ -15,7 +15,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultVideoImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(videoUrlField)
override val url: String,
@SerialName(thumbUrlField)

View File

@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultVoiceCachedImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(voiceFileIdField)
override val fileId: FileId,
@SerialName(titleField)

View File

@ -13,7 +13,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class InlineQueryResultVoiceImpl(
@SerialName(idField)
override val id: String,
override val id: InlineQueryIdentifier,
@SerialName(voiceUrlField)
override val url: String,
@SerialName(titleField)

View File

@ -1,12 +1,13 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.serializers.InlineQueryResultSerializer
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueryIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.Serializable
@Serializable(InlineQueryResultSerializer::class)
interface InlineQueryResult {
val type: String
val id: String
val id: InlineQueryIdentifier
val replyMarkup: InlineKeyboardMarkup?
}

View File

@ -8,6 +8,7 @@ internal val nonstrictJsonFormat = Json {
ignoreUnknownKeys = true
allowSpecialFloatingPointValues = true
useArrayPolymorphism = true
encodeDefaults = true
}
fun <T: Any> T.toJsonWithoutNulls(serializer: SerializationStrategy<T>): JsonObject = toJson(serializer).withoutNulls()

View File

@ -13,6 +13,7 @@ private val nonstrictJsonFormat = Json {
ignoreUnknownKeys = true
allowSpecialFloatingPointValues = true
useArrayPolymorphism = true
encodeDefaults = true
}
class SimpleInputFilesTest {

View File

@ -2,4 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI
import kotlinx.serialization.json.Json
val TestsJsonFormat = Json {}
val TestsJsonFormat = Json {
encodeDefaults = true
}

View File

@ -8,4 +8,5 @@ internal val nonstrictJsonFormat = Json {
ignoreUnknownKeys = true
allowSpecialFloatingPointValues = true
useArrayPolymorphism = true
encodeDefaults = true
}

View File

@ -8,4 +8,5 @@ internal val nonstrictJsonFormat = Json {
ignoreUnknownKeys = true
allowSpecialFloatingPointValues = true
useArrayPolymorphism = true
encodeDefaults = true
}

View File

@ -0,0 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.internal_utils
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
internal inline fun <reified T : Any, UT : Update> Flow<UT>.onlySpecifiedTypeOfDataWithUpdates(): Flow<Pair<UpdateIdentifier, T>> {
return mapNotNull {
it.updateId to (it.data as? T ?: return@mapNotNull null)
}
}
internal inline fun <reified T : Any, UT : Update> Flow<UT>.onlySpecifiedTypeOfData(): Flow<T> {
return mapNotNull { it as? T }
}

View File

@ -0,0 +1,36 @@
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.internal_utils.onlySpecifiedTypeOfData
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.internal_utils.onlySpecifiedTypeOfDataWithUpdates
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.ChosenInlineResult.BaseChosenInlineResult
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.ChosenInlineResult.LocationChosenInlineResult
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.update.ChosenInlineResultUpdate
import com.github.insanusmokrassar.TelegramBotAPI.types.update.InlineQueryUpdate
import kotlinx.coroutines.flow.Flow
/**
* @return Mapped [Flow] with [Pair]s. [Pair.first] in this pair will be [UpdateIdentifier]. It could be useful in
* cases you are using [InlineQueryUpdate.updateId] for some reasons. [Pair.second] will always be [BaseChosenInlineResult].
*/
fun Flow<ChosenInlineResultUpdate>.onlyBaseChosenInlineResultsWithUpdates(): Flow<Pair<UpdateIdentifier, BaseChosenInlineResult>> = onlySpecifiedTypeOfDataWithUpdates()
/**
* @return Filter updates only with [BaseChosenInlineResult] and map it to a [Flow] with values [BaseChosenInlineResult]
*
* @see onlyBaseChosenInlineResultsWithUpdates
*/
fun Flow<ChosenInlineResultUpdate>.onlyBaseChosenInlineResults(): Flow<BaseChosenInlineResult> = onlySpecifiedTypeOfData()
/**
* @return Mapped [Flow] with [Pair]s. [Pair.first] in this pair will be [UpdateIdentifier]. It could be useful in
* cases you are using [InlineQueryUpdate.updateId] for some reasons. [Pair.second] will always be [LocationChosenInlineResult].
*/
fun Flow<ChosenInlineResultUpdate>.onlyLocationChosenInlineResultsWithUpdates(): Flow<Pair<UpdateIdentifier, LocationChosenInlineResult>> = onlySpecifiedTypeOfDataWithUpdates()
/**
* @return Filter updates only with [LocationChosenInlineResult] and map it to a [Flow] with values [LocationChosenInlineResult]
*
* @see onlyLocationChosenInlineResultsWithUpdates
*/
fun Flow<ChosenInlineResultUpdate>.onlyLocationChosenInlineResults(): Flow<LocationChosenInlineResult> = onlySpecifiedTypeOfData()

View File

@ -0,0 +1,35 @@
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.internal_utils.onlySpecifiedTypeOfData
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.internal_utils.onlySpecifiedTypeOfDataWithUpdates
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.query.BaseInlineQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.query.LocationInlineQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.update.InlineQueryUpdate
import kotlinx.coroutines.flow.*
/**
* @return Mapped [Flow] with [Pair]s. [Pair.first] in this pair will be [UpdateIdentifier]. It could be useful in
* cases you are using [InlineQueryUpdate.updateId] for some reasons. [Pair.second] will always be [BaseInlineQuery].
*/
fun Flow<InlineQueryUpdate>.onlyBaseInlineQueriesWithUpdates(): Flow<Pair<UpdateIdentifier, BaseInlineQuery>> = onlySpecifiedTypeOfDataWithUpdates()
/**
* @return Filter updates only with [BaseInlineQuery] and map it to a [Flow] with values [BaseInlineQuery]
*
* @see onlyBaseInlineQueriesWithUpdates
*/
fun Flow<InlineQueryUpdate>.onlyBaseInlineQueries(): Flow<BaseInlineQuery> = onlySpecifiedTypeOfData()
/**
* @return Mapped [Flow] with [Pair]s. [Pair.first] in this pair will be [UpdateIdentifier]. It could be useful in
* cases you are using [InlineQueryUpdate.updateId] for some reasons. [Pair.second] will always be [LocationInlineQuery].
*/
fun Flow<InlineQueryUpdate>.onlyLocationInlineQueriesWithUpdates(): Flow<Pair<UpdateIdentifier, LocationInlineQuery>> = onlySpecifiedTypeOfDataWithUpdates()
/**
* @return Filter updates only with [LocationInlineQuery] and map it to a [Flow] with values [LocationInlineQuery]
*
* @see onlyLocationInlineQueriesWithUpdates
*/
fun Flow<InlineQueryUpdate>.onlyLocationInlineQueries(): Flow<LocationInlineQuery> = onlySpecifiedTypeOfData()

View File

@ -3,12 +3,14 @@ buildscript {
mavenLocal()
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
}
}
@ -16,3 +18,31 @@ plugins {
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version" apply false
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" apply false
}
private String getCurrentVersionChangelog() {
OutputStream changelogDataOS = new ByteArrayOutputStream()
exec {
standardOutput = changelogDataOS
commandLine './changelog_info_retriever', "$library_version", 'CHANGELOG.md'
}
return changelogDataOS.toString().trim()
}
if (new File(projectDir, "secret.gradle").exists()) {
apply from: './secret.gradle'
apply plugin: "com.github.breadmoirai.github-release"
githubRelease {
token "${project.property('GITHUB_RELEASE_TOKEN')}"
owner "InsanusMokrassar"
repo "TelegramBotAPI"
tagName "$library_version"
releaseName "$library_version"
targetCommitish "$library_version"
body getCurrentVersionChangelog()
}
}

29
changelog_info_retriever Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
function parse() {
version=$1
read -r
while [ -z "`echo $REPLY | grep -e "^#\+ $version"`" ]
do
read -r
done
read -r
while [ -z "`echo $REPLY | grep -e "^#\+"`" ]
do
echo "$REPLY"
read -r
done
}
version=$1
file=$2
if [ -n "$file" ]; then
parse $version < "$file"
else
parse $version
fi

View File

@ -7,14 +7,15 @@ kotlin.incremental.js=true
kotlin_version=1.4.10
kotlin_coroutines_version=1.3.9
kotlin_serialisation_runtime_version=1.0.0-RC
klock_version=1.12.0
kotlin_serialisation_runtime_version=1.0.0-RC2
klock_version=1.12.1
uuid_version=0.2.2
ktor_version=1.4.0
javax_activation_version=1.1.1
library_group=com.github.insanusmokrassar
library_version=0.28.2
library_version=0.28.3
gradle_bintray_plugin_version=1.8.5
github_release_plugin_version=2.2.12