fix #53 bilibili video description exceed the tg image caption size limit

This commit is contained in:
A.C.Sukazyo Eyre 2024-11-14 22:31:00 +08:00
parent bf41002d87
commit 54be96e511
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
4 changed files with 26 additions and 21 deletions

View File

@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
VERSION = 1.4.0
VERSION = 1.4.1-alpha.1
USE_DELTA = false
VERSION_DELTA =

View File

@ -7,17 +7,14 @@ import cc.sukazyo.cono.morny.data.TelegramStickers
import cc.sukazyo.cono.morny.extra.{twitter, weibo, BilibiliForms}
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
import cc.sukazyo.cono.morny.Log.{exceptionLog, logger}
import cc.sukazyo.cono.morny.data.social.{SocialTwitterParser, SocialWeiboParser}
import cc.sukazyo.cono.morny.data.social.{SocialBilibiliParser, SocialTwitterParser, SocialWeiboParser}
import cc.sukazyo.cono.morny.extra.BilibiliForms.{BiliB23, BiliVideoId}
import cc.sukazyo.cono.morny.extra.bilibili.XWebAPI
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Message.entitiesSafe
import cc.sukazyo.cono.morny.util.CommonFormat.formatDurationTimers
import com.pengrad.telegrambot.model.Chat
import com.pengrad.telegrambot.model.request.ParseMode
import com.pengrad.telegrambot.request.{SendMessage, SendPhoto, SendSticker}
import java.time.Duration
class OnGetSocial (using coeur: MornyCoeur) extends EventListener {
override def onMessage (using event: EventEnv): Unit = {
@ -95,7 +92,6 @@ object OnGetSocial {
}
private def tryFetchSocialOfBilibili (video: BiliVideoId)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) = {
import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramParseEscape.escapeHtml as h
val video_info = XWebAPI.get_view(video)
coeur.account exec new SendPhoto(
@ -103,11 +99,7 @@ object OnGetSocial {
video_info.data.pic
).replyToMessageId(replyToMessage)
.caption(
// language=html
s"""<a href="https://www.bilibili.com/video/av${video.av}"><b>${h(video_info.data.title)}</b></a>
| <i>${formatDurationTimers(Duration.ofSeconds(video_info.data.duration))}</i> <a href="https://space.bilibili.com/${video_info.data.owner.mid}">@${h(video_info.data.owner.name)}</a>
|
|${h(video_info.data.desc)}""".stripMargin
SocialBilibiliParser.printsBilibiliVideoCaption(video, video_info.data)
).parseMode(ParseMode.HTML)
}

View File

@ -1,18 +1,14 @@
package cc.sukazyo.cono.morny.bot.query
import cc.sukazyo.cono.morny.data.social.{SocialTwitterParser, SocialWeiboParser}
import cc.sukazyo.cono.morny.data.social.{SocialBilibiliParser, SocialTwitterParser, SocialWeiboParser}
import cc.sukazyo.cono.morny.extra.{twitter, weibo}
import cc.sukazyo.cono.morny.extra.twitter.FXApi
import cc.sukazyo.cono.morny.extra.weibo.MApi
import cc.sukazyo.cono.morny.extra.BilibiliForms.{BiliB23, BiliVideoId}
import cc.sukazyo.cono.morny.extra.bilibili.XWebAPI
import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramParseEscape.escapeHtml as h
import cc.sukazyo.cono.morny.util.CommonFormat.formatDurationTimers
import com.pengrad.telegrambot.model.Update
import com.pengrad.telegrambot.model.request.{InlineQueryResultPhoto, ParseMode}
import java.time.Duration
class ShareToolSocialContent extends ITelegramQuery {
override def query (event: Update): List[InlineQueryUnit[_]] | Null = {
@ -41,11 +37,7 @@ class ShareToolSocialContent extends ITelegramQuery {
).description(
s"av${video.av} / BV${video.bv} - Preview"
).caption(
// language=html
s"""<a href="https://www.bilibili.com/video/av${video.av}"><b>${h(video_info.data.title)}</b></a>
| <i>${formatDurationTimers(Duration.ofSeconds(video_info.data.duration))}</i> <a href="https://space.bilibili.com/${video_info.data.owner.mid}">@${h(video_info.data.owner.name)}</a>
|
|${h(video_info.data.desc)}""".stripMargin
SocialBilibiliParser.printsBilibiliVideoCaption(video, video_info.data)
).parseMode(ParseMode.HTML))
}

View File

@ -0,0 +1,21 @@
package cc.sukazyo.cono.morny.data.social
import cc.sukazyo.cono.morny.extra.BilibiliForms.BiliVideoId
import cc.sukazyo.cono.morny.extra.bilibili.XWebView
import cc.sukazyo.cono.morny.util.CommonFormat.formatDurationTimers
import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramParseEscape.escapeHtml as h
import cc.sukazyo.cono.morny.util.StringEnsure.ensureNotExceed
import java.time.Duration
object SocialBilibiliParser {
def printsBilibiliVideoCaption (vid: BiliVideoId, info: XWebView): String =
// language=html
s"""<a href="https://www.bilibili.com/video/av${vid.av}"><b>${h(info.title)}</b></a>
| <i>${formatDurationTimers(Duration.ofSeconds(info.duration))}</i> <a href="https://space.bilibili.com/${info.owner.mid}">@${h(info.owner.name)}</a>
|
|${h(info.desc.ensureNotExceed(900))}""".stripMargin
}