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,6 +185,7 @@ object BiliVideoParseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun parse(listener: OneBotListener, message: GroupMessage) {
|
suspend fun parse(listener: OneBotListener, message: GroupMessage) {
|
||||||
|
try {
|
||||||
val bvid = if (bvRegex.containsMatchIn(message.rawMessage)) {
|
val bvid = if (bvRegex.containsMatchIn(message.rawMessage)) {
|
||||||
message.rawMessage.extractBv()
|
message.rawMessage.extractBv()
|
||||||
} else if (avRegex.containsMatchIn(message.rawMessage)) {
|
} else if (avRegex.containsMatchIn(message.rawMessage)) {
|
||||||
@@ -233,6 +234,8 @@ object BiliVideoParseCommand {
|
|||||||
.addText(shortUrl)
|
.addText(shortUrl)
|
||||||
.build()
|
.build()
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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