From a1bf244a5668c460044231340aaf16a1d16bab15 Mon Sep 17 00:00:00 2001 From: Kirill Romanov Date: Sun, 7 Jul 2024 16:51:50 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=82=D0=B0=D0=B9=D0=BC=D0=BA=D0=BE=D0=B4?= =?UTF-8?q?=D1=8B=20=D0=BA=20=D1=81=D1=83=D0=BC=D0=BC=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B2=D0=B8=D0=B4=D0=B5=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../djaler/evilbot/clients/YandexGptClient.kt | 2 ++ .../evilbot/handlers/commands/TlDrHandler.kt | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt b/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt index 9490d18..39c7a92 100644 --- a/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt +++ b/src/main/kotlin/com/github/djaler/evilbot/clients/YandexGptClient.kt @@ -90,8 +90,10 @@ data class VideoSummaryResult( val keypoints: List? ) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy::class) data class Keypoint( val content: String, + val startTime: Long, val theses: List, ) diff --git a/src/main/kotlin/com/github/djaler/evilbot/handlers/commands/TlDrHandler.kt b/src/main/kotlin/com/github/djaler/evilbot/handlers/commands/TlDrHandler.kt index 0b873b2..7b0cce0 100644 --- a/src/main/kotlin/com/github/djaler/evilbot/handlers/commands/TlDrHandler.kt +++ b/src/main/kotlin/com/github/djaler/evilbot/handlers/commands/TlDrHandler.kt @@ -20,6 +20,7 @@ import dev.inmo.tgbotapi.utils.regularln import org.apache.logging.log4j.LogManager import org.springframework.context.annotation.Conditional import org.springframework.stereotype.Component +import java.time.Duration @Component @Conditional(YandexApiCondition::class) @@ -90,7 +91,7 @@ class TlDrHandler( messageToReply, buildEntities { for (keypoint in videoKeypoints) { - boldln(keypoint.content) + boldln("${buildTimeCode(keypoint.startTime)} ${keypoint.content}") for (thesis in keypoint.theses) { regularln("• ${thesis.content}") } @@ -99,6 +100,18 @@ class TlDrHandler( ) } + private fun buildTimeCode(startTime: Long): String { + val duration = Duration.ofSeconds(startTime) + val seconds = duration.toSecondsPart() + val minutes = duration.toMinutesPart() + val hours = duration.toHoursPart() + return if (hours != 0) { + String.format("%02d:%02d:%02d", hours, minutes, seconds); + } else { + String.format("%02d:%02d", minutes, seconds); + } + } + private suspend fun replyWithArticleThesis(link: String, messageToReply: Message) { val thesis = yandexGptService.generateLinkThesis(link) if (thesis != null) {