1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-26 11:38:09 +00:00

migration from CaptionedInput

This commit is contained in:
InsanusMokrassar 2021-04-26 21:25:52 +06:00
parent 946b0222df
commit d69b2e09d5
22 changed files with 65 additions and 58 deletions

View File

@ -2,15 +2,23 @@ package dev.inmo.tgbotapi.CommonAbstracts
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
interface Captioned { const val CaptionDeprecation = "Captioned interface and others will be removed soon and not recommended to use"
@Deprecated(CaptionDeprecation)
interface Captioned : Texted {
@Deprecated(CaptionDeprecation)
val caption: String? val caption: String?
get() = text
} }
interface CaptionedInput : Captioned { @Deprecated(CaptionDeprecation)
interface CaptionedInput : Captioned, TextedInput {
/** /**
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] * Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
*/ */
@Deprecated(CaptionDeprecation)
val captionEntities: List<TextPart> val captionEntities: List<TextPart>
get() = textEntities
} }
/** /**

View File

@ -20,7 +20,7 @@ fun SendAnimation(
chatId: ChatIdentifier, chatId: ChatIdentifier,
animation: InputFile, animation: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,

View File

@ -20,7 +20,7 @@ fun SendAudio(
chatId: ChatIdentifier, chatId: ChatIdentifier,
audio: InputFile, audio: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
duration: Long? = null, duration: Long? = null,
performer: String? = null, performer: String? = null,

View File

@ -29,7 +29,7 @@ fun SendDocument(
chatId: ChatIdentifier, chatId: ChatIdentifier,
document: InputFile, document: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,

View File

@ -18,7 +18,7 @@ import kotlinx.serialization.*
fun SendPhoto( fun SendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photo: InputFile, photo: InputFile,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,

View File

@ -20,7 +20,7 @@ fun SendVideo(
chatId: ChatIdentifier, chatId: ChatIdentifier,
video: InputFile, video: InputFile,
thumb: InputFile? = null, thumb: InputFile? = null,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
duration: Long? = null, duration: Long? = null,
width: Int? = null, width: Int? = null,

View File

@ -19,7 +19,7 @@ import kotlinx.serialization.*
fun SendVoice( fun SendVoice(
chatId: ChatIdentifier, chatId: ChatIdentifier,
voice: InputFile, voice: InputFile,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
duration: Long? = null, duration: Long? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,

View File

@ -62,7 +62,7 @@ data class InputMediaAudio internal constructor(
} }
fun AudioFile.toInputMediaAudio( fun AudioFile.toInputMediaAudio(
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
title: String? = this.title title: String? = this.title
): InputMediaAudio = InputMediaAudio( ): InputMediaAudio = InputMediaAudio(

View File

@ -13,11 +13,11 @@ internal const val documentInputMediaType = "document"
fun InputMediaDocument( fun InputMediaDocument(
file: InputFile, file: InputFile,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
thumb: InputFile? = null, thumb: InputFile? = null,
disableContentTypeDetection: Boolean? = null disableContentTypeDetection: Boolean? = null
) = InputMediaDocument(file, caption, parseMode, null, thumb, disableContentTypeDetection) ) = InputMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection)
fun InputMediaDocument( fun InputMediaDocument(
file: InputFile, file: InputFile,
@ -62,11 +62,11 @@ data class InputMediaDocument internal constructor(
} }
fun DocumentFile.toInputMediaDocument( fun DocumentFile.toInputMediaDocument(
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null parseMode: ParseMode? = null
) = InputMediaDocument( ) = InputMediaDocument(
fileId, fileId,
caption, text,
parseMode, parseMode,
thumb ?.fileId thumb ?.fileId
) )

View File

@ -46,7 +46,7 @@ data class InputMediaPhoto internal constructor(
} }
fun PhotoSize.toInputMediaPhoto( fun PhotoSize.toInputMediaPhoto(
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null parseMode: ParseMode? = null
): InputMediaPhoto = InputMediaPhoto( ): InputMediaPhoto = InputMediaPhoto(
fileId, fileId,

View File

@ -34,7 +34,7 @@ data class VideoFile(
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun VideoFile.toInputMediaVideo( inline fun VideoFile.toInputMediaVideo(
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null parseMode: ParseMode? = null
) = InputMediaVideo( ) = InputMediaVideo(
fileId, fileId,

View File

@ -8,7 +8,7 @@ data class Game(
override val title: String, override val title: String,
val description: String, val description: String,
val photo: Photo, val photo: Photo,
override val caption: String? = null, override val text: String? = null,
override val captionEntities: List<TextPart> = emptyList(), override val textEntities: List<TextPart> = emptyList(),
val animation: AnimationFile? = null val animation: AnimationFile? = null
) : Titled, CaptionedInput ) : Titled, CaptionedInput, TextedInput

View File

@ -16,9 +16,9 @@ internal data class RawGame(
@SerialName(photoField) @SerialName(photoField)
private val photo: Photo, private val photo: Photo,
@SerialName(textField) @SerialName(textField)
private val caption: String? = null, private val text: String? = null,
@SerialName(textEntitiesField) @SerialName(textEntitiesField)
private val captionEntities: RawMessageEntities = emptyList(), private val textEntities: RawMessageEntities = emptyList(),
@SerialName(animationField) @SerialName(animationField)
private val animation: AnimationFile? = null private val animation: AnimationFile? = null
) { ) {
@ -27,8 +27,8 @@ internal data class RawGame(
title, title,
description, description,
photo, photo,
caption, text,
caption ?.let { _ -> captionEntities.asTextParts(caption) } ?: emptyList(), text ?.let { _ -> textEntities.asTextParts(text) } ?: emptyList(),
animation animation
) )
} }

View File

@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.message.content.abstracts
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
import dev.inmo.tgbotapi.types.InputMedia.* import dev.inmo.tgbotapi.types.InputMedia.*
interface MediaGroupContent : MediaContent, CaptionedInput { interface MediaGroupContent : MediaContent, CaptionedInput, TextedInput {
fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia
} }

View File

@ -15,9 +15,9 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
data class AnimationContent( data class AnimationContent(
override val media: AnimationFile, override val media: AnimationFile,
val includedDocument: DocumentFile?, val includedDocument: DocumentFile?,
override val caption: String?, override val text: String?,
override val captionEntities: List<TextPart> override val textEntities: List<TextPart>
) : MediaContent, CaptionedInput { ) : MediaContent, CaptionedInput, TextedInput {
override fun createResend( override fun createResend(
chatId: ChatIdentifier, chatId: ChatIdentifier,
disableNotification: Boolean, disableNotification: Boolean,

View File

@ -15,8 +15,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent
data class AudioContent( data class AudioContent(
override val media: AudioFile, override val media: AudioFile,
override val caption: String? = null, override val text: String? = null,
override val captionEntities: List<TextPart> = emptyList() override val textEntities: List<TextPart> = emptyList()
) : AudioMediaGroupContent { ) : AudioMediaGroupContent {
override fun createResend( override fun createResend(
chatId: ChatIdentifier, chatId: ChatIdentifier,

View File

@ -16,8 +16,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
data class DocumentContent( data class DocumentContent(
override val media: DocumentFile, override val media: DocumentFile,
override val caption: String? = null, override val text: String? = null,
override val captionEntities: List<TextPart> = emptyList() override val textEntities: List<TextPart> = emptyList()
) : DocumentMediaGroupContent { ) : DocumentMediaGroupContent {
override fun createResend( override fun createResend(
chatId: ChatIdentifier, chatId: ChatIdentifier,
@ -43,10 +43,10 @@ data class DocumentContent(
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun MediaContent.asDocumentContent() = when (this) { inline fun MediaContent.asDocumentContent() = when (this) {
is CaptionedInput -> DocumentContent( is TextedInput -> DocumentContent(
media.asDocumentFile(), media.asDocumentFile(),
caption, text,
captionEntities textEntities
) )
else -> DocumentContent( else -> DocumentContent(
media.asDocumentFile() media.asDocumentFile()

View File

@ -16,8 +16,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
data class PhotoContent( data class PhotoContent(
override val mediaCollection: Photo, override val mediaCollection: Photo,
override val caption: String? = null, override val text: String? = null,
override val captionEntities: List<TextPart> = emptyList() override val textEntities: List<TextPart> = emptyList()
) : MediaCollectionContent<PhotoSize>, VisualMediaGroupContent { ) : MediaCollectionContent<PhotoSize>, VisualMediaGroupContent {
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content") override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")

View File

@ -15,8 +15,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
data class VideoContent( data class VideoContent(
override val media: VideoFile, override val media: VideoFile,
override val caption: String? = null, override val text: String? = null,
override val captionEntities: List<TextPart> = emptyList() override val textEntities: List<TextPart> = emptyList()
) : VisualMediaGroupContent { ) : VisualMediaGroupContent {
override fun createResend( override fun createResend(
chatId: ChatIdentifier, chatId: ChatIdentifier,

View File

@ -13,9 +13,9 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
data class VoiceContent( data class VoiceContent(
override val media: VoiceFile, override val media: VoiceFile,
override val caption: String? = null, override val text: String? = null,
override val captionEntities: List<TextPart> = emptyList() override val textEntities: List<TextPart> = emptyList()
) : MediaContent, CaptionedInput { ) : MediaContent, CaptionedInput, TextedInput {
override fun createResend( override fun createResend(
chatId: ChatIdentifier, chatId: ChatIdentifier,
disableNotification: Boolean, disableNotification: Boolean,

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.extensions.api.edit.caption package dev.inmo.tgbotapi.extensions.api.edit.caption
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption
import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.ChatIdentifier
@ -35,7 +34,7 @@ suspend fun <T> TelegramBot.editMessageCaption(
text: String, text: String,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
): ContentMessage<MediaContent> where T : CaptionedInput, T : MediaContent { ): ContentMessage<MediaContent> where T : TextedInput, T : MediaContent {
return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup) return editMessageCaption(message.chat.id, message.messageId, text, parseMode, replyMarkup)
} }
@ -59,6 +58,6 @@ suspend fun <T> TelegramBot.editMessageCaption(
message: ContentMessage<T>, message: ContentMessage<T>,
entities: List<TextSource>, entities: List<TextSource>,
replyMarkup: InlineKeyboardMarkup? = null replyMarkup: InlineKeyboardMarkup? = null
): ContentMessage<MediaContent> where T : CaptionedInput, T : MediaContent { ): ContentMessage<MediaContent> where T : TextedInput, T : MediaContent {
return editMessageCaption(message.chat.id, message.messageId, entities, replyMarkup) return editMessageCaption(message.chat.id, message.messageId, entities, replyMarkup)
} }

View File

@ -16,7 +16,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
suspend fun TelegramBot.sendPhoto( suspend fun TelegramBot.sendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
fileId: InputFile, fileId: InputFile,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
@ -26,7 +26,7 @@ suspend fun TelegramBot.sendPhoto(
SendPhoto( SendPhoto(
chatId, chatId,
fileId, fileId,
caption, text,
parseMode, parseMode,
disableNotification, disableNotification,
replyToMessageId, replyToMessageId,
@ -38,65 +38,65 @@ suspend fun TelegramBot.sendPhoto(
suspend fun TelegramBot.sendPhoto( suspend fun TelegramBot.sendPhoto(
chat: Chat, chat: Chat,
fileId: InputFile, fileId: InputFile,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, fileId, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, fileId, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
suspend fun TelegramBot.sendPhoto( suspend fun TelegramBot.sendPhoto(
chatId: ChatIdentifier, chatId: ChatIdentifier,
photo: Photo, photo: Photo,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
suspend fun TelegramBot.sendPhoto( suspend fun TelegramBot.sendPhoto(
chat: Chat, chat: Chat,
photo: Photo, photo: Photo,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photo, caption, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, photo, text, parseMode, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithPhoto( suspend inline fun TelegramBot.replyWithPhoto(
to: Message, to: Message,
fileId: InputFile, fileId: InputFile,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, fileId, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, fileId, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithPhoto( suspend inline fun TelegramBot.replyWithPhoto(
to: Message, to: Message,
photo: Photo, photo: Photo,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photo, caption, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply( suspend inline fun TelegramBot.reply(
to: Message, to: Message,
photo: Photo, photo: Photo,
caption: String? = null, text: String? = null,
parseMode: ParseMode? = null, parseMode: ParseMode? = null,
disableNotification: Boolean = false, disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = replyWithPhoto(to, photo, caption, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup) ) = replyWithPhoto(to, photo, text, parseMode, disableNotification, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.sendPhoto( suspend inline fun TelegramBot.sendPhoto(