1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-21 15:53:47 +00:00

Added "ResendableContent"

This commit is contained in:
InsanusMokrassar 2019-01-17 10:19:33 +08:00
parent b4ef91cc77
commit 54c55d2dc6
18 changed files with 263 additions and 21 deletions

View File

@ -19,3 +19,12 @@
## 0.8.4
* Added `createMarkdownText` and extensions for `CaptionedMediaContent` and `TextContent`
* Added `ResendableContent` and realize in different contents
* Animation
* Audio
* Document
* Photo
* Sticker
* Video
* VideoNote
* Voice

View File

@ -4,5 +4,5 @@ interface DuratedSendMessageRequest<T: Any>: SendMessageRequest<T> {
/**
* Duration of media, usually in seconds
*/
val duration: Int?
val duration: Long?
}

View File

@ -17,7 +17,7 @@ fun SendAnimation(
thumb: InputFile?,
caption: String? = null,
parseMode: ParseMode? = null,
duration: Int? = null,
duration: Long? = null,
width: Int? = null,
height: Int? = null,
disableNotification: Boolean = false,
@ -71,7 +71,7 @@ data class SendAnimationData internal constructor(
override val parseMode: ParseMode? = null,
@SerialName(durationField)
@Optional
override val duration: Int? = null,
override val duration: Long? = null,
@SerialName(widthField)
@Optional
override val width: Int? = null,

View File

@ -17,7 +17,7 @@ fun SendAudio(
thumb: InputFile?,
caption: String? = null,
parseMode: ParseMode? = null,
duration: Int? = null,
duration: Long? = null,
performer: String? = null,
title: String? = null,
disableNotification: Boolean = false,
@ -71,7 +71,7 @@ data class SendAudioData internal constructor(
override val parseMode: ParseMode? = null,
@SerialName(durationField)
@Optional
override val duration: Int? = null,
override val duration: Long? = null,
@SerialName(performerField)
@Optional
val performer: String? = null,

View File

@ -17,7 +17,7 @@ fun SendVideo(
thumb: InputFile?,
caption: String? = null,
parseMode: ParseMode? = null,
duration: Int? = null,
duration: Long? = null,
width: Int? = null,
height: Int? = null,
supportStreaming: Boolean? = null,
@ -73,7 +73,7 @@ data class SendVideoData internal constructor(
override val parseMode: ParseMode? = null,
@SerialName(durationField)
@Optional
override val duration: Int? = null,
override val duration: Long? = null,
@SerialName(widthField)
@Optional
override val width: Int? = null,

View File

@ -17,7 +17,7 @@ fun SendVideoNote(
thumb: InputFile?,
caption: String? = null,
parseMode: ParseMode? = null,
duration: Int? = null,
duration: Long? = null,
size: Int? = null, // in documentation - length (size of video side)
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
@ -69,7 +69,7 @@ data class SendVideoNoteData internal constructor(
override val parseMode: ParseMode? = null,
@SerialName(durationField)
@Optional
override val duration: Int? = null,
override val duration: Long? = null,
@SerialName(lengthField)
@Optional
override val width: Int? = null,

View File

@ -17,7 +17,7 @@ fun SendVoice(
thumb: InputFile?,
caption: String? = null,
parseMode: ParseMode? = null,
duration: Int? = null,
duration: Long? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
@ -67,7 +67,7 @@ data class SendVoiceData internal constructor(
override val parseMode: ParseMode? = null,
@SerialName(durationField)
@Optional
override val duration: Int? = null,
override val duration: Long? = null,
@SerialName(disableNotificationField)
@Optional
override val disableNotification: Boolean = false,

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstrac
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent {
interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent, ResendableContent {
val media: List<T>
}

View File

@ -2,6 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstrac
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.TelegramMediaFile
interface MediaContent<T: TelegramMediaFile>: MessageContent {
interface MediaContent<T: TelegramMediaFile>: MessageContent, ResendableContent {
val media: T
}

View File

@ -0,0 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
interface ResendableContent {
fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage>
}

View File

@ -1,10 +1,46 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
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.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
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
data class AnimationContent(
override val media: AnimationFile,
val includedDocument: DocumentFile?
) : MediaContent<AnimationFile>
) : MediaContent<AnimationFile> {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup)
fun createResend(
chatId: ChatIdentifier,
caption: String?,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> = SendAnimation(
chatId,
media.fileId,
media.thumb ?.fileId,
caption,
parseMode,
media.duration,
media.width,
media.height,
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -1,12 +1,39 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendAudio
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.MarkdownParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
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
data class AudioContent(
override val media: AudioFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaContent<AudioFile>, CaptionedMediaContent
) : MediaContent<AudioFile>, CaptionedMediaContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendAudio(
chatId,
media.fileId,
media.thumb ?.fileId,
toMarkdownCaption(),
MarkdownParseMode,
media.duration,
media.performer,
media.title,
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -1,12 +1,36 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendDocument
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.MarkdownParseMode
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.toMarkdownCaption
data class DocumentContent(
override val media: DocumentFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaContent<DocumentFile>, CaptionedMediaContent
) : MediaContent<DocumentFile>, CaptionedMediaContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendDocument(
chatId,
media.fileId,
media.thumb ?.fileId,
toMarkdownCaption(),
MarkdownParseMode,
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -1,11 +1,35 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
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.MarkdownParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
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
data class PhotoContent(
override val media: List<PhotoSize>,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent
) : MediaCollectionContent<PhotoSize>, CaptionedMediaContent, MediaGroupContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendPhoto(
chatId,
media.biggest() ?.fileId ?: throw IllegalStateException("Empty list of media"),
toMarkdownCaption(),
MarkdownParseMode,
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -1,8 +1,27 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendSticker
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
data class StickerContent(
override val media: Sticker
) : MediaContent<Sticker>
) : MediaContent<Sticker> {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendSticker(
chatId,
media.fileId,
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -1,11 +1,39 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
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.MarkdownParseMode
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
data class VideoContent(
override val media: VideoFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaContent<VideoFile>, CaptionedMediaContent, MediaGroupContent
) : MediaContent<VideoFile>, CaptionedMediaContent, MediaGroupContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendVideo(
chatId,
media.fileId,
media.thumb ?.fileId,
toMarkdownCaption(),
MarkdownParseMode,
media.duration,
media.width,
media.height,
null,
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -1,8 +1,42 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideoNote
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.files.VideoNoteFile
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
data class VideoNoteContent(
override val media: VideoNoteFile
) : MediaContent<VideoNoteFile>
) : MediaContent<VideoNoteFile> {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = createResend(chatId, null, null, disableNotification, replyToMessageId, replyMarkup)
fun createResend(
chatId: ChatIdentifier,
caption: String?,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null
): Request<RawMessage> = SendVideoNote(
chatId,
media.fileId,
media.thumb ?.fileId,
caption,
parseMode,
media.duration,
media.width,
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -1,12 +1,37 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVoice
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.MarkdownParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
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
data class VoiceContent(
override val media: VoiceFile,
override val caption: String? = null,
override val captionEntities: List<MessageEntity> = emptyList()
) : MediaContent<VoiceFile>, CaptionedMediaContent
) : MediaContent<VoiceFile>, CaptionedMediaContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendVoice(
chatId,
media.fileId,
null,
toMarkdownCaption(),
MarkdownParseMode,
media.duration,
disableNotification,
replyToMessageId,
replyMarkup
)
}