mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-23 11:37:38 +08:00
fix #53 bilibili video description exceed the tg image caption size limit
This commit is contained in:
parent
bf41002d87
commit
54be96e511
@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur
|
|||||||
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
|
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
|
||||||
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
|
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
|
USE_DELTA = false
|
||||||
VERSION_DELTA =
|
VERSION_DELTA =
|
||||||
|
@ -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.extra.{twitter, weibo, BilibiliForms}
|
||||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
|
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
|
||||||
import cc.sukazyo.cono.morny.Log.{exceptionLog, logger}
|
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.BilibiliForms.{BiliB23, BiliVideoId}
|
||||||
import cc.sukazyo.cono.morny.extra.bilibili.XWebAPI
|
import cc.sukazyo.cono.morny.extra.bilibili.XWebAPI
|
||||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Message.entitiesSafe
|
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.Chat
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode
|
import com.pengrad.telegrambot.model.request.ParseMode
|
||||||
import com.pengrad.telegrambot.request.{SendMessage, SendPhoto, SendSticker}
|
import com.pengrad.telegrambot.request.{SendMessage, SendPhoto, SendSticker}
|
||||||
|
|
||||||
import java.time.Duration
|
|
||||||
|
|
||||||
class OnGetSocial (using coeur: MornyCoeur) extends EventListener {
|
class OnGetSocial (using coeur: MornyCoeur) extends EventListener {
|
||||||
|
|
||||||
override def onMessage (using event: EventEnv): Unit = {
|
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) = {
|
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)
|
val video_info = XWebAPI.get_view(video)
|
||||||
coeur.account exec new SendPhoto(
|
coeur.account exec new SendPhoto(
|
||||||
@ -103,11 +99,7 @@ object OnGetSocial {
|
|||||||
video_info.data.pic
|
video_info.data.pic
|
||||||
).replyToMessageId(replyToMessage)
|
).replyToMessageId(replyToMessage)
|
||||||
.caption(
|
.caption(
|
||||||
// language=html
|
SocialBilibiliParser.printsBilibiliVideoCaption(video, video_info.data)
|
||||||
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
|
|
||||||
).parseMode(ParseMode.HTML)
|
).parseMode(ParseMode.HTML)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
package cc.sukazyo.cono.morny.bot.query
|
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, weibo}
|
||||||
import cc.sukazyo.cono.morny.extra.twitter.FXApi
|
import cc.sukazyo.cono.morny.extra.twitter.FXApi
|
||||||
import cc.sukazyo.cono.morny.extra.weibo.MApi
|
import cc.sukazyo.cono.morny.extra.weibo.MApi
|
||||||
import cc.sukazyo.cono.morny.extra.BilibiliForms.{BiliB23, BiliVideoId}
|
import cc.sukazyo.cono.morny.extra.BilibiliForms.{BiliB23, BiliVideoId}
|
||||||
import cc.sukazyo.cono.morny.extra.bilibili.XWebAPI
|
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.Update
|
||||||
import com.pengrad.telegrambot.model.request.{InlineQueryResultPhoto, ParseMode}
|
import com.pengrad.telegrambot.model.request.{InlineQueryResultPhoto, ParseMode}
|
||||||
|
|
||||||
import java.time.Duration
|
|
||||||
|
|
||||||
class ShareToolSocialContent extends ITelegramQuery {
|
class ShareToolSocialContent extends ITelegramQuery {
|
||||||
|
|
||||||
override def query (event: Update): List[InlineQueryUnit[_]] | Null = {
|
override def query (event: Update): List[InlineQueryUnit[_]] | Null = {
|
||||||
@ -41,11 +37,7 @@ class ShareToolSocialContent extends ITelegramQuery {
|
|||||||
).description(
|
).description(
|
||||||
s"av${video.av} / BV${video.bv} - Preview"
|
s"av${video.av} / BV${video.bv} - Preview"
|
||||||
).caption(
|
).caption(
|
||||||
// language=html
|
SocialBilibiliParser.printsBilibiliVideoCaption(video, video_info.data)
|
||||||
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
|
|
||||||
).parseMode(ParseMode.HTML))
|
).parseMode(ParseMode.HTML))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user