1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-10 10:23:47 +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
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?
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]
*/
@Deprecated(CaptionDeprecation)
val captionEntities: List<TextPart>
get() = textEntities
}
/**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,9 +16,9 @@ internal data class RawGame(
@SerialName(photoField)
private val photo: Photo,
@SerialName(textField)
private val caption: String? = null,
private val text: String? = null,
@SerialName(textEntitiesField)
private val captionEntities: RawMessageEntities = emptyList(),
private val textEntities: RawMessageEntities = emptyList(),
@SerialName(animationField)
private val animation: AnimationFile? = null
) {
@ -27,8 +27,8 @@ internal data class RawGame(
title,
description,
photo,
caption,
caption ?.let { _ -> captionEntities.asTextParts(caption) } ?: emptyList(),
text,
text ?.let { _ -> textEntities.asTextParts(text) } ?: emptyList(),
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.types.InputMedia.*
interface MediaGroupContent : MediaContent, CaptionedInput {
interface MediaGroupContent : MediaContent, CaptionedInput, TextedInput {
fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia
}

View File

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

View File

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

View File

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

View File

@ -16,8 +16,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
data class PhotoContent(
override val mediaCollection: Photo,
override val caption: String? = null,
override val captionEntities: List<TextPart> = emptyList()
override val text: String? = null,
override val textEntities: List<TextPart> = emptyList()
) : MediaCollectionContent<PhotoSize>, VisualMediaGroupContent {
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(
override val media: VideoFile,
override val caption: String? = null,
override val captionEntities: List<TextPart> = emptyList()
override val text: String? = null,
override val textEntities: List<TextPart> = emptyList()
) : VisualMediaGroupContent {
override fun createResend(
chatId: ChatIdentifier,

View File

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

View File

@ -1,7 +1,6 @@
package dev.inmo.tgbotapi.extensions.api.edit.caption
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.edit.caption.EditChatMessageCaption
import dev.inmo.tgbotapi.types.ChatIdentifier
@ -35,7 +34,7 @@ suspend fun <T> TelegramBot.editMessageCaption(
text: String,
parseMode: ParseMode? = 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)
}
@ -59,6 +58,6 @@ suspend fun <T> TelegramBot.editMessageCaption(
message: ContentMessage<T>,
entities: List<TextSource>,
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)
}

View File

@ -16,7 +16,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
suspend fun TelegramBot.sendPhoto(
chatId: ChatIdentifier,
fileId: InputFile,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
@ -26,7 +26,7 @@ suspend fun TelegramBot.sendPhoto(
SendPhoto(
chatId,
fileId,
caption,
text,
parseMode,
disableNotification,
replyToMessageId,
@ -38,65 +38,65 @@ suspend fun TelegramBot.sendPhoto(
suspend fun TelegramBot.sendPhoto(
chat: Chat,
fileId: InputFile,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = 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(
chatId: ChatIdentifier,
photo: Photo,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = 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(
chat: Chat,
photo: Photo,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = 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(
to: Message,
fileId: InputFile,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = 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(
to: Message,
photo: Photo,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = 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(
to: Message,
photo: Photo,
caption: String? = null,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
allowSendingWithoutReply: Boolean? = 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(