Skip to content

Commit

Permalink
Generate reply_markup child
Browse files Browse the repository at this point in the history
  • Loading branch information
IRus committed Aug 19, 2023
1 parent 59dddf3 commit 24eb4b4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
15 changes: 12 additions & 3 deletions core-gen/src/main/kotlin/Generate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@ fun main() {
}

fun TelegramApi.generate() {
val supertypeMapping = objects
val objectSupertypeMapping = objects
.filterIsInstance<AnyOfObject>()
.flatMap { anyOf ->
anyOf.any_of.map { (it as ReferenceApiType).reference to anyOf.name }
}
.toMap()

val methodFiles = methods.map(Method::toFileSpec)
val methodSupertypeMapping = methods.flatMap { it.arguments ?: emptyList() }
.filterIsInstance<AnyOfArgument>()
.flatMap { anyOf ->
anyOf.any_of
.filterIsInstance<ReferenceApiType>()
.map { it.reference to anyOf.name.snakeToTitle() }
}
.toMap()

val methodFiles = methods.map { it.toFileSpec() }

val objectsFiles = objects.map { it.toFileSpec(supertypeMapping) }
val objectsFiles = objects.map { it.toFileSpec(objectSupertypeMapping + methodSupertypeMapping) }

val anyOfArgumentsFiles = objects.filterIsInstance<PropertiesObject>()
.flatMap(PropertiesObject::toAnyOfArguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public data class ForceReply(
* *Optional*. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the *text* of the [Message](https://core.telegram.org/bots/api/#message) object; 2) if the bot's message is a reply (has *reply_to_message_id*), sender of the original message.
*/
public val selective: Boolean? = null,
)
) : ReplyMarkup
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public data class ReplyKeyboardMarkup(
* *Example:* A user requests to change the bot's language, bot replies to the request with a keyboard to select the new language. Other users in the group don't see the keyboard.
*/
public val selective: Boolean? = null,
)
) : ReplyMarkup
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public data class ReplyKeyboardRemove(
* *Example:* A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
*/
public val selective: Boolean? = null,
)
) : ReplyMarkup
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ package io.heapy.kotbot.bot.model

import kotlinx.serialization.Serializable

/**
* TODO: Generate sealead classes
*/
@Serializable
public sealed interface ReplyMarkup

0 comments on commit 24eb4b4

Please sign in to comment.