mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-04-04 09:02:27 +00:00
init
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
|
||||
interface CaptionedInputMedia: InputMedia {
|
||||
val caption: String?
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
interface DuratedInputMedia : InputMedia {
|
||||
val duration: Int?
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile
|
||||
|
||||
const val inputMediaFileAttachmentNameTemplate = "attach://%s"
|
||||
|
||||
interface InputMedia {
|
||||
val type: String
|
||||
val file: InputFile
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class InputMediaAnimation(
|
||||
@Transient
|
||||
override val file: InputFile = throw IllegalStateException("Must be created with file"),
|
||||
@Optional
|
||||
override val caption: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@Optional
|
||||
override val width: Int? = null,
|
||||
@Optional
|
||||
override val height: Int? = null,
|
||||
@Optional
|
||||
override val duration: Int? = null,
|
||||
@Transient
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia {
|
||||
override val type: String = "animation"
|
||||
|
||||
@SerialName(mediaField)
|
||||
val media: String
|
||||
get() = file.let {
|
||||
when (it) {
|
||||
is FileId -> it.fileId
|
||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class InputMediaAudio(
|
||||
@Transient
|
||||
override val file: InputFile = throw IllegalStateException("Must be created with file"),
|
||||
@Optional
|
||||
override val caption: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@Optional
|
||||
override val duration: Int? = null,
|
||||
@Optional
|
||||
val performer: String? = null,
|
||||
@Optional
|
||||
override val title: String? = null,
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, CaptionedInputMedia {
|
||||
override val type: String = "audio"
|
||||
|
||||
@SerialName(mediaField)
|
||||
val media: String
|
||||
get() = file.let {
|
||||
when (it) {
|
||||
is FileId -> it.fileId
|
||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class InputMediaDocument(
|
||||
@Transient
|
||||
override val file: InputFile = throw IllegalStateException("Must be created with file"),
|
||||
@Optional
|
||||
override val caption: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@Transient
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, ThumbedInputMedia, CaptionedInputMedia {
|
||||
override val type: String = "document"
|
||||
|
||||
@SerialName(mediaField)
|
||||
val media: String
|
||||
get() = file.let {
|
||||
when (it) {
|
||||
is FileId -> it.fileId
|
||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class InputMediaPhoto(
|
||||
@Transient
|
||||
override val file: InputFile = throw IllegalStateException("Must be created with file"),
|
||||
@Optional
|
||||
override val caption: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null
|
||||
) : InputMedia, CaptionedInputMedia, MediaGroupMemberInputMedia {
|
||||
override val type: String = "photo"
|
||||
|
||||
override fun serialize(format: StringFormat): String = format.stringify(serializer(), this)
|
||||
|
||||
@Transient
|
||||
override val arguments: Map<String, Any?> = Mapper.mapNullable(serializer(), this)
|
||||
|
||||
@SerialName(mediaField)
|
||||
val media: String
|
||||
get() = file.let {
|
||||
when (it) {
|
||||
is FileId -> it.fileId
|
||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun PhotoSize.toInputMediaPhoto(
|
||||
caption: String? = null,
|
||||
parseMode: ParseMode? = null
|
||||
): InputMediaPhoto = InputMediaPhoto(
|
||||
fileId,
|
||||
caption,
|
||||
parseMode
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class InputMediaVideo(
|
||||
@Transient
|
||||
override val file: InputFile = throw IllegalStateException("Must be created with file"),
|
||||
@Optional
|
||||
override val caption: String? = null,
|
||||
@SerialName(parseModeField)
|
||||
@Optional
|
||||
override val parseMode: ParseMode? = null,
|
||||
@Optional
|
||||
override val width: Int? = null,
|
||||
@Optional
|
||||
override val height: Int? = null,
|
||||
@Optional
|
||||
override val duration: Int? = null,
|
||||
@Transient
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia, MediaGroupMemberInputMedia {
|
||||
override val type: String = "video"
|
||||
|
||||
override fun serialize(format: StringFormat): String = format.stringify(serializer(), this)
|
||||
|
||||
@Transient
|
||||
override val arguments: Map<String, Any?> = Mapper.mapNullable(serializer(), this)
|
||||
|
||||
@SerialName(mediaField)
|
||||
val media: String
|
||||
get() = file.let {
|
||||
when (it) {
|
||||
is FileId -> it.fileId
|
||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import kotlinx.serialization.StringFormat
|
||||
|
||||
interface MediaGroupMemberInputMedia: InputMedia {
|
||||
fun serialize(format: StringFormat): String
|
||||
val arguments: Map<String, Any?>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
interface SizedInputMedia : InputMedia {
|
||||
val width: Int?
|
||||
val height: Int?
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.thumbField
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
// TODO:: fill thumbed
|
||||
interface ThumbedInputMedia : InputMedia {
|
||||
val thumb: InputFile?
|
||||
@Serializable
|
||||
@SerialName(thumbField)
|
||||
val thumbMedia: String?
|
||||
get() = thumb ?.let {
|
||||
when (it) {
|
||||
is FileId -> it.fileId
|
||||
is MultipartFile -> inputMediaFileAttachmentNameTemplate.format(it.fileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||
|
||||
interface TitledInputMedia : InputMedia {
|
||||
val title: String?
|
||||
}
|
||||
Reference in New Issue
Block a user