mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2025-10-29 03:00:12 +00:00
add MessageContentCache.sendAndSave
This commit is contained in:
@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.libraries.cache.media.common
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile
|
||||||
import dev.inmo.tgbotapi.requests.get.GetFile
|
import dev.inmo.tgbotapi.requests.get.GetFile
|
||||||
import dev.inmo.tgbotapi.requests.send.media.*
|
import dev.inmo.tgbotapi.requests.send.media.*
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
@@ -58,6 +59,20 @@ class DefaultMessageContentCache<K>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun sendAndSave(
|
||||||
|
k: K,
|
||||||
|
filename: String,
|
||||||
|
inputAllocator: () -> Input
|
||||||
|
) {
|
||||||
|
val sentDocument = bot.execute(
|
||||||
|
SendDocument(
|
||||||
|
filesRefreshingChatId,
|
||||||
|
MultipartFile(filename, inputAllocator),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
save(k, sentDocument.content, filename, inputAllocator)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun get(k: K): MessageContent? {
|
override suspend fun get(k: K): MessageContent? {
|
||||||
val savedSimpleContent = simpleMessageContentCache.get(k) ?: return null
|
val savedSimpleContent = simpleMessageContentCache.get(k) ?: return null
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ interface MessageContentCache<K> {
|
|||||||
filename: String,
|
filename: String,
|
||||||
inputAllocator: suspend () -> Input
|
inputAllocator: suspend () -> Input
|
||||||
)
|
)
|
||||||
|
suspend fun sendAndSave(
|
||||||
|
k: K,
|
||||||
|
filename: String,
|
||||||
|
inputAllocator: () -> Input
|
||||||
|
)
|
||||||
|
|
||||||
suspend fun get(k: K): MessageContent?
|
suspend fun get(k: K): MessageContent?
|
||||||
suspend fun contains(k: K): Boolean
|
suspend fun contains(k: K): Boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user