1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +00:00

partially restructurize InlineQueryResult and several its implementators

This commit is contained in:
InsanusMokrassar 2020-11-05 18:00:40 +06:00
parent c0e81b1d6d
commit a5982ac881
11 changed files with 195 additions and 15 deletions

View File

@ -1,18 +1,43 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideoCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity
import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
fun InlineQueryResultVideoCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
title: String,
description: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, text, parseMode, null, replyMarkup, inputMessageContent)
fun InlineQueryResultVideoCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
title: String,
description: String? = null,
entities: List<TextSource>,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVideoCachedImpl(id, fileId, title, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@Serializable
data class InlineQueryResultVideoCachedImpl(
data class InlineQueryResultVideoCachedImpl internal constructor(
@SerialName(idField)
override val id: InlineQueryIdentifier,
@SerialName(videoFileIdField)
@ -22,13 +47,18 @@ data class InlineQueryResultVideoCachedImpl(
@SerialName(descriptionField)
override val description: String? = null,
@SerialName(captionField)
override val caption: String? = null,
override val text: String? = null,
@SerialName(parseModeField)
override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null,
@SerialName(inputMessageContentField)
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVideoCached {
override val type: String = inlineQueryResultVideoType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
}
}

View File

@ -1,9 +1,13 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideo
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity
import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
@ -12,8 +16,39 @@ import dev.inmo.tgbotapi.utils.MimeType
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
fun InlineQueryResultVideoImpl(
id: InlineQueryIdentifier,
url: String,
thumbUrl: String,
mimeType: MimeType,
title: String,
width: Int? = null,
height: Int? = null,
duration: Int? = null,
description: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, text, parseMode, null, replyMarkup, inputMessageContent)
fun InlineQueryResultVideoImpl(
id: InlineQueryIdentifier,
url: String,
thumbUrl: String,
mimeType: MimeType,
title: String,
width: Int? = null,
height: Int? = null,
duration: Int? = null,
description: String? = null,
entities: List<TextSource>,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVideoImpl(id, url, thumbUrl, mimeType, title, width, height, duration, description, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@Serializable
data class InlineQueryResultVideoImpl(
data class InlineQueryResultVideoImpl internal constructor(
@SerialName(idField)
override val id: InlineQueryIdentifier,
@SerialName(videoUrlField)
@ -33,13 +68,18 @@ data class InlineQueryResultVideoImpl(
@SerialName(descriptionField)
override val description: String? = null,
@SerialName(captionField)
override val caption: String? = null,
override val text: String? = null,
@SerialName(parseModeField)
override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null,
@SerialName(inputMessageContentField)
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVideo {
override val type: String = inlineQueryResultVideoType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
}
}

View File

@ -1,18 +1,41 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoiceCached
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity
import dev.inmo.tgbotapi.types.MessageEntity.asTextParts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
fun InlineQueryResultVoiceCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
title: String,
text: String? = null,
parseMode: ParseMode? = null,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVoiceCachedImpl(id, fileId, title, text, parseMode, null, replyMarkup, inputMessageContent)
fun InlineQueryResultVoiceCachedImpl(
id: InlineQueryIdentifier,
fileId: FileId,
title: String,
entities: List<TextSource>,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVoiceCachedImpl(id, fileId, title, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@Serializable
data class InlineQueryResultVoiceCachedImpl(
data class InlineQueryResultVoiceCachedImpl internal constructor(
@SerialName(idField)
override val id: InlineQueryIdentifier,
@SerialName(voiceFileIdField)
@ -20,13 +43,18 @@ data class InlineQueryResultVoiceCachedImpl(
@SerialName(titleField)
override val title: String,
@SerialName(captionField)
override val caption: String? = null,
override val text: String? = null,
@SerialName(parseModeField)
override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null,
@SerialName(inputMessageContentField)
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVoiceCached {
override val type: String = inlineQueryResultVoiceType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
}
}

View File

@ -1,17 +1,52 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoice
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
import dev.inmo.tgbotapi.types.MessageEntity.*
import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntity
import dev.inmo.tgbotapi.types.MessageEntity.toRawMessageEntities
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.ParseMode.parseModeField
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
fun InlineQueryResultVoiceImpl(
id: InlineQueryIdentifier,
url: String,
title: String,
duration: Int? = null,
text: String? = null,
parseMode: ParseMode? = null,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVoiceImpl(
id,
url,
title,
duration,
text,
parseMode,
null,
replyMarkup,
inputMessageContent
)
fun InlineQueryResultVoiceImpl(
id: InlineQueryIdentifier,
url: String,
title: String,
duration: Int? = null,
entities: List<TextSource>,
replyMarkup: InlineKeyboardMarkup? = null,
inputMessageContent: InputMessageContent? = null
) = InlineQueryResultVoiceImpl(id, url, title, duration, entities.makeString(), null, entities.toRawMessageEntities(), replyMarkup, inputMessageContent)
@Serializable
data class InlineQueryResultVoiceImpl(
data class InlineQueryResultVoiceImpl internal constructor(
@SerialName(idField)
override val id: InlineQueryIdentifier,
@SerialName(voiceUrlField)
@ -21,13 +56,18 @@ data class InlineQueryResultVoiceImpl(
@SerialName(voiceDurationField)
override val duration: Int? = null,
@SerialName(captionField)
override val caption: String? = null,
override val text: String? = null,
@SerialName(parseModeField)
override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup? = null,
@SerialName(inputMessageContentField)
override val inputMessageContent: InputMessageContent? = null
) : InlineQueryResultVoice {
override val type: String = inlineQueryResultVoiceType
override val entities: List<TextSource>? by lazy {
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
}
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.WithInputMessageContentInlineQueryResult
@ -8,4 +9,9 @@ const val inlineQueryResultAudioType = "audio"
interface InlineQueryResultAudioCommon : InlineQueryResult,
CaptionedOutput,
WithInputMessageContentInlineQueryResult
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultDocumentType = "document"
@ -9,4 +10,9 @@ interface InlineQueryResultDocumentCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
WithInputMessageContentInlineQueryResult
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultGifType = "gif"
@ -8,4 +9,9 @@ const val inlineQueryResultGifType = "gif"
interface InlineQueryResultGifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
CaptionedOutput,
WithInputMessageContentInlineQueryResult
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultMpeg4GifType = "mpeg4_gif"
@ -8,4 +9,9 @@ const val inlineQueryResultMpeg4GifType = "mpeg4_gif"
interface InlineQueryResultMpeg4GifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
CaptionedOutput,
WithInputMessageContentInlineQueryResult
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultPhotoType = "photo"
@ -9,4 +10,9 @@ interface InlineQueryResultPhotoCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
WithInputMessageContentInlineQueryResult
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultVideoType = "video"
@ -9,4 +10,9 @@ interface InlineQueryResultVideoCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
CaptionedOutput,
WithInputMessageContentInlineQueryResult
TextedOutput,
WithInputMessageContentInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}

View File

@ -1,11 +1,17 @@
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedOutput
import dev.inmo.tgbotapi.CommonAbstracts.TextedOutput
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultVoiceType = "voice"
interface InlineQueryResultVoiceCommon : InlineQueryResult,
CaptionedOutput,
TextedOutput,
WithInputMessageContentInlineQueryResult,
TitledInlineQueryResult
TitledInlineQueryResult {
@Deprecated("Will be removed in next major release")
override val caption: String?
get() = text
}