From ac88dcc29633ec050a083d31f33601038d2dac20 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Tue, 15 Oct 2024 11:13:54 +0800 Subject: [PATCH] chore: use short api --- src/main/kotlin/cn/rtast/fancybot/Const.kt | 1 + src/main/kotlin/cn/rtast/fancybot/FancyBot.kt | 6 ++---- .../rtast/fancybot/commands/misc/PastebinCommand.kt | 13 ++++--------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/cn/rtast/fancybot/Const.kt b/src/main/kotlin/cn/rtast/fancybot/Const.kt index f1f0cb4..2994bbc 100644 --- a/src/main/kotlin/cn/rtast/fancybot/Const.kt +++ b/src/main/kotlin/cn/rtast/fancybot/Const.kt @@ -45,6 +45,7 @@ val gson: Gson = GsonBuilder() const val ROOT_PATH = "./data" const val ASSETS_BASE_URL = "https://static.rtast.cn" const val API_RTAST_URL = "https://api.rtast.cn" +const val PBI_API_URL = "https://pbi.us.kg" val DEFAULT_CONFIG = Config( ncmAPI = "https://ncm.rtast.cn", diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index 691d48f..df3841f 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -19,7 +19,6 @@ import cn.rtast.fancybot.util.misc.convertToDate import cn.rtast.fancybot.util.misc.initCommandAndItem import cn.rtast.fancybot.util.misc.initFilesDir import cn.rtast.fancybot.util.misc.initSetuIndex -import cn.rtast.fancybot.util.misc.isValidUrl import cn.rtast.rob.ROneBotFactory import cn.rtast.rob.entity.* import cn.rtast.rob.entity.lagrange.FileEvent @@ -31,7 +30,6 @@ import cn.rtast.rob.util.ob.OneBotListener import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import sun.net.www.content.text.plain import java.io.File import java.net.URI @@ -94,8 +92,8 @@ class FancyBot : OneBotListener { } if (command.contains("/pb") || command.contains("/pastebin")) { // 使用回复消息的方式快速将创建一个pastebin - val shortUrl = PastebinCommand.createPastebin(plainTextContent).second - message.reply(shortUrl) + val pastebinUrl = PastebinCommand.createPastebin(plainTextContent) + message.reply(pastebinUrl) } if (command.contains("/ascii") || command.contains("/asc")) { // 使用回复消息的方式直接对一个图片进行生成Ascii art的操作 diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/misc/PastebinCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/misc/PastebinCommand.kt index 6e24931..779b896 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/misc/PastebinCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/misc/PastebinCommand.kt @@ -8,8 +8,8 @@ package cn.rtast.fancybot.commands.misc import cn.rtast.fancybot.API_RTAST_URL +import cn.rtast.fancybot.PBI_API_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 @@ -26,24 +26,19 @@ class PastebinCommand : BaseCommand() { override val commandNames = listOf("/pastebin", "/pb") companion object { - /** - * 创建一个pastebin返回一个pair 第一个是原始链接, 第二个是缩短url后的链接 - */ - fun createPastebin(content: String): Pair { + fun createPastebin(content: String): String { val pastebinPayload = PastebinPayload(content) val response = Http.post( "$API_RTAST_URL/api/pastebin", pastebinPayload.toJson(), params = mapOf("key" to configManager.apiRtastKey) ) - val url = "$API_RTAST_URL/api/pp/${response.id}?raw=true" - return url to url.makeShortLink() + return "$PBI_API_URL/-/${response.id}" } } override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { val content = args.joinToString(" ") - val shortUrl = createPastebin(content).second - message.reply(shortUrl) + message.reply(createPastebin(content)) insertActionRecord(CommandAction.Pastebin, message.sender.userId, content) } } \ No newline at end of file