feat: add image bed api
This commit is contained in:
10 files changed
+91
-31
No files matched your search
@@ -7,10 +7,13 @@
|
||||
|
||||
package cn.rtast.fancybot.commands.misc
|
||||
|
||||
import cn.rtast.fancybot.API_RTAST_URL
|
||||
import cn.rtast.fancybot.annotations.CommandDescription
|
||||
import cn.rtast.fancybot.entity.ShortLink
|
||||
import cn.rtast.fancybot.entity.shortlink.ShortLinkPayload
|
||||
import cn.rtast.fancybot.entity.shortlink.ShortLinkResponse
|
||||
import cn.rtast.fancybot.util.Http
|
||||
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||
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
|
||||
@@ -19,7 +22,16 @@ import cn.rtast.rob.util.ob.OneBotListener
|
||||
class ShortLinkCommand : BaseCommand() {
|
||||
override val commandNames = listOf("/s")
|
||||
|
||||
private val shortLinkApi = "https://api.rtast.cn"
|
||||
|
||||
companion object {
|
||||
fun String.makeShortLink(): String {
|
||||
val shortLink = Http.post<ShortLinkResponse>(
|
||||
"$API_RTAST_URL/short_link",
|
||||
ShortLinkPayload(this).toJson()
|
||||
)
|
||||
return "$API_RTAST_URL/s?rnd_id=${shortLink.id}"
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
@@ -27,10 +39,7 @@ class ShortLinkCommand : BaseCommand() {
|
||||
return
|
||||
}
|
||||
val target = args.first().encodeToBase64()
|
||||
val shortLink = Http.post<ShortLink>(
|
||||
"$shortLinkApi/short_link",
|
||||
params = mapOf("target" to target)
|
||||
)
|
||||
message.reply("$shortLinkApi/s?rnd_id=${shortLink.id}")
|
||||
val shortLink = target.makeShortLink()
|
||||
message.reply(shortLink)
|
||||
}
|
||||
}
|
||||
@@ -113,15 +113,25 @@ class AsciiArtCommand : BaseCommand() {
|
||||
val asciiFrames = mutableListOf<BufferedImage>()
|
||||
val width = frames.first().width
|
||||
val height = frames.first().height
|
||||
frames.forEach { asciiFrames.add(it.convertToAscii().saveAsciiArtToImage(width, height)) }
|
||||
frames.forEachIndexed { index, item ->
|
||||
asciiFrames.add(item.convertToAscii().saveAsciiArtToImage(width, height))
|
||||
logger.info("帧:${index}处理完成")
|
||||
}
|
||||
logger.info("合成GIF中...")
|
||||
val gifBytes = decoder.makeGif(asciiFrames)
|
||||
logger.info("合并完成")
|
||||
val gifBase64 = gifBytes.encodeToBase64()
|
||||
logger.info("处理后的图片大小: ${gifBytes.size}字节, base64大小: ${gifBase64.length * 2}字节")
|
||||
message.reply(MessageChain.Builder().addImage(gifBase64, true).build())
|
||||
logger.info("处理后的图片大小: ${gifBytes.size}字节")
|
||||
val msg = MessageChain.Builder()
|
||||
.addImage(gifBase64, true)
|
||||
message.reply(msg.build())
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
message.reply("处理GIF失败")
|
||||
logger.info("gif处理失败")
|
||||
} catch (_: OutOfMemoryError) {
|
||||
message.reply("GIF处理失败: 内存溢出")
|
||||
logger.info("GIF处理失败: 内存溢出")
|
||||
} catch (e: Exception) {
|
||||
message.reply("处理GIF失败: ${e.message}")
|
||||
logger.info("gif处理失败: ${e.message}")
|
||||
}
|
||||
} else {
|
||||
message.reply("回复错误已取消本次操作")
|
||||
|
||||
Reference in New Issue
Block a user