1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

add ReplaceWith to old functions and replace built-in usages of deprecations

This commit is contained in:
InsanusMokrassar 2019-02-10 13:46:23 +08:00
parent 1dc80f6929
commit d67d16c72d
7 changed files with 23 additions and 15 deletions

View File

@ -23,7 +23,7 @@ data class TextContent(
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendMessage(
chatId,
toMarkdownText(),
toMarkdownTexts().first(),
MarkdownParseMode,
false,
disableNotification,

View File

@ -11,7 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.files.AudioFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaption
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class AudioContent(
override val media: AudioFile,
@ -27,7 +27,7 @@ data class AudioContent(
chatId,
media.fileId,
media.thumb ?.fileId,
toMarkdownCaption(),
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
media.duration,
media.performer,

View File

@ -11,7 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.files.DocumentFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaption
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class DocumentContent(
override val media: DocumentFile,
@ -27,7 +27,7 @@ data class DocumentContent(
chatId,
media.fileId,
media.thumb ?.fileId,
toMarkdownCaption(),
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
disableNotification,
replyToMessageId,

View File

@ -13,7 +13,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
import com.github.insanusmokrassar.TelegramBotAPI.types.files.biggest
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaption
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class PhotoContent(
override val media: List<PhotoSize>,
@ -28,7 +28,7 @@ data class PhotoContent(
): Request<RawMessage> = SendPhoto(
chatId,
media.biggest() ?.fileId ?: throw IllegalStateException("Empty list of media"),
toMarkdownCaption(),
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
disableNotification,
replyToMessageId,
@ -37,7 +37,7 @@ data class PhotoContent(
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
media.biggest() ?.fileId ?: throw IllegalStateException("Can't locate any photo size for this content"),
toMarkdownCaption(),
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode
)
}

View File

@ -12,7 +12,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaption
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class VideoContent(
override val media: VideoFile,
@ -28,7 +28,7 @@ data class VideoContent(
chatId,
media.fileId,
media.thumb ?.fileId,
toMarkdownCaption(),
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
media.duration,
media.width,
@ -41,7 +41,7 @@ data class VideoContent(
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaVideo(
media.fileId,
toMarkdownCaption(),
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
media.width,
media.height,

View File

@ -11,7 +11,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.files.VoiceFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaption
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions
data class VoiceContent(
override val media: VoiceFile,
@ -27,7 +27,7 @@ data class VoiceContent(
chatId,
media.fileId,
null,
toMarkdownCaption(),
toMarkdownCaptions().firstOrNull(),
MarkdownParseMode,
media.duration,
disableNotification,

View File

@ -55,7 +55,11 @@ fun createMarkdownText(
}
@Deprecated(
"Deprecated because old version have problem with long texts, but new one must return list of strings"
"Deprecated because old version have problem with long texts, but new one must return list of strings",
ReplaceWith(
"toMarkdownCaptions().firstOrNull()",
"com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions"
)
)
fun CaptionedMediaContent.toMarkdownCaption(): String? = toMarkdownCaptions().firstOrNull()
@ -69,7 +73,11 @@ fun CaptionedMediaContent.fullEntitiesList(): List<MessageEntity> = caption ?.le
} ?: emptyList()
@Deprecated(
"Deprecated because old version have problem with long texts, but new one must return list of strings"
"Deprecated because old version have problem with long texts, but new one must return list of strings",
ReplaceWith(
"toMarkdownTexts().first()",
"com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownTexts"
)
)
fun TextContent.toMarkdownText(): String = toMarkdownTexts().first()