chore: use short api
This commit is contained in:
3 files changed
+7
-13
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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的操作
|
||||
|
||||
@@ -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<String, String> {
|
||||
fun createPastebin(content: String): String {
|
||||
val pastebinPayload = PastebinPayload(content)
|
||||
val response = Http.post<PastebinResponse>(
|
||||
"$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<String>) {
|
||||
val content = args.joinToString(" ")
|
||||
val shortUrl = createPastebin(content).second
|
||||
message.reply(shortUrl)
|
||||
message.reply(createPastebin(content))
|
||||
insertActionRecord(CommandAction.Pastebin, message.sender.userId, content)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user