1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

Merge pull request #38 from InsanusMokrassar/0.16.1

0.16.1
This commit is contained in:
InsanusMokrassar 2019-06-28 19:00:50 +08:00 committed by GitHub
commit 46a4e7ea27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 87 additions and 52 deletions

View File

@ -9,6 +9,12 @@
* `String#asUsername` method renamed to `String#toUsername`
* Several `toChatId` extensions added
### 0.16.1
* Now old uncommon `CaptionedMediaContent` and `CaptionedInputMedia` are replaced by almost the same
interfaces `CaptionedInput` and `CaptionedOutput`. They are both implementing `Captioned` interface
* `AnimationContent` now is `CaptionedInput`
## 0.15.0
* Old `UpdatesPoller` removed (was deprecated)

View File

@ -1,4 +1,4 @@
project.version = "0.16.0"
project.version = "0.16.1"
project.group = "com.github.insanusmokrassar"
buildscript {

View File

@ -1,8 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
interface Captioned {
val caption: String?
}
interface CaptionedOutput : Captioned {
val parseMode: ParseMode?
}
interface CaptionedInput : Captioned {
val captionEntities: List<MessageEntity>
}

View File

@ -1,11 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.results.audio
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.WithInputMessageContentInlineQueryResult
const val inlineQueryResultAudioType = "audio"
interface InlineQueryResultAudioCommon : InlineQueryResult,
Captioned,
CaptionedOutput,
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.results.document
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultDocumentType = "document"
@ -8,5 +8,5 @@ const val inlineQueryResultDocumentType = "document"
interface InlineQueryResultDocumentCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
Captioned,
CaptionedOutput,
WithInputMessageContentInlineQueryResult

View File

@ -1,11 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.results.gif
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultGifType = "gif"
interface InlineQueryResultGifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
Captioned,
CaptionedOutput,
WithInputMessageContentInlineQueryResult

View File

@ -1,11 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultMpeg4GifType = "mpeg4_gif"
interface InlineQueryResultMpeg4GifCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
Captioned,
CaptionedOutput,
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.results.photo
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultPhotoType = "photo"
@ -8,5 +8,5 @@ const val inlineQueryResultPhotoType = "photo"
interface InlineQueryResultPhotoCommon : InlineQueryResult,
OptionallyTitledInlineQueryResult,
DescribedInlineQueryResult,
Captioned,
CaptionedOutput,
WithInputMessageContentInlineQueryResult

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.results.video
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultVideoType = "video"
@ -8,5 +8,5 @@ const val inlineQueryResultVideoType = "video"
interface InlineQueryResultVideoCommon : InlineQueryResult,
TitledInlineQueryResult,
DescribedInlineQueryResult,
Captioned,
CaptionedOutput,
WithInputMessageContentInlineQueryResult

View File

@ -1,11 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.results.voice
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InlineQueryResult.abstracts.*
const val inlineQueryResultVoiceType = "voice"
interface InlineQueryResultVoiceCommon : InlineQueryResult,
Captioned,
CaptionedOutput,
WithInputMessageContentInlineQueryResult,
TitledInlineQueryResult

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.InputMessageContent
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Captioned
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.DisableWebPagePreview
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineQueries.abstracts.InputMessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
@ -18,4 +18,4 @@ data class InputTextMessageContent(
override val parseMode: ParseMode? = null,
@SerialName(disableWebPagePreviewField)
override val disableWebPagePreview: Boolean? = null
) : Captioned, DisableWebPagePreview, InputMessageContent
) : CaptionedOutput, DisableWebPagePreview, InputMessageContent

View File

@ -1,8 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
interface CaptionedInputMedia: InputMedia {
val caption: String?
val parseMode: ParseMode?
}
@Deprecated(
"Deprecated due to replace by common type CaptionedOutput",
ReplaceWith("CaptionedOutput", "com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput")
)
typealias CaptionedInputMedia = CaptionedOutput

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
@ -17,7 +18,7 @@ data class InputMediaAnimation(
override val height: Int? = null,
override val duration: Long? = null,
override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia {
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedOutput {
override val type: String = "animation"
@SerialName(mediaField)

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.Performerable
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
@ -18,7 +19,7 @@ data class InputMediaAudio(
override val performer: String? = null,
override val title: String? = null,
override val thumb: InputFile? = null
) : InputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, CaptionedInputMedia, Performerable {
) : InputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, CaptionedOutput, Performerable {
override val type: String = "audio"
@SerialName(mediaField)

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
@ -14,7 +15,7 @@ data class InputMediaDocument(
@SerialName(parseModeField)
override val parseMode: ParseMode? = null,
override val thumb: InputFile? = null
) : InputMedia, ThumbedInputMedia, CaptionedInputMedia {
) : InputMedia, ThumbedInputMedia, CaptionedOutput {
override val type: String = "document"
@SerialName(mediaField)

View File

@ -13,7 +13,7 @@ data class InputMediaPhoto(
override val caption: String? = null,
@SerialName(parseModeField)
override val parseMode: ParseMode? = null
) : InputMedia, CaptionedInputMedia, MediaGroupMemberInputMedia {
) : InputMedia, MediaGroupMemberInputMedia {
override val type: String = "photo"
override fun serialize(format: StringFormat): String = format.stringify(serializer(), this)

View File

@ -16,7 +16,7 @@ data class InputMediaVideo(
override val height: Int? = null,
override val duration: Long? = null,
override val thumb: InputFile? = null
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia, MediaGroupMemberInputMedia {
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, MediaGroupMemberInputMedia {
override val type: String = "video"
override fun serialize(format: StringFormat): String = format.stringify(serializer(), this)

View File

@ -1,10 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput
import kotlinx.serialization.Serializable
import kotlinx.serialization.StringFormat
@Serializable(MediaGroupMemberInputMediaSerializer::class)
interface MediaGroupMemberInputMedia: InputMedia {
interface MediaGroupMemberInputMedia : InputMedia, CaptionedOutput {
fun serialize(format: StringFormat): String
val arguments: Map<String, Any?>
}

View File

@ -122,7 +122,12 @@ data class RawMessage(
caption,
adaptedCaptionEntities
)
animation != null -> AnimationContent(animation, document)
animation != null -> AnimationContent(
animation,
document,
caption,
adaptedCaptionEntities
)
sticker != null -> StickerContent(sticker)
game != null -> GameContent(game)
video_note != null -> VideoNoteContent(video_note)

View File

@ -1,8 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
interface CaptionedMediaContent {
val caption: String?
val captionEntities: List<MessageEntity>
}
@Deprecated(
"Deprecated due to replace by common type CaptionedInput",
ReplaceWith("CaptionedInput", "com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput")
)
typealias CaptionedMediaContent = CaptionedInput

View File

@ -1,7 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
interface MediaGroupContent : MediaContent {
interface MediaGroupContent : MediaContent, CaptionedInput {
fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia
}

View File

@ -1,27 +1,34 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAnimation
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.AnimationFile
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.MediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlCaptions
data class AnimationContent(
override val media: AnimationFile,
val includedDocument: DocumentFile?
) : MediaContent {
val includedDocument: DocumentFile?,
override val caption: String?,
override val captionEntities: List<MessageEntity>
) : MediaContent, CaptionedInput {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup)
): Request<RawMessage> = createResend(chatId, toHtmlCaptions().firstOrNull(), HTMLParseMode, disableNotification, replyToMessageId, replyMarkup)
@Deprecated("Will be fully replaced by default method")
fun createResend(
chatId: ChatIdentifier,
caption: String?,

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAudio
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
@ -17,7 +18,7 @@ data class AudioContent(
override val media: AudioFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaContent, CaptionedMediaContent {
) : MediaContent, CaptionedInput {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendDocument
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
@ -9,7 +10,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
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.toHtmlCaptions
@ -17,7 +17,7 @@ data class DocumentContent(
override val media: DocumentFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaContent, CaptionedMediaContent {
) : MediaContent, CaptionedInput {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,

View File

@ -19,7 +19,7 @@ data class PhotoContent(
override val mediaCollection: List<PhotoSize>,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent {
) : MediaCollectionContent<PhotoSize>, MediaGroupContent {
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
override fun createResend(

View File

@ -19,7 +19,7 @@ data class VideoContent(
override val media: VideoFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : CaptionedMediaContent, MediaGroupContent {
) : MediaGroupContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVoice
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
@ -17,7 +18,7 @@ data class VoiceContent(
override val media: VoiceFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaContent, CaptionedMediaContent {
) : MediaContent, CaptionedInput {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,

View File

@ -1,12 +1,12 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RegularTextMessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
fun CaptionedMediaContent.fullEntitiesList(): List<MessageEntity> = caption ?.let {
fun CaptionedInput.fullEntitiesList(): List<MessageEntity> = caption ?.let {
convertToFullMessageEntityList(it, captionEntities)
} ?: emptyList()

View File

@ -1,10 +1,10 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.HTMLParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
fun createHtmlText(
@ -12,7 +12,7 @@ fun createHtmlText(
partLength: Int = 4096
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
fun CaptionedMediaContent.toHtmlCaptions(): List<String> = createHtmlText(
fun CaptionedInput.toHtmlCaptions(): List<String> = createHtmlText(
fullEntitiesList(),
captionLength.endInclusive + 1
)

View File

@ -1,10 +1,10 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedInput
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
@Deprecated(
@ -31,9 +31,9 @@ fun createMarkdownText(
"com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaptions"
)
)
fun CaptionedMediaContent.toMarkdownCaption(): String? = toMarkdownCaptions().firstOrNull()
fun CaptionedInput.toMarkdownCaption(): String? = toMarkdownCaptions().firstOrNull()
fun CaptionedMediaContent.toMarkdownCaptions(): List<String> = createMarkdownText(
fun CaptionedInput.toMarkdownCaptions(): List<String> = createMarkdownText(
fullEntitiesList(),
captionLength.endInclusive + 1
)