chore: chore: chore: chore: chore: chore: chore
This commit is contained in:
4 files changed
+37
-42
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
kotlinVersion = "2.0.10"
|
kotlinVersion = "2.0.10"
|
||||||
ronebotVersion = "1.11.1"
|
ronebotVersion = "1.11.2"
|
||||||
shadowVersion = "8.3.0"
|
shadowVersion = "8.3.0"
|
||||||
okhttpVersion = "5.0.0-alpha.14"
|
okhttpVersion = "5.0.0-alpha.14"
|
||||||
exposedVersion = "0.53.0"
|
exposedVersion = "0.53.0"
|
||||||
|
|||||||
@@ -7,12 +7,7 @@
|
|||||||
|
|
||||||
package cn.rtast.fancybot
|
package cn.rtast.fancybot
|
||||||
|
|
||||||
import cn.rtast.fancybot.commands.parse.AsciiArtCommand
|
import cn.rtast.fancybot.commands.parse.*
|
||||||
import cn.rtast.fancybot.commands.parse.BVParseCommand
|
|
||||||
import cn.rtast.fancybot.commands.parse.CalculateCommand
|
|
||||||
import cn.rtast.fancybot.commands.parse.GitHubParseCommand
|
|
||||||
import cn.rtast.fancybot.commands.parse.ImageURLCommand
|
|
||||||
import cn.rtast.fancybot.commands.parse.ReverseGIFCommand
|
|
||||||
import cn.rtast.fancybot.entity.bili.CardShare
|
import cn.rtast.fancybot.entity.bili.CardShare
|
||||||
import cn.rtast.fancybot.entity.enums.WSType
|
import cn.rtast.fancybot.entity.enums.WSType
|
||||||
import cn.rtast.fancybot.util.initDatabase
|
import cn.rtast.fancybot.util.initDatabase
|
||||||
@@ -55,6 +50,7 @@ class FancyBot : OneBotListener {
|
|||||||
|
|
||||||
ReverseGIFCommand.callback(message)
|
ReverseGIFCommand.callback(message)
|
||||||
AsciiArtCommand.callback(message)
|
AsciiArtCommand.callback(message)
|
||||||
|
|
||||||
if (message.message.any { it.type == ArrayMessageType.reply }) { // Image url parse
|
if (message.message.any { it.type == ArrayMessageType.reply }) { // Image url parse
|
||||||
val command = message.message.reversed().find { it.type == ArrayMessageType.text }!!.data.text!!
|
val command = message.message.reversed().find { it.type == ArrayMessageType.text }!!.data.text!!
|
||||||
val replyId = message.message.find { it.type == ArrayMessageType.reply }!!.data.id!!
|
val replyId = message.message.find { it.type == ArrayMessageType.reply }!!.data.id!!
|
||||||
|
|||||||
@@ -87,41 +87,40 @@ class AsciiArtCommand : BaseCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun callback(message: GroupMessage) {
|
suspend fun callback(message: GroupMessage) {
|
||||||
if (message.sender.userId in waitingList) {
|
if (message.sender.userId !in waitingList) return
|
||||||
if (message.message.any { it.type == ArrayMessageType.image }
|
waitingList.removeIf { it == message.sender.userId }
|
||||||
|| message.message.any { it.type == ArrayMessageType.mface }) {
|
if (message.message.any { it.type == ArrayMessageType.image }
|
||||||
val url = if (message.message.any { it.type == ArrayMessageType.image })
|
|| message.message.any { it.type == ArrayMessageType.mface }) {
|
||||||
message.message.find { it.type == ArrayMessageType.image }!!.data.file!!
|
val url = if (message.message.any { it.type == ArrayMessageType.image })
|
||||||
else message.message.find { it.type == ArrayMessageType.mface }!!.data.url!!
|
message.message.find { it.type == ArrayMessageType.image }!!.data.file!!
|
||||||
val gifStream = withContext(Dispatchers.IO) { URI(url).toURL().openStream() }
|
else message.message.find { it.type == ArrayMessageType.mface }!!.data.url!!
|
||||||
val decoder = GifDecoder()
|
val gifStream = withContext(Dispatchers.IO) { URI(url).toURL().openStream() }
|
||||||
try {
|
val decoder = GifDecoder()
|
||||||
decoder.read(gifStream)
|
try {
|
||||||
if (decoder.frameCount == 0) {
|
decoder.read(gifStream)
|
||||||
val bufferedImage = withContext(Dispatchers.IO) { ImageIO.read(URI(url).toURL()) }
|
if (decoder.frameCount == 0) {
|
||||||
val imageBase64 = bufferedImage.convertToAscii()
|
val bufferedImage = withContext(Dispatchers.IO) { ImageIO.read(URI(url).toURL()) }
|
||||||
.saveAsciiArtToImage(bufferedImage.width, bufferedImage.height)
|
val imageBase64 = bufferedImage.convertToAscii()
|
||||||
.toByteArray().encodeToBase64()
|
.saveAsciiArtToImage(bufferedImage.width, bufferedImage.height)
|
||||||
val msg = MessageChain.Builder().addImage(imageBase64, true).build()
|
.toByteArray().encodeToBase64()
|
||||||
message.reply(msg)
|
val msg = MessageChain.Builder().addImage(imageBase64, true).build()
|
||||||
} else {
|
message.reply(msg)
|
||||||
println("Making gif ascii art, frames: ${decoder.frameCount}")
|
} else {
|
||||||
val frames = (0 until decoder.frameCount).map { decoder.getFrame(it) }
|
println("Making gif ascii art, frames: ${decoder.frameCount}")
|
||||||
val asciiFrames = mutableListOf<BufferedImage>()
|
val frames = (0 until decoder.frameCount).map { decoder.getFrame(it) }
|
||||||
val width = frames.first().width
|
val asciiFrames = mutableListOf<BufferedImage>()
|
||||||
val height = frames.first().height
|
val width = frames.first().width
|
||||||
frames.forEach { asciiFrames.add(it.convertToAscii().saveAsciiArtToImage(width, height)) }
|
val height = frames.first().height
|
||||||
val gifBytes = decoder.makeGif(asciiFrames)
|
frames.forEach { asciiFrames.add(it.convertToAscii().saveAsciiArtToImage(width, height)) }
|
||||||
val gifBase64 = gifBytes.encodeToBase64()
|
val gifBytes = decoder.makeGif(asciiFrames)
|
||||||
message.reply(MessageChain.Builder().addImage(gifBase64, true).build())
|
val gifBase64 = gifBytes.encodeToBase64()
|
||||||
}
|
message.reply(MessageChain.Builder().addImage(gifBase64, true).build())
|
||||||
} catch (_: Exception) {
|
|
||||||
message.reply("处理GIF失败")
|
|
||||||
}
|
}
|
||||||
} else {
|
} catch (_: Exception) {
|
||||||
message.reply("回复错误已取消本次操作")
|
message.reply("处理GIF失败")
|
||||||
}
|
}
|
||||||
waitingList.removeIf { it == message.sender.userId }
|
} else {
|
||||||
|
message.reply("回复错误已取消本次操作")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class ReverseGIFCommand : BaseCommand() {
|
|||||||
|
|
||||||
suspend fun callback(message: GroupMessage) {
|
suspend fun callback(message: GroupMessage) {
|
||||||
if (message.sender.userId !in waitingList) return
|
if (message.sender.userId !in waitingList) return
|
||||||
|
waitingList.removeIf { it == message.sender.userId }
|
||||||
val gifUrl = if (message.message.find { it.type == ArrayMessageType.mface } == null) {
|
val gifUrl = if (message.message.find { it.type == ArrayMessageType.mface } == null) {
|
||||||
message.message.find { it.type == ArrayMessageType.image }!!.data.file!!
|
message.message.find { it.type == ArrayMessageType.image }!!.data.file!!
|
||||||
} else {
|
} else {
|
||||||
@@ -44,14 +45,13 @@ class ReverseGIFCommand : BaseCommand() {
|
|||||||
val base64String = this.reverseGif(gifUrl)
|
val base64String = this.reverseGif(gifUrl)
|
||||||
val msg = MessageChain.Builder().addImage(base64String, true).build()
|
val msg = MessageChain.Builder().addImage(base64String, true).build()
|
||||||
message.reply(msg)
|
message.reply(msg)
|
||||||
waitingList.removeIf { it == message.sender.userId }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
if (message.sender.userId !in waitingList) {
|
if (message.sender.userId !in waitingList) {
|
||||||
waitingList.add(message.sender.userId)
|
|
||||||
message.reply("发送一张动图来继续操作")
|
message.reply("发送一张动图来继续操作")
|
||||||
|
waitingList.add(message.sender.userId)
|
||||||
} else {
|
} else {
|
||||||
message.reply("发送错误本次操作已取消")
|
message.reply("发送错误本次操作已取消")
|
||||||
waitingList.removeIf { it == message.sender.userId }
|
waitingList.removeIf { it == message.sender.userId }
|
||||||
|
|||||||
Reference in New Issue
Block a user