mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 11:38:45 +00:00
commit
d3a6978f4f
11
CHANGELOG.md
11
CHANGELOG.md
@ -38,6 +38,17 @@
|
|||||||
* `UpdatesFilter` and other objects now work with `UpdateReceiver<Update>` as common supertype
|
* `UpdatesFilter` and other objects now work with `UpdateReceiver<Update>` as common supertype
|
||||||
for receivers.
|
for receivers.
|
||||||
|
|
||||||
|
### 0.12.3 Cleaning
|
||||||
|
|
||||||
|
* Refactor, optimizing and cleaning of code
|
||||||
|
* Removed deprecated method `T#toJsonWithoutNulls()`
|
||||||
|
* Renamed instances of `MediaGroupMessage`s and refactored their interfaces. `ChannelMediaGroupMessage`
|
||||||
|
will not contain `user` field (but `CommonMediaGroupMessage` will have)
|
||||||
|
* Now `MediaCollectionContent` is `MediaContent` (classes of this interface must choose best
|
||||||
|
media for present out)
|
||||||
|
* `PhotoContent` now choose biggest photo size from its collection as `media`
|
||||||
|
* Fix in order of media group messages which was received by webhooks
|
||||||
|
|
||||||
## 0.11.0
|
## 0.11.0
|
||||||
|
|
||||||
* Kotlin `1.3.11` -> `1.3.21`
|
* Kotlin `1.3.11` -> `1.3.21`
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
project.version = "0.12.2"
|
project.version = "0.12.3"
|
||||||
project.group = "com.github.insanusmokrassar"
|
project.group = "com.github.insanusmokrassar"
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
@ -7,4 +7,7 @@ ktor_version=1.1.2
|
|||||||
|
|
||||||
gradle_bintray_plugin_version=1.8.4
|
gradle_bintray_plugin_version=1.8.4
|
||||||
|
|
||||||
|
project_public_name=Telegram Bot API
|
||||||
|
project_public_description=It is one more project which wish to be useful and full Telegram Bots API bridge for Kotlin
|
||||||
|
|
||||||
disableImplicitReflectionSerializerAnnotation=-Xexperimental=kotlinx.serialization.ImplicitReflectionSerializer
|
disableImplicitReflectionSerializerAnnotation=-Xexperimental=kotlinx.serialization.ImplicitReflectionSerializer
|
||||||
|
@ -1,26 +1,6 @@
|
|||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
apply plugin: 'signing'
|
apply plugin: 'signing'
|
||||||
|
|
||||||
def pomConfig = {
|
|
||||||
licenses {
|
|
||||||
license {
|
|
||||||
name "The Apache Software License, Version 2.0"
|
|
||||||
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
|
|
||||||
distribution "repo"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
developers {
|
|
||||||
developer {
|
|
||||||
name "Ovsiannikov Aleksei"
|
|
||||||
email "ovsyannikov.alexey95@gmail.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scm {
|
|
||||||
url "https://github.com/InsanusMokrassar/${project.name}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task sourcesJar(type: Jar) {
|
task sourcesJar(type: Jar) {
|
||||||
from sourceSets.main.allSource
|
from sourceSets.main.allSource
|
||||||
classifier = 'sources'
|
classifier = 'sources'
|
||||||
@ -45,8 +25,8 @@ publishing {
|
|||||||
pom.withXml {
|
pom.withXml {
|
||||||
asNode().children().last() + {
|
asNode().children().last() + {
|
||||||
resolveStrategy = Closure.DELEGATE_FIRST
|
resolveStrategy = Closure.DELEGATE_FIRST
|
||||||
name 'Telegram Bot API'
|
name "${project_public_name}"
|
||||||
description 'It is one more project which wish to be useful and full Telegram Bots API bridge for Kotlin'
|
description "${project_public_description}"
|
||||||
url "https://insanusmokrassar.github.io/${project.name}"
|
url "https://insanusmokrassar.github.io/${project.name}"
|
||||||
|
|
||||||
scm {
|
scm {
|
||||||
|
@ -11,10 +11,8 @@ import io.ktor.client.request.forms.MultiPartFormDataContent
|
|||||||
import io.ktor.client.request.forms.formData
|
import io.ktor.client.request.forms.formData
|
||||||
import io.ktor.client.request.url
|
import io.ktor.client.request.url
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
|
|
||||||
class MultipartRequestCallFactory : KtorCallFactory {
|
class MultipartRequestCallFactory : KtorCallFactory {
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
override suspend fun <T: Any> prepareCall(
|
override suspend fun <T: Any> prepareCall(
|
||||||
client: HttpClient,
|
client: HttpClient,
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
|
@ -11,10 +11,8 @@ import io.ktor.client.request.url
|
|||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
import io.ktor.http.HttpMethod
|
import io.ktor.http.HttpMethod
|
||||||
import io.ktor.http.content.TextContent
|
import io.ktor.http.content.TextContent
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
|
|
||||||
class SimpleRequestCallFactory : KtorCallFactory {
|
class SimpleRequestCallFactory : KtorCallFactory {
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
override suspend fun <T: Any> prepareCall(
|
override suspend fun <T: Any> prepareCall(
|
||||||
client: HttpClient,
|
client: HttpClient,
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.common
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.common
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
|
||||||
data class CommonMultipartFileRequest<T: Any>(
|
data class CommonMultipartFileRequest<T: Any>(
|
||||||
val data: Request<T>,
|
val data: Request<T>,
|
||||||
override val mediaMap: Map<String, MultipartFile>
|
override val mediaMap: Map<String, MultipartFile>
|
||||||
) : MultipartRequest<T>, Request<T> by data {
|
) : MultipartRequest<T>, Request<T> by data {
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
override val paramsJson: JsonObject = data.json()
|
override val paramsJson: JsonObject = data.json()
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
|
||||||
@ -15,7 +14,6 @@ class MultipartRequestImpl<D: DataRequest<R>, F: Files, R: Any>(
|
|||||||
) : MultipartRequest<R> {
|
) : MultipartRequest<R> {
|
||||||
override fun method(): String = data.method()
|
override fun method(): String = data.method()
|
||||||
override fun resultSerializer(): KSerializer<R> = data.resultSerializer()
|
override fun resultSerializer(): KSerializer<R> = data.resultSerializer()
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
override val paramsJson: JsonObject = data.json()
|
override val paramsJson: JsonObject = data.json()
|
||||||
override val mediaMap: Map<String, MultipartFile> = files
|
override val mediaMap: Map<String, MultipartFile> = files
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Messag
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
data class MediaGroupMessage(
|
data class ChannelMediaGroupMessage(
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
override val chat: Chat,
|
override val chat: Chat,
|
||||||
override val date: DateTime,
|
override val date: DateTime,
|
||||||
@ -17,4 +17,4 @@ data class MediaGroupMessage(
|
|||||||
override val editDate: DateTime?,
|
override val editDate: DateTime?,
|
||||||
override val forwarded: ForwardedMessage?,
|
override val forwarded: ForwardedMessage?,
|
||||||
override val replyTo: Message?
|
override val replyTo: Message?
|
||||||
) : Message, MediaGroupMessage
|
) : MediaGroupMessage
|
@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
@ -17,4 +16,4 @@ data class CommonMediaGroupMessage(
|
|||||||
override val editDate: DateTime?,
|
override val editDate: DateTime?,
|
||||||
override val forwarded: ForwardedMessage?,
|
override val forwarded: ForwardedMessage?,
|
||||||
override val replyTo: Message?
|
override val replyTo: Message?
|
||||||
) : Message, MediaGroupMessage, FromUserMessage
|
) : MediaGroupMessage, FromUserMessage
|
||||||
|
@ -210,7 +210,7 @@ data class RawMessage(
|
|||||||
content ->
|
content ->
|
||||||
media_group_id ?.let {
|
media_group_id ?.let {
|
||||||
when (from) {
|
when (from) {
|
||||||
null -> MediaGroupMessage(
|
null -> ChannelMediaGroupMessage(
|
||||||
messageId,
|
messageId,
|
||||||
chat,
|
chat,
|
||||||
date.asDate,
|
date.asDate,
|
||||||
|
@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstrac
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile
|
||||||
|
|
||||||
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent {
|
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent, MediaContent<T> {
|
||||||
val media: List<T>
|
val mediaCollection: List<T>
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstract
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
|
||||||
|
|
||||||
data class PhotoContent(
|
data class PhotoContent(
|
||||||
override val media: List<PhotoSize>,
|
override val mediaCollection: List<PhotoSize>,
|
||||||
override val caption: String? = null,
|
override val caption: String? = null,
|
||||||
override val captionEntities: List<MessageEntity> = emptyList()
|
override val captionEntities: List<MessageEntity> = emptyList()
|
||||||
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent {
|
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent {
|
||||||
|
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
|
||||||
|
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
disableNotification: Boolean,
|
disableNotification: Boolean,
|
||||||
@ -27,7 +29,7 @@ data class PhotoContent(
|
|||||||
replyMarkup: KeyboardMarkup?
|
replyMarkup: KeyboardMarkup?
|
||||||
): Request<RawMessage> = SendPhoto(
|
): Request<RawMessage> = SendPhoto(
|
||||||
chatId,
|
chatId,
|
||||||
media.biggest() ?.fileId ?: throw IllegalStateException("Empty list of media"),
|
media.fileId,
|
||||||
toMarkdownCaptions().firstOrNull(),
|
toMarkdownCaptions().firstOrNull(),
|
||||||
MarkdownParseMode,
|
MarkdownParseMode,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
@ -36,7 +38,7 @@ data class PhotoContent(
|
|||||||
)
|
)
|
||||||
|
|
||||||
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
|
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
|
||||||
media.biggest() ?.fileId ?: throw IllegalStateException("Can't locate any photo size for this content"),
|
media.fileId,
|
||||||
toMarkdownCaptions().firstOrNull(),
|
toMarkdownCaptions().firstOrNull(),
|
||||||
MarkdownParseMode
|
MarkdownParseMode
|
||||||
)
|
)
|
||||||
|
@ -5,11 +5,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate
|
||||||
|
|
||||||
fun List<BaseMessageUpdate>.toMediaGroupUpdate(): MediaGroupUpdate? = (this as? MediaGroupUpdate) ?: let {
|
fun List<BaseMessageUpdate>.toMediaGroupUpdate(): MediaGroupUpdate? = (this as? MediaGroupUpdate) ?: let {
|
||||||
|
val resultList = sortedBy { it.updateId }
|
||||||
when (first()) {
|
when (first()) {
|
||||||
is MessageUpdate -> MessageMediaGroupUpdate(this)
|
is MessageUpdate -> MessageMediaGroupUpdate(resultList)
|
||||||
is EditMessageUpdate -> EditMessageMediaGroupUpdate(this)
|
is EditMessageUpdate -> EditMessageMediaGroupUpdate(resultList)
|
||||||
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(this)
|
is ChannelPostUpdate -> ChannelPostMediaGroupUpdate(resultList)
|
||||||
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(this)
|
is EditChannelPostUpdate -> EditChannelPostMediaGroupUpdate(resultList)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
|
||||||
@Deprecated("This method can throw exceptions")
|
|
||||||
@ImplicitReflectionSerializer
|
|
||||||
inline fun <reified T: Any> T.toJsonWithoutNulls(): JsonObject = Json.nonstrict.toJson(
|
|
||||||
this
|
|
||||||
).jsonObject.withoutNulls()
|
|
||||||
|
|
||||||
inline fun <reified T: Any> T.toJsonWithoutNulls(serializer: KSerializer<T>): JsonObject = toJson(serializer).withoutNulls()
|
inline fun <reified T: Any> T.toJsonWithoutNulls(serializer: KSerializer<T>): JsonObject = toJson(serializer).withoutNulls()
|
||||||
|
|
||||||
inline fun <reified T: Any> T.toJson(serializer: KSerializer<T>): JsonObject = Json.nonstrict.toJson(
|
inline fun <reified T: Any> T.toJson(serializer: KSerializer<T>): JsonObject = Json.nonstrict.toJson(
|
||||||
|
Loading…
Reference in New Issue
Block a user