fix: fix bili video parse error and add pastebin command
This commit is contained in:
4 files changed
+96
-46
No files matched your search
@@ -127,5 +127,5 @@ val commands = listOf(
|
|||||||
SupportMeCommand(), TheCatCommand(), TheHistoryOfTodayCommand(), MCVersionCommand(),
|
SupportMeCommand(), TheCatCommand(), TheHistoryOfTodayCommand(), MCVersionCommand(),
|
||||||
MinecraftWikiCommand(), GaoKaoDaysRemainCommand(), IdiomExplainCommand(), NiuziManagerCommand(),
|
MinecraftWikiCommand(), GaoKaoDaysRemainCommand(), IdiomExplainCommand(), NiuziManagerCommand(),
|
||||||
TodayEatCommand(), TodayDrinkCommand(), MCLoginCommand(), RCONCommand(),
|
TodayEatCommand(), TodayDrinkCommand(), MCLoginCommand(), RCONCommand(),
|
||||||
GravatarCommand()
|
GravatarCommand(), PastebinCommand()
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/14
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.misc
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.API_RTAST_URL
|
||||||
|
import cn.rtast.fancybot.annotations.CommandDescription
|
||||||
|
import cn.rtast.fancybot.commands.misc.ShortLinkCommand.Companion.makeShortLink
|
||||||
|
import cn.rtast.fancybot.configManager
|
||||||
|
import cn.rtast.fancybot.entity.pastebin.PastebinPayload
|
||||||
|
import cn.rtast.fancybot.entity.pastebin.PastebinResponse
|
||||||
|
import cn.rtast.fancybot.util.Http
|
||||||
|
import cn.rtast.fancybot.util.str.toJson
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
|
||||||
|
@CommandDescription("Pastebin!")
|
||||||
|
class PastebinCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("/pastebin", "/pb")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val content = args.joinToString(" ")
|
||||||
|
val pastebinPayload = PastebinPayload(content)
|
||||||
|
val response = Http.post<PastebinResponse>(
|
||||||
|
"$API_RTAST_URL/api/pastebin", pastebinPayload.toJson(),
|
||||||
|
params = mapOf("key" to configManager.apiRtastKey)
|
||||||
|
)
|
||||||
|
message.reply("$API_RTAST_URL/api/pp/${response.id}?raw=true".makeShortLink())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -185,54 +185,57 @@ object BiliVideoParseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun parse(listener: OneBotListener, message: GroupMessage) {
|
suspend fun parse(listener: OneBotListener, message: GroupMessage) {
|
||||||
val bvid = if (bvRegex.containsMatchIn(message.rawMessage)) {
|
try {
|
||||||
message.rawMessage.extractBv()
|
val bvid = if (bvRegex.containsMatchIn(message.rawMessage)) {
|
||||||
} else if (avRegex.containsMatchIn(message.rawMessage)) {
|
message.rawMessage.extractBv()
|
||||||
message.rawMessage.extractAv().avToBv()
|
} else if (avRegex.containsMatchIn(message.rawMessage)) {
|
||||||
} else if (shortUrlRegex.containsMatchIn(message.rawMessage)) {
|
message.rawMessage.extractAv().avToBv()
|
||||||
val shortUrl = shortUrlRegex.find(message.rawMessage)!!.value
|
} else if (shortUrlRegex.containsMatchIn(message.rawMessage)) {
|
||||||
getShortUrlBVID(shortUrl)
|
val shortUrl = shortUrlRegex.find(message.rawMessage)!!.value
|
||||||
} else if (bvRegex.containsMatchIn(message.rawMessage)) {
|
getShortUrlBVID(shortUrl)
|
||||||
bvRegex.find(message.rawMessage)!!.value
|
} else if (bvRegex.containsMatchIn(message.rawMessage)) {
|
||||||
} else if (message.message.find { it.type == ArrayMessageType.json } != null) {
|
bvRegex.find(message.rawMessage)!!.value
|
||||||
val card = message.message.find { it.type == ArrayMessageType.json }!!
|
} else if (message.message.find { it.type == ArrayMessageType.json } != null) {
|
||||||
.data.data!!.toString().fromJson<CardShare>()
|
val card = message.message.find { it.type == ArrayMessageType.json }!!
|
||||||
val shortUrl = if (card.meta.detail == null) {
|
.data.data!!.toString().fromJson<CardShare>()
|
||||||
if (!card.meta.news?.tag!!.contains("哔哩哔哩")) return
|
val shortUrl = if (card.meta.detail == null) {
|
||||||
card.meta.news.jumpUrl
|
if (!card.meta.news?.tag!!.contains("哔哩哔哩")) return
|
||||||
|
card.meta.news.jumpUrl
|
||||||
|
} else {
|
||||||
|
if (!card.meta.detail.title.contains("哔哩哔哩")) return
|
||||||
|
card.meta.detail.qqDocUrl
|
||||||
|
}
|
||||||
|
getShortUrlBVID(shortUrl)
|
||||||
} else {
|
} else {
|
||||||
if (!card.meta.detail.title.contains("哔哩哔哩")) return
|
return
|
||||||
card.meta.detail.qqDocUrl
|
|
||||||
}
|
}
|
||||||
getShortUrlBVID(shortUrl)
|
val videoInfo = this.getVideoStat(bvid)
|
||||||
} else {
|
val viewCount = this.getViewCount(bvid, videoInfo.data.cid)
|
||||||
return
|
val shortUrl = this.generateShortUrl(bvid, videoInfo.data.aid)
|
||||||
|
val fans = Http.get<UserStat>(USER_STAT_URL, mapOf("vmid" to videoInfo.data.owner.mid)).data.follower
|
||||||
|
val authorFace = videoInfo.data.owner.face
|
||||||
|
val title = videoInfo.data.title
|
||||||
|
val author = videoInfo.data.owner.name
|
||||||
|
val coverPicUrl = videoInfo.data.pic
|
||||||
|
val view = videoInfo.data.stat.view.formatNumber()
|
||||||
|
val share = videoInfo.data.stat.share.formatNumber()
|
||||||
|
val like = videoInfo.data.stat.like.formatNumber()
|
||||||
|
val favorite = videoInfo.data.stat.favorite.formatNumber()
|
||||||
|
val coin = videoInfo.data.stat.coin.formatNumber()
|
||||||
|
val reply = videoInfo.data.stat.reply.formatNumber()
|
||||||
|
val image = this.createResponseImage(
|
||||||
|
title, author, authorFace,
|
||||||
|
coverPicUrl, reply, view, coin,
|
||||||
|
share, like, favorite, fans, viewCount
|
||||||
|
)
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addReply(message.messageId)
|
||||||
|
.addImage(image, true)
|
||||||
|
.addText(shortUrl)
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
} catch (_: Exception) {
|
||||||
}
|
}
|
||||||
val videoInfo = this.getVideoStat(bvid)
|
|
||||||
val viewCount = this.getViewCount(bvid, videoInfo.data.cid)
|
|
||||||
val shortUrl = this.generateShortUrl(bvid, videoInfo.data.aid)
|
|
||||||
val fans = Http.get<UserStat>(USER_STAT_URL, mapOf("vmid" to videoInfo.data.owner.mid)).data.follower
|
|
||||||
val authorFace = videoInfo.data.owner.face
|
|
||||||
val title = videoInfo.data.title
|
|
||||||
val author = videoInfo.data.owner.name
|
|
||||||
val coverPicUrl = videoInfo.data.pic
|
|
||||||
val view = videoInfo.data.stat.view.formatNumber()
|
|
||||||
val share = videoInfo.data.stat.share.formatNumber()
|
|
||||||
val like = videoInfo.data.stat.like.formatNumber()
|
|
||||||
val favorite = videoInfo.data.stat.favorite.formatNumber()
|
|
||||||
val coin = videoInfo.data.stat.coin.formatNumber()
|
|
||||||
val reply = videoInfo.data.stat.reply.formatNumber()
|
|
||||||
val image = this.createResponseImage(
|
|
||||||
title, author, authorFace,
|
|
||||||
coverPicUrl, reply, view, coin,
|
|
||||||
share, like, favorite, fans, viewCount
|
|
||||||
)
|
|
||||||
val msg = MessageChain.Builder()
|
|
||||||
.addReply(message.messageId)
|
|
||||||
.addImage(image, true)
|
|
||||||
.addText(shortUrl)
|
|
||||||
.build()
|
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/14
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity.pastebin
|
||||||
|
|
||||||
|
data class PastebinPayload(val content: String)
|
||||||
|
|
||||||
|
data class PastebinResponse(val id: String)
|
||||||
Reference in New Issue
Block a user