1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

fix of build and add annotation to all fields with one

This commit is contained in:
InsanusMokrassar 2024-01-09 17:52:13 +06:00
parent aa315f6fec
commit 0013e91f6e
22 changed files with 62 additions and 13 deletions

View File

@ -16,6 +16,9 @@ kotlin {
api project(":tgbotapi.core")
}
}
configureEach {
languageSettings.optIn("kotlinx.serialization.ExperimentalSerializationApi")
}
}
}

View File

@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.DeleteMessages
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import kotlin.jvm.JvmName
suspend fun TelegramBot.deleteMessages(
chatId: ChatIdentifier,
@ -44,6 +45,7 @@ suspend fun TelegramBot.deleteMessages(
)
}.all { it }
@JvmName("deleteMessagesWithMessages")
suspend fun TelegramBot.deleteMessages(
messages: List<AccessibleMessage>
) = deleteMessages(messages.map { it.metaInfo })
@ -70,6 +72,7 @@ suspend fun TelegramBot.delete(
messagesMetas: List<Message.MetaInfo>
) = deleteMessages(messagesMetas)
@JvmName("deleteWithMessages")
suspend fun TelegramBot.delete(
messages: List<AccessibleMessage>
) = deleteMessages(messages)

View File

@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.requests.ForwardMessages
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import kotlin.jvm.JvmName
suspend fun TelegramBot.forwardMessages(
toChatId: ChatIdentifier,
@ -85,6 +86,7 @@ suspend fun TelegramBot.forwardMessages(
)
}
@JvmName("forwardMessagesWithMessages")
suspend fun TelegramBot.forwardMessages(
toChatId: ChatIdentifier,
messages: List<AccessibleMessage>,
@ -173,6 +175,7 @@ suspend fun TelegramBot.forward(
removeCaption = removeCaption
)
@JvmName("forwardWithMessages")
suspend fun TelegramBot.forward(
toChatId: ChatIdentifier,
messages: List<AccessibleMessage>,

View File

@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.send.CopyMessages
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import kotlin.jvm.JvmName
suspend fun TelegramBot.copyMessages(
toChatId: ChatIdentifier,
@ -84,6 +85,7 @@ suspend fun TelegramBot.copyMessages(
)
}
@JvmName("copyMessagesWithMessages")
suspend fun TelegramBot.copyMessages(
toChatId: ChatIdentifier,
messages: List<AccessibleMessage>,
@ -172,6 +174,7 @@ suspend fun TelegramBot.copy(
removeCaption = removeCaption
)
@JvmName("copyWithMessages")
suspend fun TelegramBot.copy(
toChatId: ChatIdentifier,
messages: List<AccessibleMessage>,

View File

@ -98,6 +98,7 @@ data class MultipartFile (
private val inputSource: () -> Input
) : InputFile() {
@Required
@EncodeDefault
override val fileId: String = "${uuid4()}.${filename.fileExtension}"
val input: Input
get() = inputSource()

View File

@ -112,6 +112,7 @@ data class CreateChatInviteLinkWithJoinRequest(
override val expirationUnixTimeStamp: TelegramDate? = null,
) : CreateChatInviteLink<ChatInviteLinkWithJoinRequest>, WithJoinRequestChatInviteLinkRequest {
@Required
@EncodeDefault
@SerialName(createsJoinRequestField)
private val createsJoinRequest: Boolean = true

View File

@ -126,6 +126,7 @@ data class EditChatInviteLinkWithJoinRequest(
) : EditChatInviteLink<ChatInviteLinkWithJoinRequest>,
WithJoinRequestChatInviteLinkRequest {
@Required
@EncodeDefault
@SerialName(createsJoinRequestField)
private val createsJoinRequest: Boolean = true

View File

@ -9,13 +9,15 @@ import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*
@Serializable(MenuButtonSerializer::class)
@OptIn(ExperimentalSerializationApi::class)
sealed interface MenuButton {
@Required
@EncodeDefault
val type: String
@Serializable
object Commands : MenuButton {
@Required
@EncodeDefault
override val type: String
get() = "commands"
}
@ -27,6 +29,7 @@ sealed interface MenuButton {
val webApp: WebAppInfo
) : MenuButton {
@Required
@EncodeDefault
override val type: String
get() = Companion.type
@ -39,6 +42,7 @@ sealed interface MenuButton {
@Serializable
object Default : MenuButton {
@Required
@EncodeDefault
override val type: String
get() = "default"
}

View File

@ -4,10 +4,7 @@ import dev.inmo.tgbotapi.abstracts.WithMessageId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PreviewUser
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Required
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@ -31,6 +28,7 @@ sealed interface ChatBoostSource {
override val user: PreviewUser
) : ByUser {
@Required
@EncodeDefault
@SerialName(sourceField)
override val sourceName: String = sourceCode
@ -45,6 +43,7 @@ sealed interface ChatBoostSource {
override val user: PreviewUser
) : ByUser {
@Required
@EncodeDefault
@SerialName(sourceField)
override val sourceName: String = sourceCode
@ -67,9 +66,11 @@ sealed interface ChatBoostSource {
override val user: PreviewUser
) : Giveaway, ByUser {
@Required
@EncodeDefault
@SerialName(sourceField)
override val sourceName: String = Giveaway.sourceCode
@Required
@EncodeDefault
@SerialName(isUnclaimedField)
override val unclaimed: Boolean = false
}
@ -80,9 +81,11 @@ sealed interface ChatBoostSource {
override val messageId: MessageId
) : Giveaway {
@Required
@EncodeDefault
@SerialName(sourceField)
override val sourceName: String = Giveaway.sourceCode
@Required
@EncodeDefault
@SerialName(isUnclaimedField)
override val unclaimed: Boolean = true
@SerialName(userField)
@ -104,6 +107,7 @@ sealed interface ChatBoostSource {
@Serializable
private data class Surrogate(
@Required
@EncodeDefault
@SerialName(sourceField)
val sourceName: String,
@SerialName(userField)

View File

@ -65,6 +65,7 @@ data class RequestLocationKeyboardButton(
) : KeyboardButton {
@SerialName(requestLocationField)
@Required
@EncodeDefault
val requestLocation: Boolean = true
}

View File

@ -11,6 +11,7 @@ data class ReplyForce(
) : KeyboardMarkup {
@SerialName(forceReplyField)
@Required
@EncodeDefault
val forceReply: Boolean = true
companion object {

View File

@ -8,5 +8,6 @@ data class ReplyKeyboardRemove(
) : KeyboardMarkup {
@SerialName("remove_keyboard")
@Required
@EncodeDefault
val removeKeyboard: Boolean = true
}

View File

@ -45,5 +45,6 @@ data class AdministratorChatMemberImpl(
) : AdministratorChatMember {
@SerialName(statusField)
@Required
@EncodeDefault
override val status: ChatMember.Status = ChatMember.Status.Administrator
}

View File

@ -13,5 +13,6 @@ data class KickedChatMember(
) : BannedChatMember {
@SerialName(statusField)
@Required
@EncodeDefault
override val status: ChatMember.Status = ChatMember.Status.Kicked
}

View File

@ -11,5 +11,6 @@ data class LeftChatMemberImpl(
) : LeftChatMember {
@SerialName(statusField)
@Required
@EncodeDefault
override val status: ChatMember.Status = ChatMember.Status.Left
}

View File

@ -11,5 +11,6 @@ data class MemberChatMemberImpl(
) : MemberChatMember {
@SerialName(statusField)
@Required
@EncodeDefault
override val status: ChatMember.Status = ChatMember.Status.Member
}

View File

@ -45,5 +45,6 @@ data class OwnerChatMember(
@SerialName(statusField)
@Required
@EncodeDefault
override val status: ChatMember.Status = ChatMember.Status.Creator
}

View File

@ -44,5 +44,6 @@ data class RestrictedChatMember(
) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
@SerialName(statusField)
@Required
@EncodeDefault
override val status: ChatMember.Status = ChatMember.Status.Restricted
}

View File

@ -71,24 +71,28 @@ data class UnknownBotCommandScope internal constructor(
@Serializable
object BotCommandScopeDefault : BotCommandScope {
@Required
@EncodeDefault
override val type: String = "default"
}
@Serializable
object BotCommandScopeAllPrivateChats : BotCommandScope {
@Required
@EncodeDefault
override val type: String = "all_private_chats"
}
@Serializable
object BotCommandScopeAllGroupChats : BotCommandScope {
@Required
@EncodeDefault
override val type: String = "all_group_chats"
}
@Serializable
object BotCommandScopeAllChatAdministrators : BotCommandScope {
@Required
@EncodeDefault
override val type: String = "all_chat_administrators"
}
@ -102,6 +106,7 @@ data class BotCommandScopeChatAdministrators(
override val chatId: ChatIdentifier
) : ChatBotCommandScope {
@Required
@EncodeDefault
override val type: String = BotCommandScopeChatAdministrators.type
companion object {
const val type = "chat_administrators"
@ -113,6 +118,7 @@ data class BotCommandScopeChat(
override val chatId: ChatIdentifier
) : ChatBotCommandScope {
@Required
@EncodeDefault
override val type: String = BotCommandScopeChat.type
companion object {
const val type = "chat"
@ -125,6 +131,7 @@ data class BotCommandScopeChatMember(
val userId: UserId
) : ChatBotCommandScope {
@Required
@EncodeDefault
override val type: String = BotCommandScopeChatMember.type
companion object {
const val type = "chat_member"

View File

@ -4,10 +4,7 @@ import dev.inmo.tgbotapi.abstracts.WithPreviewChatAndMessageId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.PreviewChat
import dev.inmo.tgbotapi.types.chat.PreviewUser
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Required
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@ -32,6 +29,7 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
) : GiveawayPublicResults {
@SerialName(wasRefundedField)
@Required
@EncodeDefault
override val refunded: Boolean = true
@SerialName(winnersCountField)
override val count: Int = 0
@ -78,6 +76,7 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
) : GiveawayPublicResults {
@SerialName(wasRefundedField)
@Required
@EncodeDefault
override val refunded: Boolean = false
}

View File

@ -2,10 +2,7 @@ package dev.inmo.tgbotapi.types.message
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Required
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@ -27,6 +24,7 @@ sealed interface MessageOrigin {
) : MessageOrigin {
@SerialName(typeField)
@Required
@EncodeDefault
override val type: String = Companion.type
companion object {
@ -43,6 +41,7 @@ sealed interface MessageOrigin {
) : MessageOrigin {
@SerialName(typeField)
@Required
@EncodeDefault
override val type: String = Companion.type
companion object {
@ -66,6 +65,7 @@ sealed interface MessageOrigin {
) : Public {
@SerialName(typeField)
@Required
@EncodeDefault
override val type: String = Companion.type
companion object {
@ -86,6 +86,7 @@ sealed interface MessageOrigin {
) : Public {
@SerialName(typeField)
@Required
@EncodeDefault
override val type: String = Companion.type
companion object {
@ -105,6 +106,7 @@ sealed interface MessageOrigin {
private data class Surrogate(
@SerialName(typeField)
@Required
@EncodeDefault
val type: String,
@SerialName(senderChatField)
val senderChat: PreviewChat? = null,

View File

@ -100,6 +100,7 @@ data class PassportElementErrorDataField(
) : PassportSingleElementError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = dataField
}
fun EncryptedPassportElementWithData.createDataError(field: String, message: String) = PassportElementErrorDataField(
@ -121,6 +122,7 @@ data class PassportElementErrorFrontSide(
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = frontSideField
}
fun EncryptedPassportElementWithFrontSide.createFrontSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFrontSide(
@ -141,6 +143,7 @@ data class PassportElementErrorReverseSide(
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = reverseSideField
}
fun EncryptedPassportElementWithReverseSide.createReverseSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorReverseSide(
@ -160,6 +163,7 @@ data class PassportElementErrorSelfie(
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = selfieField
}
fun EncryptedPassportElementWithSelfie.createSelfieError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorSelfie(
@ -181,6 +185,7 @@ data class PassportElementErrorFile(
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = fileField
}
fun EncryptedPassportElementWithFilesCollection.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFile(
@ -200,6 +205,7 @@ data class PassportElementErrorFiles(
) : PassportElementFilesError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = filesField
}
fun EncryptedPassportElementWithFilesCollection.createFilesError(message: String, unencryptedFileHashes: List<PassportElementHash>) = PassportElementErrorFiles(
@ -221,6 +227,7 @@ data class PassportElementErrorTranslationFile(
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = translationFileField
}
fun EncryptedPassportElementTranslatable.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorTranslationFile(
@ -239,6 +246,7 @@ data class PassportElementErrorTranslationFiles(
) : PassportElementFilesError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = translationFilesField
}
fun EncryptedPassportElementTranslatable.createFilesError(message: String, unencryptedFileHashes: List<PassportElementHash>) = PassportElementErrorTranslationFiles(
@ -259,6 +267,7 @@ data class PassportElementErrorUnspecified(
) : PassportElementFileError() {
@SerialName(sourceField)
@Required
@EncodeDefault
override val source: String = unspecifiedField
}
fun EncryptedPassportElement.createUnspecifiedError(message: String, elementHash: PassportElementHash) = PassportElementErrorUnspecified(