From 224341c9716577fa38ff7eec0e8456317e77d45d Mon Sep 17 00:00:00 2001 From: Omar Miatello Date: Tue, 30 Apr 2024 23:30:33 +0200 Subject: [PATCH] Version 7.2.1 --- data/telegramapi.html | 2 +- example/TelegramModels.kt | 48 ++++++++++++++++------------- example/TelegramModelsOnly.kt | 14 ++++----- example/telegram.json | 49 +++++++++++++++++++++++++++--- src/main/kotlin/GeneratorKotlin.kt | 2 +- src/main/kotlin/GeneratorRust.kt | 2 +- src/main/kotlin/TelegramType.kt | 38 +++++++++++++---------- 7 files changed, 104 insertions(+), 51 deletions(-) diff --git a/data/telegramapi.html b/data/telegramapi.html index b846b5c..d3288a0 100644 --- a/data/telegramapi.html +++ b/data/telegramapi.html @@ -13191,4 +13191,4 @@
Press
- + diff --git a/example/TelegramModels.kt b/example/TelegramModels.kt index c1a65de..d71937e 100644 --- a/example/TelegramModels.kt +++ b/example/TelegramModels.kt @@ -8,13 +8,13 @@ ReactionTypeSerializer::class, MessageOriginSerializer::class, ChatBoostSourceSerializer::class, + MenuButtonSerializer::class, InputFileOrStringSerializer::class, IntegerOrStringSerializer::class, KeyboardOptionSerializer::class, MaybeInaccessibleMessageSerializer::class, VoiceChatStartedSerializer::class, VideoChatStartedSerializer::class, - MenuButtonSerializer::class, ) package com.github.omarmiatello.telegram @@ -57,7 +57,14 @@ object InputMediaSerializer : KSerializer { sealed class InputMessageContent : TelegramModel() object InputMessageContentSerializer : KSerializer { override val descriptor: SerialDescriptor = InputMessageContent.serializer().descriptor - override fun serialize(encoder: Encoder, value: InputMessageContent) = TODO() + override fun serialize(encoder: Encoder, value: InputMessageContent) = when (value) { + is InputTextMessageContent -> encoder.encodeSerializableValue(serializer(), value) + is InputLocationMessageContent -> encoder.encodeSerializableValue(serializer(), value) + is InputVenueMessageContent -> encoder.encodeSerializableValue(serializer(), value) + is InputContactMessageContent -> encoder.encodeSerializableValue(serializer(), value) + is InputInvoiceMessageContent -> encoder.encodeSerializableValue(serializer(), value) + } + override fun deserialize(decoder: Decoder): InputMessageContent = TODO() } @Serializable @@ -65,7 +72,6 @@ sealed class InlineQueryResult : TelegramModel() object InlineQueryResultSerializer : KSerializer { override val descriptor: SerialDescriptor = InlineQueryResult.serializer().descriptor override fun serialize(encoder: Encoder, value: InlineQueryResult) = when (value) { - is InlineQueryResultsButton -> encoder.encodeSerializableValue(serializer(), value) is InlineQueryResultArticle -> encoder.encodeSerializableValue(serializer(), value) is InlineQueryResultPhoto -> encoder.encodeSerializableValue(serializer(), value) is InlineQueryResultGif -> encoder.encodeSerializableValue(serializer(), value) @@ -177,6 +183,18 @@ object ChatBoostSourceSerializer : KSerializer { override fun deserialize(decoder: Decoder): ChatBoostSource = TODO() } @Serializable +sealed class MenuButton : TelegramModel() +object MenuButtonSerializer : KSerializer { + override val descriptor: SerialDescriptor = MenuButton.serializer().descriptor + override fun serialize(encoder: Encoder, value: MenuButton) = when (value) { + is MenuButtonCommands -> encoder.encodeSerializableValue(serializer(), value) + is MenuButtonWebApp -> encoder.encodeSerializableValue(serializer(), value) + is MenuButtonDefault -> encoder.encodeSerializableValue(serializer(), value) + } + + override fun deserialize(decoder: Decoder): MenuButton = TODO() +} +@Serializable sealed class InputFileOrString : TelegramModel() object InputFileOrStringSerializer : KSerializer { override val descriptor: SerialDescriptor = InputFileOrString.serializer().descriptor @@ -229,18 +247,6 @@ object VideoChatStartedSerializer : KSerializer { override fun deserialize(decoder: Decoder): VideoChatStarted = TODO() } @Serializable -sealed class MenuButton : TelegramModel() -object MenuButtonSerializer : KSerializer { - override val descriptor: SerialDescriptor = MenuButton.serializer().descriptor - override fun serialize(encoder: Encoder, value: MenuButton) = when (value) { - is MenuButtonCommands -> encoder.encodeSerializableValue(serializer(), value) - is MenuButtonWebApp -> encoder.encodeSerializableValue(serializer(), value) - is MenuButtonDefault -> encoder.encodeSerializableValue(serializer(), value) - } - - override fun deserialize(decoder: Decoder): MenuButton = TODO() -} -@Serializable data class TelegramResponse(val ok: Boolean, val result: T? = null) // --- Utility --- @@ -3511,7 +3517,7 @@ data class InlineQueryResultsButton( val text: String, val web_app: WebAppInfo? = null, val start_parameter: String? = null, -) : InlineQueryResult() { +) : TelegramModel() { override fun toJson() = json.encodeToString(serializer(), this) companion object { fun fromJson(string: String) = json.decodeFromString(serializer(), string) @@ -4268,7 +4274,7 @@ data class InputTextMessageContent( val parse_mode: ParseMode? = null, val entities: List? = null, val link_preview_options: LinkPreviewOptions? = null, -) : TelegramModel() { +) : InputMessageContent() { override fun toJson() = json.encodeToString(serializer(), this) companion object { fun fromJson(string: String) = json.decodeFromString(serializer(), string) @@ -4295,7 +4301,7 @@ data class InputLocationMessageContent( val live_period: Long? = null, val heading: Long? = null, val proximity_alert_radius: Long? = null, -) : TelegramModel() { +) : InputMessageContent() { override fun toJson() = json.encodeToString(serializer(), this) companion object { fun fromJson(string: String) = json.decodeFromString(serializer(), string) @@ -4326,7 +4332,7 @@ data class InputVenueMessageContent( val foursquare_type: String? = null, val google_place_id: String? = null, val google_place_type: String? = null, -) : TelegramModel() { +) : InputMessageContent() { override fun toJson() = json.encodeToString(serializer(), this) companion object { fun fromJson(string: String) = json.decodeFromString(serializer(), string) @@ -4349,7 +4355,7 @@ data class InputContactMessageContent( val first_name: String, val last_name: String? = null, val vcard: String? = null, -) : TelegramModel() { +) : InputMessageContent() { override fun toJson() = json.encodeToString(serializer(), this) companion object { fun fromJson(string: String) = json.decodeFromString(serializer(), string) @@ -4404,7 +4410,7 @@ data class InputInvoiceMessageContent( val send_phone_number_to_provider: Boolean? = null, val send_email_to_provider: Boolean? = null, val is_flexible: Boolean? = null, -) : TelegramModel() { +) : InputMessageContent() { override fun toJson() = json.encodeToString(serializer(), this) companion object { fun fromJson(string: String) = json.decodeFromString(serializer(), string) diff --git a/example/TelegramModelsOnly.kt b/example/TelegramModelsOnly.kt index 2d8d57a..58158df 100644 --- a/example/TelegramModelsOnly.kt +++ b/example/TelegramModelsOnly.kt @@ -10,13 +10,13 @@ sealed class BotCommandScope : TelegramModel() sealed class ReactionType : TelegramModel() sealed class MessageOrigin : TelegramModel() sealed class ChatBoostSource : TelegramModel() +sealed class MenuButton : TelegramModel() sealed class InputFileOrString : TelegramModel() sealed class IntegerOrString : TelegramModel() sealed class KeyboardOption : TelegramModel() sealed class MaybeInaccessibleMessage : TelegramModel() sealed class VoiceChatStarted : TelegramModel() sealed class VideoChatStarted : TelegramModel() -sealed class MenuButton : TelegramModel() data class TelegramResponse(val ok: Boolean, val result: T? = null) // --- Utility --- @@ -2565,7 +2565,7 @@ data class InlineQueryResultsButton( val text: String, val web_app: WebAppInfo? = null, val start_parameter: String? = null, -) : InlineQueryResult() +) : TelegramModel() /** *

Represents a link to an article or web page.

@@ -3196,7 +3196,7 @@ data class InputTextMessageContent( val parse_mode: ParseMode? = null, val entities: List? = null, val link_preview_options: LinkPreviewOptions? = null, -) : TelegramModel() +) : InputMessageContent() /** *

Represents the content of a location message to be sent as the result of an inline query.

@@ -3217,7 +3217,7 @@ data class InputLocationMessageContent( val live_period: Long? = null, val heading: Long? = null, val proximity_alert_radius: Long? = null, -) : TelegramModel() +) : InputMessageContent() /** *

Represents the content of a venue message to be sent as the result of an inline query.

@@ -3242,7 +3242,7 @@ data class InputVenueMessageContent( val foursquare_type: String? = null, val google_place_id: String? = null, val google_place_type: String? = null, -) : TelegramModel() +) : InputMessageContent() /** *

Represents the content of a contact message to be sent as the result of an inline query.

@@ -3259,7 +3259,7 @@ data class InputContactMessageContent( val first_name: String, val last_name: String? = null, val vcard: String? = null, -) : TelegramModel() +) : InputMessageContent() /** *

Represents the content of an invoice message to be sent as the result of an inline query.

@@ -3308,7 +3308,7 @@ data class InputInvoiceMessageContent( val send_phone_number_to_provider: Boolean? = null, val send_email_to_provider: Boolean? = null, val is_flexible: Boolean? = null, -) : TelegramModel() +) : InputMessageContent() /** *

Represents a result of an inline query that was chosen by the user and sent to their chat partner.

Note: It is necessary to enable inline feedback via @BotFather in order to receive these objects in updates.

diff --git a/example/telegram.json b/example/telegram.json index 1e60009..9f06ab2 100644 --- a/example/telegram.json +++ b/example/telegram.json @@ -223,6 +223,7 @@ "type": { "name": "ChatMemberUpdated", "superType": { + "subclasses": {}, "name": "ChatMember" } }, @@ -234,6 +235,7 @@ "type": { "name": "ChatMemberUpdated", "superType": { + "subclasses": {}, "name": "ChatMember" } }, @@ -720,6 +722,7 @@ "description": "\u003cem\u003eOptional\u003c/em\u003e. List of available reactions allowed in the chat. If omitted, then all \u003ca href\u003d\"#reactiontypeemoji\"\u003eemoji reactions\u003c/a\u003e are allowed. Returned only in \u003ca href\u003d\"#getchat\"\u003egetChat\u003c/a\u003e.", "type": { "elementType": { + "subclasses": {}, "name": "ReactionType" }, "name": "List\u003cReactionType\u003e" @@ -1035,6 +1038,7 @@ "name": "forward_origin", "description": "\u003cem\u003eOptional\u003c/em\u003e. Information about the original message for forwarded messages", "type": { + "subclasses": {}, "name": "MessageOrigin" }, "required": false @@ -1807,6 +1811,7 @@ "name": "origin", "description": "Origin of the message replied to by the given message", "type": { + "subclasses": {}, "name": "MessageOrigin" }, "required": true @@ -4576,6 +4581,7 @@ "name": "old_chat_member", "description": "Previous information about the chat member", "type": { + "subclasses": {}, "name": "ChatMember" }, "required": true @@ -4584,6 +4590,7 @@ "name": "new_chat_member", "description": "New information about the chat member", "type": { + "subclasses": {}, "name": "ChatMember" }, "required": true @@ -5401,6 +5408,7 @@ "name": "type", "description": "Type of the reaction", "type": { + "subclasses": {}, "name": "ReactionType" }, "required": true @@ -5464,6 +5472,7 @@ "description": "Previous list of reaction types that were set by the user", "type": { "elementType": { + "subclasses": {}, "name": "ReactionType" }, "name": "List\u003cReactionType\u003e" @@ -5475,6 +5484,7 @@ "description": "New list of reaction types that have been set by the user", "type": { "elementType": { + "subclasses": {}, "name": "ReactionType" }, "name": "List\u003cReactionType\u003e" @@ -5952,6 +5962,7 @@ "name": "source", "description": "Source of the added boost", "type": { + "subclasses": {}, "name": "ChatBoostSource" }, "required": true @@ -6012,6 +6023,7 @@ "name": "source", "description": "Source of the removed boost", "type": { + "subclasses": {}, "name": "ChatBoostSource" }, "required": true @@ -8319,6 +8331,7 @@ "description": "A JSON-serialized array describing messages to be sent, must include 2-10 items", "type": { "elementType": { + "subclasses": {}, "name": "InputMedia" }, "name": "List\u003cInputMedia\u003e" @@ -9194,6 +9207,7 @@ "description": "A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators.", "type": { "elementType": { + "subclasses": {}, "name": "ReactionType" }, "name": "List\u003cReactionType\u003e" @@ -10253,6 +10267,7 @@ ], "returns": { "elementType": { + "subclasses": {}, "name": "ChatMember" }, "name": "List\u003cChatMember\u003e" @@ -10313,6 +10328,7 @@ } ], "returns": { + "subclasses": {}, "name": "ChatMember" } }, @@ -10891,6 +10907,7 @@ "name": "scope", "description": "A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to \u003ca href\u003d\"#botcommandscopedefault\"\u003eBotCommandScopeDefault\u003c/a\u003e.", "type": { + "subclasses": {}, "name": "BotCommandScope" }, "required": false @@ -10916,6 +10933,7 @@ "name": "scope", "description": "A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to \u003ca href\u003d\"#botcommandscopedefault\"\u003eBotCommandScopeDefault\u003c/a\u003e.", "type": { + "subclasses": {}, "name": "BotCommandScope" }, "required": false @@ -10941,6 +10959,7 @@ "name": "scope", "description": "A JSON-serialized object, describing scope of users. Defaults to \u003ca href\u003d\"#botcommandscopedefault\"\u003eBotCommandScopeDefault\u003c/a\u003e.", "type": { + "subclasses": {}, "name": "BotCommandScope" }, "required": false @@ -11103,6 +11122,7 @@ "name": "menu_button", "description": "A JSON-serialized object for the bot\u0027s new menu button. Defaults to \u003ca href\u003d\"#menubuttondefault\"\u003eMenuButtonDefault\u003c/a\u003e", "type": { + "subclasses": {}, "name": "MenuButton" }, "required": false @@ -11126,6 +11146,7 @@ } ], "returns": { + "subclasses": {}, "name": "MenuButton" } }, @@ -11434,6 +11455,7 @@ "name": "media", "description": "A JSON-serialized object for a new media content of the message", "type": { + "subclasses": {}, "name": "InputMedia" }, "required": true @@ -12848,6 +12870,7 @@ "name": "input_message_content", "description": "Content of the message to be sent", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": true @@ -13051,6 +13074,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the photo", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -13189,6 +13213,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the GIF animation", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -13327,6 +13352,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the video animation", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -13473,6 +13499,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the video. This field is \u003cstrong\u003erequired\u003c/strong\u003e if InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video).", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -13587,6 +13614,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the audio", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -13693,6 +13721,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the voice recording", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -13807,6 +13836,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the file", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -13942,6 +13972,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the location", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14085,6 +14116,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the venue", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14196,6 +14228,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the contact", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14381,6 +14414,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the photo", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14479,6 +14513,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the GIF animation", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14577,6 +14612,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the video animation", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14640,6 +14676,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the sticker", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14746,6 +14783,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the file", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14852,6 +14890,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the video", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -14950,6 +14989,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the voice message", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -15040,6 +15080,7 @@ "name": "input_message_content", "description": "\u003cem\u003eOptional\u003c/em\u003e. Content of the message to be sent instead of the audio", "type": { + "subclasses": {}, "name": "InputMessageContent" }, "required": false @@ -15500,6 +15541,7 @@ "description": "A JSON-serialized array of results for the inline query", "type": { "elementType": { + "subclasses": {}, "name": "InlineQueryResult" }, "name": "List\u003cInlineQueryResult\u003e" @@ -15534,10 +15576,7 @@ "name": "button", "description": "A JSON-serialized object describing a button to be shown above inline query results", "type": { - "name": "InlineQueryResultsButton", - "superType": { - "name": "InlineQueryResult" - } + "name": "InlineQueryResultsButton" }, "required": false } @@ -15562,6 +15601,7 @@ "name": "result", "description": "A JSON-serialized object describing the message to be sent", "type": { + "subclasses": {}, "name": "InlineQueryResult" }, "required": true @@ -17019,6 +17059,7 @@ "description": "A JSON-serialized array describing the errors", "type": { "elementType": { + "subclasses": {}, "name": "PassportElementError" }, "name": "List\u003cPassportElementError\u003e" diff --git a/src/main/kotlin/GeneratorKotlin.kt b/src/main/kotlin/GeneratorKotlin.kt index 3732285..7428a17 100644 --- a/src/main/kotlin/GeneratorKotlin.kt +++ b/src/main/kotlin/GeneratorKotlin.kt @@ -244,7 +244,6 @@ private fun TelegramType.toKotlinType(prefixPolymorphic: String = ""): String = TelegramType.ParseMode -> name TelegramType.VoiceChatStarted, - TelegramType.MenuButton, TelegramType.VideoChatStarted -> "${prefixPolymorphic}$name" is TelegramType.Super -> { @@ -257,6 +256,7 @@ private fun TelegramType.toKotlinType(prefixPolymorphic: String = ""): String = TelegramType.Super.ChatMember, TelegramType.Super.ReactionType, TelegramType.Super.MessageOrigin, + TelegramType.Super.MenuButton, TelegramType.Super.ChatBoostSource -> "${prefixPolymorphic}$name" } } diff --git a/src/main/kotlin/GeneratorRust.kt b/src/main/kotlin/GeneratorRust.kt index 28fdd65..48c7db1 100644 --- a/src/main/kotlin/GeneratorRust.kt +++ b/src/main/kotlin/GeneratorRust.kt @@ -112,7 +112,6 @@ private fun TelegramType.toRustType(): String = when (this) { TelegramType.ParseMode -> name TelegramType.VoiceChatStarted, - TelegramType.MenuButton, TelegramType.VideoChatStarted -> name is TelegramType.Super -> { @@ -125,6 +124,7 @@ private fun TelegramType.toRustType(): String = when (this) { TelegramType.Super.BotCommandScope, TelegramType.Super.ReactionType, TelegramType.Super.MessageOrigin, + TelegramType.Super.MenuButton, TelegramType.Super.ChatBoostSource -> name } } diff --git a/src/main/kotlin/TelegramType.kt b/src/main/kotlin/TelegramType.kt index 332298f..db56085 100644 --- a/src/main/kotlin/TelegramType.kt +++ b/src/main/kotlin/TelegramType.kt @@ -13,23 +13,30 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS object ParseMode : TelegramType("ParseMode", superType = null) object VoiceChatStarted : TelegramType("VoiceChatStarted", superType = null) object VideoChatStarted : TelegramType("VideoChatStarted", superType = null) - object MenuButton : TelegramType("MenuButton", superType = null) object ForumTopicClosed : TelegramType("ForumTopicClosed", superType = null) object ForumTopicReopened : TelegramType("ForumTopicReopened", superType = null) object GeneralForumTopicHidden : TelegramType("GeneralForumTopicHidden", superType = null) object GeneralForumTopicUnhidden : TelegramType("GeneralForumTopicUnhidden", superType = null) object GiveawayCreated : TelegramType("GiveawayCreated", superType = null) - sealed class Super(name: String) : TelegramType(name, superType = null) { - object InputMedia : Super("InputMedia") - object InputMessageContent : Super("InputMessageContent") - object InlineQueryResult : Super("InlineQueryResult") - object PassportElementError : Super("PassportElementError") - object ChatMember : Super("ChatMember") - object BotCommandScope : Super("BotCommandScope") - object ReactionType : Super("ReactionType") - object MessageOrigin : Super("MessageOrigin") - object ChatBoostSource : Super("ChatBoostSource") + sealed class Super(name: String, val subclasses: (String) -> kotlin.Boolean) : + TelegramType(name, superType = null) { + object InputMessageContent : + Super("InputMessageContent", subclasses = { it.startsWith("Input") && it.endsWith("MessageContent") }) + + object InlineQueryResult : + Super("InlineQueryResult", subclasses = { it.startsWith("InlineQueryResult") && "Results" !in it }) + + object PassportElementError : + Super("PassportElementError", subclasses = { it.startsWith("PassportElementError") }) + + object InputMedia : Super("InputMedia", subclasses = { it.startsWith("InputMedia") }) + object ChatMember : Super("ChatMember", subclasses = { it.startsWith("ChatMember") }) + object BotCommandScope : Super("BotCommandScope", subclasses = { it.startsWith("BotCommandScope") }) + object ReactionType : Super("ReactionType", subclasses = { it.startsWith("ReactionType") }) + object MessageOrigin : Super("MessageOrigin", subclasses = { it.startsWith("MessageOrigin") }) + object ChatBoostSource : Super("ChatBoostSource", subclasses = { it.startsWith("ChatBoostSource") }) + object MenuButton : Super("MenuButton", subclasses = { it.startsWith("MenuButton") }) } sealed class WithAlternative(name: String, val validTypes: List, superType: TelegramType?) : @@ -63,8 +70,6 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS superType = null ) - - object MaybeInaccessibleMessage : WithAlternative( name = "MaybeInaccessibleMessage", validTypes = listOf( @@ -90,18 +95,19 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS Super.ReactionType, Super.MessageOrigin, Super.ChatBoostSource, + Super.MenuButton, WithAlternative.InputFileOrString, WithAlternative.IntegerOrString, WithAlternative.KeyboardOption, WithAlternative.MaybeInaccessibleMessage, VoiceChatStarted, VideoChatStarted, - MenuButton, ) private fun findSuper(docName: String) = allSuper.filterIsInstance(WithAlternative::class.java) .firstOrNull { docName in it.validTypes.map { it.name } } - ?: allSuper.firstOrNull { docName.startsWith(it.name) } + ?: allSuper.filterIsInstance(Super::class.java) + .firstOrNull { it.subclasses(docName) } fun from(type: String): TelegramType = when (type) { "Integer" -> Integer @@ -114,7 +120,6 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS "ParseMode" -> ParseMode "VoiceChatStarted" -> VoiceChatStarted "VideoChatStarted" -> VideoChatStarted - "MenuButton" -> MenuButton "ForumTopicClosed" -> ForumTopicClosed "ForumTopicReopened" -> ForumTopicReopened "GeneralForumTopicHidden" -> GeneralForumTopicHidden @@ -127,6 +132,7 @@ sealed class TelegramType(val name: String, val superType: TelegramType? = findS "ChatBoostSource" -> Super.ChatBoostSource "PassportElementError" -> Super.PassportElementError "ChatMember" -> Super.ChatMember + "MenuButton" -> Super.MenuButton "BotCommandScope" -> Super.BotCommandScope "InputFileOrString" -> WithAlternative.InputFileOrString "IntegerOrString" -> WithAlternative.IntegerOrString