All Downloads are FREE. Search and download functionalities are using the official Maven repository.

models.OfferTemplate.kt Maven / Gradle / Ivy

There is a newer version: 0.24.1
Show newest version
package dev.inmo.plagubot.plugins.inline.queries.models

import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
import dev.inmo.tgbotapi.types.InlineQueryId
import kotlinx.serialization.Serializable

@Serializable
data class OfferTemplate(
    val title: String,
    val formats: List = emptyList(),
    val description: String? = null
) {
    fun createArticleResult(id: String, query: String): InlineQueryResultArticle? = formats.firstOrNull {
        it.queryRegex.matches(query)
    } ?.createContent(query) ?.let { content ->
        InlineQueryResultArticle(
            InlineQueryId(id),
            title,
            content,
            description = description
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy