feat: add ascii art upload to image bed
This commit is contained in:
3 files changed
+22
-14
No files matched your search
@@ -1,6 +1,6 @@
|
||||
[versions]
|
||||
kotlinVersion = "2.0.20"
|
||||
ronebotVersion = "1.13.0"
|
||||
ronebotVersion = "1.13.1"
|
||||
shadowVersion = "8.3.0"
|
||||
okhttpVersion = "5.0.0-alpha.14"
|
||||
exposedVersion = "0.53.0"
|
||||
|
||||
@@ -173,15 +173,13 @@ class FancyBot : OneBotListener {
|
||||
this.sendGroupMessage(groupId, msg)
|
||||
}
|
||||
|
||||
override suspend fun onPoke(event: PokeEvent) {
|
||||
event.groupId?.let {
|
||||
if (event.targetId == configManager.selfId) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(event.userId)
|
||||
.addText("你${event.action.first()}牛魔呢")
|
||||
.build()
|
||||
this.sendGroupMessage(it, msg)
|
||||
}
|
||||
override suspend fun onGroupPoke(event: PokeEvent) {
|
||||
if (event.targetId == configManager.selfId) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(event.userId)
|
||||
.addText("你${event.action.first()}牛魔呢")
|
||||
.build()
|
||||
this.sendGroupMessage(event.groupId!!, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import cn.rtast.fancybot.annotations.CommandDescription
|
||||
import cn.rtast.fancybot.commands.misc.ShortLinkCommand.Companion.makeShortLink
|
||||
import cn.rtast.fancybot.util.Logger
|
||||
import cn.rtast.fancybot.util.file.getFileType
|
||||
import cn.rtast.fancybot.util.misc.ImageBed
|
||||
import cn.rtast.fancybot.util.misc.makeGif
|
||||
import cn.rtast.fancybot.util.str.encodeToBase64
|
||||
import cn.rtast.fancybot.util.misc.toByteArray
|
||||
@@ -102,10 +105,14 @@ class AsciiArtCommand : BaseCommand() {
|
||||
decoder.read(gifStream)
|
||||
if (decoder.frameCount == 0) {
|
||||
val bufferedImage = withContext(Dispatchers.IO) { ImageIO.read(URI(url).toURL()) }
|
||||
val imageBase64 = bufferedImage.convertToAscii()
|
||||
val imageBytes = bufferedImage.convertToAscii()
|
||||
.saveAsciiArtToImage(bufferedImage.width, bufferedImage.height)
|
||||
.toByteArray().encodeToBase64()
|
||||
val msg = MessageChain.Builder().addImage(imageBase64, true).build()
|
||||
.toByteArray()
|
||||
val imageBedUrl = ImageBed.upload(imageBytes, imageBytes.getFileType())
|
||||
val msg = MessageChain.Builder()
|
||||
.addImage(imageBytes.encodeToBase64(), true)
|
||||
.addText(imageBedUrl)
|
||||
.build()
|
||||
message.reply(msg)
|
||||
} else {
|
||||
logger.info("制作GIF Ascii art中, 总帧数: ${decoder.frameCount}")
|
||||
@@ -119,12 +126,15 @@ class AsciiArtCommand : BaseCommand() {
|
||||
}
|
||||
logger.info("合成GIF中...")
|
||||
val gifBytes = decoder.makeGif(asciiFrames)
|
||||
val imageBedUrl = ImageBed.upload(gifBytes, gifBytes.getFileType()).makeShortLink()
|
||||
logger.info("合并完成")
|
||||
val gifBase64 = gifBytes.encodeToBase64()
|
||||
logger.info("处理后的图片大小: ${(gifBytes.size / 1024 / 1024).toInt()}MB")
|
||||
val msg = MessageChain.Builder()
|
||||
.addImage(gifBase64, true)
|
||||
message.reply(msg.build())
|
||||
.addText(imageBedUrl)
|
||||
.build()
|
||||
message.reply(msg)
|
||||
}
|
||||
} catch (_: OutOfMemoryError) {
|
||||
message.reply("GIF处理失败: 内存溢出")
|
||||
|
||||
Reference in New Issue
Block a user