1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

total rework of requests serialization

This commit is contained in:
InsanusMokrassar 2019-12-02 14:35:37 +06:00
parent cb64f44ceb
commit 24498479a8
97 changed files with 344 additions and 160 deletions

View File

@ -2,6 +2,11 @@
## 0.19.0 ImplicitReflection removing
* Total rework of serialization for requests. Now all `SimpleRequest` children have:
* `requestSerializer` - field, which must provide serializer of current type
* `resultDeserializer` - field, which must provide opportunity to deserializer result. Previously it was a function
## 0.18.0 Raws cleaning
* Made internal and not available outside of library:

View File

@ -42,9 +42,3 @@ dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = [ disableImplicitReflectionSerializerAnnotation ]
}
}

View File

@ -9,5 +9,3 @@ gradle_bintray_plugin_version=1.8.4
project_public_name=Telegram Bot API
project_public_description=Library for Object-Oriented and type-safe work with Telegram Bot API
disableImplicitReflectionSerializerAnnotation=-Xexperimental=kotlinx.serialization.ImplicitReflectionSerializer

View File

@ -77,7 +77,7 @@ class KtorRequestsExecutor(
val responseObject = jsonFormatter.parse(Response.serializer(), content)
(responseObject.result ?.let {
jsonFormatter.fromJson(request.resultDeserializer(), it)
jsonFormatter.fromJson(request.resultDeserializer, it)
} ?: responseObject.parameters ?.let {
val error = it.error
if (error is RetryAfterError) {

View File

@ -12,12 +12,11 @@ class SimpleRequestCallFactory : AbstractRequestCallFactory() {
baseUrl: String,
request: Request<T>
): Any? = (request as? SimpleRequest<T>) ?.let { _ ->
val content = request.toJsonWithoutNulls(SimpleRequestSerializer).toString()
val content = request.json().toString()
TextContent(
content,
ContentType.Application.Json
)
}
}

View File

@ -15,5 +15,8 @@ data class DeleteMessage(
) : SimpleRequest<Boolean>, MessageAction {
override fun method(): String = "deleteMessage"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -24,5 +24,8 @@ data class ForwardMessage(
override fun method(): String = "forwardMessage"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -2,11 +2,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.User
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
class GetMe : SimpleRequest<User> {
override fun method(): String = "getMe"
override fun resultDeserializer(): KSerializer<User> = User.serializer()
override val resultDeserializer: DeserializationStrategy<User>
get() = User.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -5,10 +5,13 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutDeserialization
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
import kotlinx.serialization.internal.ArrayListSerializer
private val updatesListSerializer = ArrayListSerializer(
UpdateSerializerWithoutDeserialization
)
@Serializable
data class GetUpdates(
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
@ -18,7 +21,9 @@ data class GetUpdates(
): SimpleRequest<List<Update>> {
override fun method(): String = "getUpdates"
override fun resultDeserializer(): KSerializer<List<Update>> = ArrayListSerializer(
UpdateSerializerWithoutDeserialization
)
override val resultDeserializer: DeserializationStrategy<List<Update>>
get() = updatesListSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -18,5 +18,8 @@ data class StopPoll(
override val replyMarkup: InlineKeyboardMarkup? = null
) : MessageAction, SimpleRequest<Poll>, ReplyMarkup {
override fun method(): String = "stopPoll"
override fun resultDeserializer(): KSerializer<Poll> = Poll.serializer()
override val resultDeserializer: DeserializationStrategy<Poll>
get() = Poll.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -1,13 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject
@Serializable(RequestSerializer::class)
interface Request<T: Any> {
fun method(): String
fun resultDeserializer(): DeserializationStrategy<T>
fun json(): JsonObject = toJsonWithoutNulls(RequestSerializer)
val resultDeserializer: DeserializationStrategy<T>
}
object RequestSerializer : KSerializer<Request<*>> by ContextSerializer(Request::class)

View File

@ -1,8 +1,12 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
import kotlinx.serialization.*
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.JsonObject
@Serializable(SimpleRequestSerializer::class)
interface SimpleRequest<T: Any> : Request<T>
interface SimpleRequest<T: Any> : Request<T> {
val requestSerializer: SerializationStrategy<*>
}
object SimpleRequestSerializer : KSerializer<SimpleRequest<*>> by ContextSerializer(SimpleRequest::class)
@Suppress("UNCHECKED_CAST")
inline fun <T: Any, K: SimpleRequest<T>> K.json(): JsonObject = toJsonWithoutNulls(requestSerializer as SerializationStrategy<K>)

View File

@ -20,7 +20,10 @@ data class AnswerCallbackQuery(
val cachedTimeSeconds: Int? = null
) : SimpleRequest<Boolean> {
override fun method(): String = "answerCallbackQuery"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
fun CallbackQuery.createAnswer(

View File

@ -28,7 +28,10 @@ data class AnswerInlineQuery(
val switchPmParameter: String? = null
): SimpleRequest<Boolean> {
override fun method(): String = "answerInlineQuery"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
fun InlineQuery.createAnswer(

View File

@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerPreCheckoutQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class AnswerPreCheckoutQueryOk(
@ -13,6 +12,8 @@ data class AnswerPreCheckoutQueryOk(
) : AnswerPreCheckoutQuery {
@SerialName(okField)
override val isOk: Boolean = true
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
@ -25,6 +26,8 @@ data class AnswerPreCheckoutQueryError(
) : AnswerPreCheckoutQuery {
@SerialName(okField)
override val isOk: Boolean = false
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
fun PreCheckoutQuery.createAnswerOk(): AnswerPreCheckoutQueryOk = AnswerPreCheckoutQueryOk(

View File

@ -17,6 +17,8 @@ data class AnswerShippingQueryOk(
) : AnswerShippingQuery {
@SerialName(okField)
override val isOk: Boolean = true
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
@ -32,6 +34,8 @@ data class AnswerShippingQueryError(
) : AnswerShippingQuery {
@SerialName(okField)
override val isOk: Boolean = false
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
fun ShippingQuery.createAnswerOk(

View File

@ -3,11 +3,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.PreCheckoutQueryId
import kotlinx.serialization.KSerializer
import kotlinx.serialization.internal.BooleanSerializer
import kotlinx.serialization.serializer
interface AnswerPreCheckoutQuery : SimpleRequest<Boolean> {
override fun method(): String = "answerPreCheckoutQuery"
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
override val resultDeserializer: KSerializer<Boolean>
get() = BooleanSerializer
val preCheckoutQueryId: PreCheckoutQueryId
val isOk: Boolean

View File

@ -2,12 +2,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.ShippingQueryIdentifier
import kotlinx.serialization.KSerializer
import kotlinx.serialization.serializer
import kotlinx.serialization.*
import kotlinx.serialization.internal.BooleanSerializer
interface AnswerShippingQuery : SimpleRequest<Boolean> {
override fun method(): String = "answerShippingQuery"
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
val shippingQueryId: ShippingQueryIdentifier
val isOk: Boolean

View File

@ -13,5 +13,8 @@ data class ExportChatInviteLink(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<String> {
override fun method(): String = "exportChatInviteLink"
override fun resultDeserializer(): KSerializer<String> = StringSerializer
override val resultDeserializer: DeserializationStrategy<String>
get() = StringSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -13,5 +13,8 @@ data class LeaveChat(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "leaveChat"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -14,5 +14,8 @@ data class GetChat(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<ExtendedChat> {
override fun method(): String = "getChat"
override fun resultDeserializer(): KSerializer<ExtendedChat> = ExtendedChatSerializer
override val resultDeserializer: DeserializationStrategy<ExtendedChat>
get() = ExtendedChatSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -9,13 +9,18 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
import kotlinx.serialization.*
import kotlinx.serialization.internal.ArrayListSerializer
private val chatMembersListSerializer = ArrayListSerializer(
ChatMemberSerializerWithoutDeserialization
)
@Serializable
data class GetChatAdministrators(
@SerialName(chatIdField)
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<List<ChatMember>> {
override fun method(): String = "getChatAdministrators"
override fun resultDeserializer(): KSerializer<List<ChatMember>> = ArrayListSerializer(
ChatMemberSerializerWithoutDeserialization
)
override val resultDeserializer: DeserializationStrategy<List<ChatMember>>
get() = chatMembersListSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -13,5 +13,8 @@ data class GetChatMembersCount(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Int> {
override fun method(): String = "getChatMembersCount"
override fun resultDeserializer(): KSerializer<Int> = IntSerializer
override val resultDeserializer: DeserializationStrategy<Int>
get() = IntSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -14,5 +14,8 @@ data class GetChatMember(
override val userId: UserId
) : ChatMemberRequest<ChatMember> {
override fun method(): String = "getChatMember"
override fun resultDeserializer(): DeserializationStrategy<ChatMember> = ChatMemberDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<ChatMember>
get() = ChatMemberDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -16,5 +16,8 @@ data class KickChatMember(
override val untilDate: TelegramDate? = null
) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "kickChatMember"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -32,5 +32,8 @@ data class PromoteChatMember(
private val canPromoteMembers: Boolean? = null
) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "promoteChatMember"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -19,5 +19,8 @@ data class RestrictChatMember(
val permissions: ChatPermissions
) : ChatMemberRequest<Boolean>, UntilDate {
override fun method(): String = "restrictChatMember"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -13,5 +13,8 @@ data class UnbanChatMember(
override val userId: UserId
) : ChatMemberRequest<Boolean> {
override fun method(): String = "unbanChatMember"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -13,5 +13,8 @@ data class DeleteChatPhoto(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "deleteChatPhoto"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -16,5 +16,8 @@ data class PinChatMessage (
override val disableNotification: Boolean = false
): ChatRequest, SimpleRequest<Boolean>, MessageAction, DisableNotification {
override fun method(): String = "pinChatMessage"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -20,5 +20,8 @@ data class SetChatDescription (
}
override fun method(): String = "setChatDescription"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -15,5 +15,8 @@ data class SetChatPermissions (
val permissions: ChatPermissions
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "setChatPermissions"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -16,7 +16,8 @@ data class SetChatPhoto (
val photo: MultipartFile = throw IllegalArgumentException("Unfortunately, this type of objects can't be parsed automatically")
): ChatRequest, MultipartRequest<Boolean> {
override fun method(): String = "setChatPhoto"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
override val paramsJson: JsonObject = toJson(serializer())
}

View File

@ -20,5 +20,8 @@ data class SetChatTitle (
}
override fun method(): String = "setChatTitle"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -13,5 +13,8 @@ data class UnpinChatMessage(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "unpinChatMessage"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -13,5 +13,8 @@ data class DeleteChatStickerSet(
override val chatId: ChatIdentifier
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "deleteChatStickerSet"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -14,5 +14,8 @@ data class SetChatStickerSet(
val stickerSetName: StickerSetName
): ChatRequest, SimpleRequest<Boolean> {
override fun method(): String = "setChatStickerSet"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -4,7 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import kotlinx.serialization.json.JsonObject
data class CommonMultipartFileRequest<T: Any>(
val data: Request<T>,
val data: SimpleRequest<T>,
override val mediaMap: Map<String, MultipartFile>
) : MultipartRequest<T>, Request<T> by data {
override val paramsJson: JsonObject = data.json()

View File

@ -21,5 +21,8 @@ data class EditChatMessageLiveLocation(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage, EditLocationMessage {
override fun method(): String = "editMessageLiveLocation"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -1,10 +1,10 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption.EditInlineMessageCaption
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class EditInlineMessageLiveLocation(
@ -18,4 +18,6 @@ data class EditInlineMessageLiveLocation(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditReplyMessage, EditLocationMessage {
override fun method(): String = "editMessageLiveLocation"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -18,5 +18,8 @@ data class StopChatMessageLiveLocation(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditChatMessage, EditReplyMessage {
override fun method(): String = "stopMessageLiveLocation"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -4,8 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditIn
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class StopInlineMessageLiveLocation(
@ -15,4 +14,6 @@ data class StopInlineMessageLiveLocation(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditReplyMessage {
override fun method(): String = "stopMessageLiveLocation"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -21,5 +21,8 @@ data class EditChatMessageReplyMarkup(
) : EditChatMessage, EditReplyMessage {
override fun method(): String = editMessageReplyMarkupMethod
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -1,11 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.ReplyMarkup
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.EditInlineMessageLiveLocation
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditInlineMessage
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class EditInlineMessageReplyMarkup(
@ -15,4 +15,6 @@ data class EditInlineMessageReplyMarkup(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditReplyMessage {
override fun method(): String = editMessageReplyMarkupMethod
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -2,10 +2,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
import kotlinx.serialization.KSerializer
import kotlinx.serialization.*
import kotlinx.serialization.internal.BooleanSerializer
interface EditInlineMessage : SimpleRequest<Boolean> {
val inlineMessageId: InlineMessageIdentifier
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
}

View File

@ -26,5 +26,8 @@ data class EditChatMessageCaption(
) : EditChatMessage, EditTextChatMessage, EditReplyMessage {
override fun method(): String = editMessageCaptionMethod
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class EditInlineMessageCaption(
@ -20,4 +19,6 @@ data class EditInlineMessageCaption(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage {
override fun method(): String = editMessageCaptionMethod
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -30,5 +30,8 @@ data class EditChatMessageMedia(
}
override fun method(): String = editMessageMediaMethod
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -1,12 +1,12 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.EditInlineMessageLiveLocation
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class EditInlineMessageMedia(
@ -23,6 +23,8 @@ data class EditInlineMessageMedia(
throw IllegalArgumentException("For editing of media messages you MUST use file id (according to documentation)")
}
}
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = editMessageMediaMethod
}

View File

@ -28,5 +28,8 @@ data class EditChatMessageText(
) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
override fun method(): String = editMessageTextMethod
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -1,13 +1,13 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation.EditInlineMessageLiveLocation
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.editMessageMediaMethod
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class EditInlineMessageText(
@ -23,4 +23,6 @@ data class EditInlineMessageText(
override val replyMarkup: InlineKeyboardMarkup? = null
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
override fun method(): String = editMessageMediaMethod
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class GetGameHighScoresByChat (
@ -14,4 +13,7 @@ data class GetGameHighScoresByChat (
override val chatId: ChatId,
@SerialName(messageIdField)
override val messageId: MessageIdentifier
) : GetGameHighScores, MessageAction
) : GetGameHighScores, MessageAction {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class GetGameHighScoresByInlineMessageId (
@ -12,4 +11,7 @@ data class GetGameHighScoresByInlineMessageId (
override val userId: UserId,
@SerialName(inlineMessageIdField)
override val inlineMessageId: InlineMessageIdentifier
) : GetGameHighScores, InlineMessageAction
) : GetGameHighScores, InlineMessageAction {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class SetGameScoreByChatId (
@ -20,4 +19,7 @@ data class SetGameScoreByChatId (
override val force: Boolean = false,
@SerialName(disableEditMessageField)
override val disableEditMessage: Boolean = false
) : SetGameScore, MessageAction
) : SetGameScore, MessageAction {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
data class SetGameScoreByInlineMessageId (
@ -18,4 +17,7 @@ data class SetGameScoreByInlineMessageId (
override val force: Boolean = false,
@SerialName(disableEditMessageField)
override val disableEditMessage: Boolean = false
) : SetGameScore, InlineMessageAction
) : SetGameScore, InlineMessageAction {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
import com.github.insanusmokrassar.TelegramBotAPI.types.games.GameHighScore
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.KSerializer
import kotlinx.serialization.internal.ArrayListSerializer
@ -10,7 +11,8 @@ interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
val userId: UserId
override fun method(): String = "getGameHighScores"
override fun resultDeserializer(): KSerializer<List<GameHighScore>> = GameHighScoresSerializer
override val resultDeserializer: DeserializationStrategy<List<GameHighScore>>
get() = GameHighScoresSerializer
}
object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())

View File

@ -2,8 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
import kotlinx.serialization.KSerializer
import kotlinx.serialization.serializer
import kotlinx.serialization.*
interface SetGameScore : SimpleRequest<Boolean> {
val userId: UserId
@ -12,5 +11,6 @@ interface SetGameScore : SimpleRequest<Boolean> {
val disableEditMessage: Boolean
override fun method(): String = "setGameScore"
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
}

View File

@ -12,5 +12,8 @@ data class GetFile(
val fileId: FileId
): SimpleRequest<PathedFile> {
override fun method(): String = "getFile"
override fun resultDeserializer(): KSerializer<PathedFile> = PathedFile.serializer()
override val resultDeserializer: DeserializationStrategy<PathedFile>
get() = PathedFile.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -11,5 +11,8 @@ data class GetStickerSet(
val name: String
): SimpleRequest<StickerSet> {
override fun method(): String = "getStickerSet"
override fun resultDeserializer(): KSerializer<StickerSet> = StickerSet.serializer()
override val resultDeserializer: DeserializationStrategy<StickerSet>
get() = StickerSet.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -23,5 +23,8 @@ data class GetUserProfilePhotos(
}
override fun method(): String = "getUserProfilePhotos"
override fun resultDeserializer(): KSerializer<UserProfilePhotos> = UserProfilePhotos.serializer()
override val resultDeserializer: DeserializationStrategy<UserProfilePhotos>
get() = UserProfilePhotos.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -17,5 +17,8 @@ data class SendAction(
val action: BotAction
): SendChatMessageRequest<Boolean> {
override fun method(): String = "sendChatAction"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -44,7 +44,10 @@ data class SendContact(
)
override fun method(): String = "sendContact"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
fun Contact.toRequest(

View File

@ -30,5 +30,8 @@ data class SendLocation(
{
override fun method(): String = "sendLocation"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -38,5 +38,8 @@ data class SendMessage(
}
override fun method(): String = "sendMessage"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -40,5 +40,8 @@ data class SendPoll(
}
override fun method(): String = "sendPoll"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -51,7 +51,10 @@ data class SendVenue(
)
override fun method(): String = "sendVenue"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
fun Venue.toRequest(

View File

@ -23,5 +23,8 @@ data class SendGame (
) : SendMessageRequest<Message>,
ReplyMarkup {
override fun method(): String = "sendGame"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -95,7 +95,10 @@ data class SendAnimationData internal constructor(
}
override fun method(): String = "sendAnimation"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendAnimationFiles internal constructor(

View File

@ -97,7 +97,10 @@ data class SendAudioData internal constructor(
}
override fun method(): String = "sendAudio"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendAudioFiles internal constructor(

View File

@ -81,7 +81,10 @@ data class SendDocumentData internal constructor(
}
override fun method(): String = "sendDocument"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendDocumentFiles internal constructor(

View File

@ -53,7 +53,7 @@ fun SendMediaGroup(
}
}
private val serializer = ArrayListSerializer(TelegramBotAPIMessageDeserializeOnlySerializer)
private val messagesListSerializer = ArrayListSerializer(TelegramBotAPIMessageDeserializeOnlySerializer)
@Serializable
data class SendMediaGroupData internal constructor(
@ -64,9 +64,7 @@ data class SendMediaGroupData internal constructor(
override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField)
override val replyToMessageId: MessageIdentifier? = null
) : DataRequest<List<Message>>,
SendMessageRequest<List<Message>>
{
) : DataRequest<List<Message>>, SendMessageRequest<List<Message>> {
@SerialName(mediaField)
private val convertedMedia: String
get() = jsonArray {
@ -77,7 +75,10 @@ data class SendMediaGroupData internal constructor(
override fun method(): String = "sendMediaGroup"
override fun resultDeserializer(): DeserializationStrategy<List<Message>> = serializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<List<Message>>
get() = messagesListSerializer
}
data class SendMediaGroupFiles internal constructor(

View File

@ -67,7 +67,10 @@ data class SendPhotoData internal constructor(
}
override fun method(): String = "sendPhoto"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendPhotoFiles internal constructor(

View File

@ -44,7 +44,10 @@ data class SendStickerByFileId internal constructor(
override val replyMarkup: KeyboardMarkup? = null
) : SendMessageRequest<Message>, ReplyingMarkupSendMessageRequest<Message> {
override fun method(): String = "sendSticker"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendStickerByFile internal constructor(

View File

@ -99,7 +99,10 @@ data class SendVideoData internal constructor(
}
override fun method(): String = "sendVideo"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendVideoFiles internal constructor(

View File

@ -82,7 +82,6 @@ data class SendVideoNoteData internal constructor(
DuratedSendMessageRequest<Message>,
SizedSendMessageRequest<Message>
{
@Transient
override val height: Int?
get() = width
@ -95,7 +94,10 @@ data class SendVideoNoteData internal constructor(
}
override fun method(): String = "sendVideoNote"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendVideoNoteFiles internal constructor(

View File

@ -86,7 +86,10 @@ data class SendVoiceData internal constructor(
}
override fun method(): String = "sendVoice"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}
data class SendVoiceFiles internal constructor(

View File

@ -3,7 +3,4 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import kotlinx.serialization.*
@Serializable(DataRequestSerializer::class)
interface DataRequest<T: Any> : SimpleRequest<T>
object DataRequestSerializer : KSerializer<DataRequest<*>> by ContextSerializer(DataRequest::class)

View File

@ -1,8 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest
import kotlinx.serialization.DeserializationStrategy
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject
/**
@ -13,7 +12,8 @@ class MultipartRequestImpl<D: DataRequest<R>, F: Files, R: Any>(
val files: F
) : MultipartRequest<R> {
override fun method(): String = data.method()
override fun resultDeserializer(): DeserializationStrategy<R> = data.resultDeserializer()
override val resultDeserializer: DeserializationStrategy<R>
get() = data.resultDeserializer
override val paramsJson: JsonObject = data.json()
override val mediaMap: Map<String, MultipartFile> = files
}

View File

@ -65,7 +65,10 @@ data class SendInvoice(
ReplyMarkup,
SendMessageRequest<Message> {
override fun method(): String = "sendInvoice"
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
@SerialName(photoUrlField)
var photoUrl: String? = null

View File

@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipar
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
fun AddStickerToSet(
userId: UserId,
@ -44,5 +43,8 @@ data class AddStickerToSet internal constructor(
}
}
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "addStickerToSet"
}

View File

@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipar
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
fun CreateNewStickerSet(
userId: UserId,
@ -47,5 +46,8 @@ data class CreateNewStickerSet internal constructor(
}
}
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "createNewStickerSet"
}

View File

@ -12,5 +12,8 @@ data class DeleteStickerFromSet(
val sticker: FileId
) : SimpleRequest<Boolean> {
override fun method(): String = "deleteStickerFromSet"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -21,5 +21,8 @@ data class SetStickerPositionInSet(
}
override fun method(): String = "setStickerPositionInSet"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -24,5 +24,6 @@ data class UploadStickerFile(
override val mediaMap: Map<String, MultipartFile> = mapOf(pngStickerField to sticker)
@Transient
override val paramsJson: JsonObject = toJsonWithoutNulls(serializer())
override fun resultDeserializer(): KSerializer<File> = File.serializer()
override val resultDeserializer: DeserializationStrategy<File>
get() = File.serializer()
}

View File

@ -12,5 +12,6 @@ interface StickerSetAction : SimpleRequest<Boolean> {
val emojis: String // must be more than one
val maskPosition: MaskPosition?
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: KSerializer<Boolean>
get() = BooleanSerializer
}

View File

@ -1,13 +1,15 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.webhook
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
import kotlinx.serialization.internal.BooleanSerializer
@Serializable
class DeleteWebhook : SimpleRequest<Boolean> {
override fun method(): String = "deleteWebhook"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -2,12 +2,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.webhook
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.WebhookInfo
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
@Serializable
class GetWebhookInfo : SimpleRequest<WebhookInfo> {
override fun method(): String = "getWebhookInfo"
override fun resultDeserializer(): KSerializer<WebhookInfo> = WebhookInfo.serializer()
override val resultDeserializer: DeserializationStrategy<WebhookInfo>
get() = WebhookInfo.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
}

View File

@ -51,7 +51,10 @@ data class SetWebhook internal constructor(
val allowedUpdates: List<String>? = null
) : DataRequest<Boolean> {
override fun method(): String = "setWebhook"
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = BooleanSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
init {
maxAllowedConnections ?.let {

View File

@ -21,7 +21,6 @@ internal data class RawCallbackQuery(
@SerialName("game_short_name")
val gameShortName: String? = null
) {
@Transient
val asCallbackQuery: CallbackQuery by lazy {
when {
message != null && data != null -> MessageDataCallbackQuery(id, from, chatInstance, message, data)

View File

@ -40,7 +40,6 @@ internal data class RawChatMember(
@SerialName(canAddWebPagePreviewsField)
private val canAddWebPagePreviews: Boolean = false
) {
@Transient
val asChatMember: ChatMember by lazy {
when (status) {
"creator" -> CreatorChatMember(user)

View File

@ -17,7 +17,6 @@ internal data class RawChosenInlineResult(
@SerialName(inlineMessageIdField)
val inlineMessageId: InlineMessageIdentifier? = null
) {
@Transient
val asChosenInlineResult: ChosenInlineResult by lazy {
location ?.let {
LocationChosenInlineResult(resultId, user, location, inlineMessageId, query)

View File

@ -16,7 +16,6 @@ internal data class RawInlineQuery(
@SerialName(locationField)
val location: Location? = null
) {
@Transient
val asInlineQuery by lazy {
location ?.let {
LocationInlineQuery(id, from, query, offset, location)

View File

@ -11,7 +11,6 @@ data class ResponseParametersRaw(
) {
@Transient
private val createTime: Long = System.currentTimeMillis()
@Transient
val error: RequestError? by lazy {
when {
migrateToChatId != null -> MigrateChatId(migrateToChatId);

View File

@ -17,7 +17,6 @@ data class User(
@SerialName(languageCodeField)
private val languageCode: String? = null
) {
@Transient
val userLocale: Locale? by lazy {
languageCode ?.let {
Locale.forLanguageTag(it)

View File

@ -83,7 +83,6 @@ internal data class RawMessage(
private val reply_markup: InlineKeyboardMarkup? = null
) {
@Transient
private val content: MessageContent? by lazy {
val adaptedCaptionEntities = caption ?.let {
caption_entities ?.map {
@ -157,7 +156,6 @@ internal data class RawMessage(
}
}
@Transient
private val chatEvent: ChatEvent? by lazy {
when {
new_chat_members != null -> NewChatMembers(new_chat_members.toList())
@ -177,7 +175,6 @@ internal data class RawMessage(
}
}
@Transient
private val paymentInfo: PaymentInfo? by lazy {
when {
invoice != null -> InvoiceOfPayment(invoice)
@ -187,8 +184,6 @@ internal data class RawMessage(
}
@Transient
val asMessage: Message by lazy {
chatEvent ?.let {
chatEvent ->

View File

@ -32,7 +32,6 @@ internal data class RawUpdate constructor(
private val pre_checkout_query: PreCheckoutQuery? = null,
private val poll: Poll? = null
) {
@Transient
val asUpdate: Update by lazy {
when {
edited_message != null -> EditMessageUpdate(updateId, edited_message)

View File

@ -1,11 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.*
inline fun <reified T: Any> T.toJsonWithoutNulls(serializer: KSerializer<T>): JsonObject = toJson(serializer).withoutNulls()
inline fun <T: Any> T.toJsonWithoutNulls(serializer: SerializationStrategy<T>): JsonObject = toJson(serializer).withoutNulls()
inline fun <reified T: Any> T.toJson(serializer: KSerializer<T>): JsonObject = Json.nonstrict.toJson(
inline fun <T: Any> T.toJson(serializer: SerializationStrategy<T>): JsonObject = Json.nonstrict.toJson(
serializer,
this
).jsonObject