Skip to content

Commit

Permalink
fix: разбиение ответа /tldr на части
Browse files Browse the repository at this point in the history
  • Loading branch information
Djaler committed Sep 8, 2024
1 parent 49fbcf7 commit c057b68
Showing 1 changed file with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.content.TextMessage
import dev.inmo.tgbotapi.types.message.textsources.splitForText
import dev.inmo.tgbotapi.utils.boldln
import dev.inmo.tgbotapi.utils.buildEntities
import dev.inmo.tgbotapi.utils.regular
Expand All @@ -26,23 +27,23 @@ import java.time.Duration
@Component
@Conditional(YandexApiCondition::class)
class TlDrHandler(
private val requestsExecutor: RequestsExecutor,
private val yandexGptService: YandexGptService,
private val sentryClient: SentryClient,
botInfo: ExtendedBot
private val requestsExecutor: RequestsExecutor,
private val yandexGptService: YandexGptService,
private val sentryClient: SentryClient,
botInfo: ExtendedBot
) : CommandHandler(
botInfo,
command = arrayOf("tldr"),
commandDescription = "пересказать содержимое по ссылке"
botInfo,
command = arrayOf("tldr"),
commandDescription = "пересказать содержимое по ссылке"
) {
companion object {
private val log = LogManager.getLogger()
private val youtubeVideoLinkRegex = Regex("^(https?://)?(www\\.|m\\.)?youtu(\\.be|be\\.\\w{2,3})+/.*")
}

override suspend fun handleCommand(
message: TextMessage,
args: String?
message: TextMessage,
args: String?
) {
val messageToReply: Message
val link: String?
Expand Down Expand Up @@ -88,18 +89,22 @@ class TlDrHandler(
return
}

requestsExecutor.reply(
messageToReply,
buildEntities {
for (keypoint in videoKeypoints) {
regular(buildTimeCode(keypoint.startTime))
boldln(" ${keypoint.content}")
for (thesis in keypoint.theses) {
regularln("${thesis.content}")
}
val messageContent = buildEntities {
for (keypoint in videoKeypoints) {
regular(buildTimeCode(keypoint.startTime))
boldln(" ${keypoint.content}")
for (thesis in keypoint.theses) {
regularln("${thesis.content}")
}
}
)
}

messageContent.splitForText().forEach { part ->
requestsExecutor.reply(
messageToReply,
part
)
}
}

private fun buildTimeCode(startTime: Long): String {
Expand Down

0 comments on commit c057b68

Please sign in to comment.