add MessageContentCache.sendAndSave

This commit is contained in:
2025-03-26 18:14:25 +06:00
parent c25f6d522f
commit 953df71d9e
2 changed files with 20 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.libraries.cache.media.common
import dev.inmo.tgbotapi.bot.TelegramBot
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.send.media.*
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? {
val savedSimpleContent = simpleMessageContentCache.get(k) ?: return null

View File

@@ -12,6 +12,11 @@ interface MessageContentCache<K> {
filename: String,
inputAllocator: suspend () -> Input
)
suspend fun sendAndSave(
k: K,
filename: String,
inputAllocator: () -> Input
)
suspend fun get(k: K): MessageContent?
suspend fun contains(k: K): Boolean