mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-27 01:35:47 +00:00
init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.util.*
|
||||
|
||||
sealed class InputFile {
|
||||
abstract val fileId: String
|
||||
}
|
||||
|
||||
// TODO:: add checks for file url/file id regex
|
||||
/**
|
||||
* Contains file id or file url
|
||||
*/
|
||||
@Serializable(FileIdSerializer::class)
|
||||
data class FileId(
|
||||
override val fileId: String
|
||||
) : InputFile()
|
||||
|
||||
fun String.toInputFile(): InputFile = FileId(this)
|
||||
|
||||
@Serializer(FileId::class)
|
||||
object FileIdSerializer : KSerializer<FileId> {
|
||||
override fun serialize(output: Encoder, obj: FileId) = output.encodeString(obj.fileId)
|
||||
override fun deserialize(input: Decoder): FileId = FileId(input.decodeString())
|
||||
}
|
||||
|
||||
// TODO:: add checks for files size
|
||||
/**
|
||||
* Contains info about file for sending
|
||||
*/
|
||||
data class MultipartFile (
|
||||
val file: File,
|
||||
val mimeType: String = Files.probeContentType(file.toPath()),
|
||||
val filename: String = file.name
|
||||
) : InputFile() {
|
||||
override val fileId: String by lazy {
|
||||
"${UUID.randomUUID()}.${file.extension}"
|
||||
}
|
||||
}
|
||||
|
||||
fun File.toInputFile(): InputFile = MultipartFile(
|
||||
this
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
interface MultipartRequest<T: Any> : Request<T> {
|
||||
val paramsJson: JsonObject
|
||||
val mediaMap: Map<String, MultipartFile>
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
interface Request<T: Any> {
|
||||
fun method(): String
|
||||
fun resultSerializer(): KSerializer<T>
|
||||
@ImplicitReflectionSerializer
|
||||
fun json(): JsonObject = toJsonWithoutNulls()
|
||||
}
|
||||
|
||||
fun <T : Any> StringFormat.extractResult(
|
||||
from: String,
|
||||
dataSerializer: KSerializer<T>
|
||||
): ResponseParameters<T> {
|
||||
return parse(ResponseParameters.serializer(dataSerializer), from)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
interface SimpleRequest<T: Any> : Request<T>
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
|
||||
|
||||
interface ByInlineMessageId {
|
||||
val inlineMessageId: InlineMessageIdentifier
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
|
||||
interface ByMessageId : ChatRequest {
|
||||
val messageId: MessageIdentifier
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
|
||||
interface ChatRequest {
|
||||
val chatId: ChatIdentifier
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
interface DisableNotification {
|
||||
val disableNotification: Boolean
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
interface DisableWebPagePreview {
|
||||
val disableWebPagePreview: Boolean?
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
|
||||
interface ReplyMarkup {
|
||||
val replyMarkup: KeyboardMarkup?
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
|
||||
interface ReplyMessageId {
|
||||
val replyToMessageId: MessageIdentifier?
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.TelegramDate
|
||||
|
||||
interface UntilDate {
|
||||
val untilDate: TelegramDate?
|
||||
}
|
||||
Reference in New Issue
Block a user